Ponysearch/searx/engines/subtitleseeker.py

87 lines
2.3 KiB
Python
Raw Normal View History

"""
Subtitleseeker (Video)
@website http://www.subtitleseeker.com
@provide-api no
@using-api no
@results HTML
@stable no (HTML can change)
@parse url, title, content
"""
from lxml import html
from searx.languages import language_codes
2015-02-06 16:39:59 +01:00
from searx.engines.xpath import extract_text
2016-11-30 18:43:03 +01:00
from searx.url_utils import quote_plus
# engine dependent config
categories = ['videos']
paging = True
language = ""
# search-url
url = 'http://www.subtitleseeker.com/'
search_url = url + 'search/TITLES/{query}?p={pageno}'
# specific xpath variables
results_xpath = '//div[@class="boxRows"]'
# do search-request
def request(query, params):
params['url'] = search_url.format(query=quote_plus(query),
pageno=params['pageno'])
return params
# get response from search-request
def response(resp):
results = []
dom = html.fromstring(resp.text)
search_lang = ""
# dirty fix for languages named differenly in their site
if resp.search_params['language'][:2] == 'fa':
search_lang = 'Farsi'
2016-12-14 06:51:15 +01:00
elif resp.search_params['language'] == 'pt-BR':
search_lang = 'Brazilian'
else:
search_lang = [lc[3]
for lc in language_codes
if lc[0].split('-')[0] == resp.search_params['language'].split('-')[0]]
search_lang = search_lang[0].split(' (')[0]
# parse results
for result in dom.xpath(results_xpath):
link = result.xpath(".//a")[0]
href = link.attrib.get('href')
if language is not "":
href = href + language + '/'
elif search_lang:
href = href + search_lang + '/'
title = extract_text(link)
2015-02-06 16:39:59 +01:00
content = extract_text(result.xpath('.//div[contains(@class,"red")]'))
content = content + " - "
2015-02-06 16:39:59 +01:00
text = extract_text(result.xpath('.//div[contains(@class,"grey-web")]')[0])
content = content + text
if result.xpath(".//span") != []:
content = content +\
2015-01-02 12:33:40 +01:00
" - (" +\
2015-02-06 16:39:59 +01:00
extract_text(result.xpath(".//span")) +\
2015-01-02 12:33:40 +01:00
")"
# append result
results.append({'url': href,
'title': title,
'content': content})
# return results
return results