Procházet zdrojové kódy

Merge pull request #161 from Cqoicebordel/SubtitleSeeker-engine

SubtitleSeeker Engine
Adam Tauber před 10 roky
rodič
revize
5857141e49
2 změnil soubory, kde provedl 71 přidání a 0 odebrání
  1. 64
    0
      searx/engines/subtitleseeker.py
  2. 7
    0
      searx/settings.yml

+ 64
- 0
searx/engines/subtitleseeker.py Zobrazit soubor

1
+## Subtitleseeker (Video)
2
+#
3
+# @website     http://www.subtitleseeker.com
4
+# @provide-api no
5
+#
6
+# @using-api   no
7
+# @results     HTML
8
+# @stable      no (HTML can change)
9
+# @parse       url, title, content
10
+
11
+from cgi import escape
12
+from urllib import quote_plus
13
+from lxml import html
14
+
15
+# engine dependent config
16
+categories = ['videos']
17
+paging = True
18
+language = ""
19
+
20
+# search-url
21
+url = 'http://www.subtitleseeker.com/'
22
+search_url = url+'search/TITLES/{query}&p={pageno}'
23
+
24
+# specific xpath variables
25
+results_xpath = '//div[@class="boxRows"]'
26
+
27
+
28
+# do search-request
29
+def request(query, params):
30
+    params['url'] = search_url.format(query=quote_plus(query),
31
+                                      pageno=params['pageno'])
32
+    return params
33
+
34
+
35
+# get response from search-request
36
+def response(resp):
37
+    results = []
38
+
39
+    dom = html.fromstring(resp.text)
40
+
41
+    # parse results
42
+    for result in dom.xpath(results_xpath):
43
+        link = result.xpath(".//a")[0]
44
+        href = link.attrib.get('href')
45
+
46
+        if language is not "":
47
+            href = href + language + "/"
48
+
49
+        title = escape(link.xpath(".//text()")[0])
50
+
51
+        content = result.xpath('.//div[contains(@class,"red")]//text()')[0]
52
+        content = content + " - "
53
+        content = content + html.tostring(result.xpath('.//div[contains(@class,"grey-web")]')[0], method='text')
54
+
55
+        if result.xpath(".//span") != []:
56
+            content = content + " - (" + result.xpath(".//span//text()")[0].strip() + ")"
57
+
58
+        # append result
59
+        results.append({'url': href,
60
+                        'title': title,
61
+                        'content': escape(content)})
62
+
63
+    # return results
64
+    return results

+ 7
- 0
searx/settings.yml Zobrazit soubor

131
     engine : searchcode_code
131
     engine : searchcode_code
132
     shortcut : scc
132
     shortcut : scc
133
 
133
 
134
+  - name : subtitleseeker
135
+    engine : subtitleseeker
136
+    shortcut : ss
137
+# The language is an option. You can put any language written in english
138
+# Examples : English, French, German, Hungarian, Chinese...
139
+#    language : English
140
+
134
   - name : startpage
141
   - name : startpage
135
     engine : startpage
142
     engine : startpage
136
     shortcut : sp
143
     shortcut : sp