From 550232fc21ff2c3ae9a5de3d8b999de66c96171c Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Mon, 22 Dec 2014 01:00:16 +0100 Subject: SubtitleSeeker Engine Add the subtitleseeker engine. --- searx/engines/subtitleseeker.py | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 searx/engines/subtitleseeker.py (limited to 'searx/engines/subtitleseeker.py') diff --git a/searx/engines/subtitleseeker.py b/searx/engines/subtitleseeker.py new file mode 100644 index 000000000..346298300 --- /dev/null +++ b/searx/engines/subtitleseeker.py @@ -0,0 +1,59 @@ +## 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 cgi import escape +from urllib import quote_plus +from lxml import html + +# engine dependent config +categories = ['videos'] +paging = True + +# 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) + + # parse results + for result in dom.xpath(results_xpath): + link = result.xpath(".//a")[0] + href = link.attrib.get('href') + title = escape(link.xpath(".//text()")[0]) + + content = result.xpath('.//div[contains(@class,"red")]//text()')[0] + content = content + " - " + content = content + html.tostring(result.xpath('.//div[contains(@class,"grey-web")]')[0], method='text') + + if result.xpath(".//span") != []: + content = content + " - (" + result.xpath(".//span//text()")[0].strip() + ")" + + # append result + results.append({'url': href, + 'title': title, + 'content': escape(content)}) + + # return results + return results -- cgit v1.2.3 From 829948b85df0510e331372bcd60cb31db9c96a5c Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Tue, 23 Dec 2014 01:41:25 +0100 Subject: Add language support Allow the user to select a language. It must be written in english, and capitalized, ie : English, French, German, Hungarian... --- searx/engines/subtitleseeker.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'searx/engines/subtitleseeker.py') diff --git a/searx/engines/subtitleseeker.py b/searx/engines/subtitleseeker.py index 346298300..c72f81899 100644 --- a/searx/engines/subtitleseeker.py +++ b/searx/engines/subtitleseeker.py @@ -16,6 +16,8 @@ from lxml import html categories = ['videos'] paging = True +language = "" + # search-url url = 'http://www.subtitleseeker.com/' search_url = url+'search/TITLES/{query}&p={pageno}' @@ -41,6 +43,10 @@ def response(resp): for result in dom.xpath(results_xpath): link = result.xpath(".//a")[0] href = link.attrib.get('href') + + if language is not "": + href = href + language + "/" + title = escape(link.xpath(".//text()")[0]) content = result.xpath('.//div[contains(@class,"red")]//text()')[0] -- cgit v1.2.3 From 2ea55b1c6451e77381bd88dd82f635d48ff1b6fe Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Tue, 23 Dec 2014 01:45:39 +0100 Subject: Add language support Allow the user to select a language. It must be written in english, and capitalized, ie : English, French, German, Hungarian... (reverted from commit 829948b85df0510e331372bcd60cb31db9c96a5c) --- searx/engines/subtitleseeker.py | 6 ------ 1 file changed, 6 deletions(-) (limited to 'searx/engines/subtitleseeker.py') diff --git a/searx/engines/subtitleseeker.py b/searx/engines/subtitleseeker.py index c72f81899..346298300 100644 --- a/searx/engines/subtitleseeker.py +++ b/searx/engines/subtitleseeker.py @@ -16,8 +16,6 @@ from lxml import html categories = ['videos'] paging = True -language = "" - # search-url url = 'http://www.subtitleseeker.com/' search_url = url+'search/TITLES/{query}&p={pageno}' @@ -43,10 +41,6 @@ def response(resp): for result in dom.xpath(results_xpath): link = result.xpath(".//a")[0] href = link.attrib.get('href') - - if language is not "": - href = href + language + "/" - title = escape(link.xpath(".//text()")[0]) content = result.xpath('.//div[contains(@class,"red")]//text()')[0] -- cgit v1.2.3 From 10e4f6f31631fe51d16b324223525570f3e75850 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Tue, 23 Dec 2014 01:51:07 +0100 Subject: Add language support Allow the user to select a language. It must be written in english, and capitalized, ie : English, French, German, Hungarian... --- searx/engines/subtitleseeker.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'searx/engines/subtitleseeker.py') diff --git a/searx/engines/subtitleseeker.py b/searx/engines/subtitleseeker.py index 346298300..48790a35c 100644 --- a/searx/engines/subtitleseeker.py +++ b/searx/engines/subtitleseeker.py @@ -15,6 +15,7 @@ from lxml import html # engine dependent config categories = ['videos'] paging = True +language = "" # search-url url = 'http://www.subtitleseeker.com/' @@ -41,6 +42,10 @@ def response(resp): for result in dom.xpath(results_xpath): link = result.xpath(".//a")[0] href = link.attrib.get('href') + + if language is not "": + href = href + language + "/" + title = escape(link.xpath(".//text()")[0]) content = result.xpath('.//div[contains(@class,"red")]//text()')[0] -- cgit v1.2.3 From 3b3921fc593e49c12ff79df1d6b15d01fe481bec Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Wed, 24 Dec 2014 21:02:26 +0100 Subject: [enh] subtitleseeker: better language handling --- searx/engines/subtitleseeker.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'searx/engines/subtitleseeker.py') diff --git a/searx/engines/subtitleseeker.py b/searx/engines/subtitleseeker.py index 48790a35c..2f1636f59 100644 --- a/searx/engines/subtitleseeker.py +++ b/searx/engines/subtitleseeker.py @@ -11,6 +11,7 @@ from cgi import escape from urllib import quote_plus from lxml import html +from searx.languages import language_codes # engine dependent config categories = ['videos'] @@ -38,13 +39,22 @@ def response(resp): dom = html.fromstring(resp.text) + search_lang = "" + + if resp.search_params['language'] != 'all': + search_lang = [lc[1] + for lc in language_codes + if lc[0][:2] == resp.search_params['language']][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 + "/" + href = href + language + '/' + elif search_lang: + href = href + search_lang + '/' title = escape(link.xpath(".//text()")[0]) -- cgit v1.2.3 From 5d977056f7aa216eae09a22c3baaff73546f6ff1 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Mon, 29 Dec 2014 21:31:04 +0100 Subject: Flake8 and Twitter corrections Lots of Flake8 corrections Maybe we should change the rule to allow lines of 120 chars. It seems more usable. Big twitter correction : now it outputs the words in right order... --- searx/engines/subtitleseeker.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'searx/engines/subtitleseeker.py') diff --git a/searx/engines/subtitleseeker.py b/searx/engines/subtitleseeker.py index 2f1636f59..c413dcf26 100644 --- a/searx/engines/subtitleseeker.py +++ b/searx/engines/subtitleseeker.py @@ -60,10 +60,14 @@ def response(resp): content = result.xpath('.//div[contains(@class,"red")]//text()')[0] content = content + " - " - content = content + html.tostring(result.xpath('.//div[contains(@class,"grey-web")]')[0], method='text') + text = result.xpath('.//div[contains(@class,"grey-web")]')[0] + content = content + html.tostring(text, method='text') if result.xpath(".//span") != []: - content = content + " - (" + result.xpath(".//span//text()")[0].strip() + ")" + content = content +\ + " - (" +\ + result.xpath(".//span//text()")[0].strip() +\ + ")" # append result results.append({'url': href, -- cgit v1.2.3 From cc4e17b6686dbefe0d57862e045f98f72a4e58fc Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Fri, 2 Jan 2015 12:33:40 +0100 Subject: [fix] pep8 --- searx/engines/subtitleseeker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'searx/engines/subtitleseeker.py') diff --git a/searx/engines/subtitleseeker.py b/searx/engines/subtitleseeker.py index c413dcf26..9aaf1947b 100644 --- a/searx/engines/subtitleseeker.py +++ b/searx/engines/subtitleseeker.py @@ -65,9 +65,9 @@ def response(resp): if result.xpath(".//span") != []: content = content +\ - " - (" +\ - result.xpath(".//span//text()")[0].strip() +\ - ")" + " - (" +\ + result.xpath(".//span//text()")[0].strip() +\ + ")" # append result results.append({'url': href, -- cgit v1.2.3