浏览代码

[enh] subtitleseeker: better language handling

Adam Tauber 10 年前
父节点
当前提交
3b3921fc59
共有 1 个文件被更改,包括 11 次插入1 次删除
  1. 11
    1
      searx/engines/subtitleseeker.py

+ 11
- 1
searx/engines/subtitleseeker.py 查看文件

11
 from cgi import escape
11
 from cgi import escape
12
 from urllib import quote_plus
12
 from urllib import quote_plus
13
 from lxml import html
13
 from lxml import html
14
+from searx.languages import language_codes
14
 
15
 
15
 # engine dependent config
16
 # engine dependent config
16
 categories = ['videos']
17
 categories = ['videos']
38
 
39
 
39
     dom = html.fromstring(resp.text)
40
     dom = html.fromstring(resp.text)
40
 
41
 
42
+    search_lang = ""
43
+
44
+    if resp.search_params['language'] != 'all':
45
+        search_lang = [lc[1]
46
+                       for lc in language_codes
47
+                       if lc[0][:2] == resp.search_params['language']][0]
48
+
41
     # parse results
49
     # parse results
42
     for result in dom.xpath(results_xpath):
50
     for result in dom.xpath(results_xpath):
43
         link = result.xpath(".//a")[0]
51
         link = result.xpath(".//a")[0]
44
         href = link.attrib.get('href')
52
         href = link.attrib.get('href')
45
 
53
 
46
         if language is not "":
54
         if language is not "":
47
-            href = href + language + "/"
55
+            href = href + language + '/'
56
+        elif search_lang:
57
+            href = href + search_lang + '/'
48
 
58
 
49
         title = escape(link.xpath(".//text()")[0])
59
         title = escape(link.xpath(".//text()")[0])
50
 
60