Browse Source

[mod] tokyotoshokan dependecy to other engine removed

misnyo 7 years ago
parent
commit
1e2b60f380
1 changed files with 13 additions and 3 deletions
  1. 13
    3
      searx/engines/tokyotoshokan.py

+ 13
- 3
searx/engines/tokyotoshokan.py View File

14
 from lxml import html
14
 from lxml import html
15
 from searx.engines.xpath import extract_text
15
 from searx.engines.xpath import extract_text
16
 from datetime import datetime
16
 from datetime import datetime
17
-from searx.engines.nyaa import int_or_zero, get_filesize_mul
18
 from searx.url_utils import urlencode
17
 from searx.url_utils import urlencode
18
+from searx.utils import get_torrent_size
19
 
19
 
20
 # engine dependent config
20
 # engine dependent config
21
 categories = ['files', 'videos', 'music']
21
 categories = ['files', 'videos', 'music']
26
 search_url = base_url + 'search.php?{query}'
26
 search_url = base_url + 'search.php?{query}'
27
 
27
 
28
 
28
 
29
+# convert a variable to integer or return 0 if it's not a number
30
+def int_or_zero(num):
31
+    if isinstance(num, list):
32
+        if len(num) < 1:
33
+            return 0
34
+        num = num[0]
35
+    if num.isdigit():
36
+        return int(num)
37
+    return 0
38
+
39
+
29
 # do search-request
40
 # do search-request
30
 def request(query, params):
41
 def request(query, params):
31
     query = urlencode({'page': params['pageno'], 'terms': query})
42
     query = urlencode({'page': params['pageno'], 'terms': query})
76
                 try:
87
                 try:
77
                     # ('1.228', 'GB')
88
                     # ('1.228', 'GB')
78
                     groups = size_re.match(item).groups()
89
                     groups = size_re.match(item).groups()
79
-                    multiplier = get_filesize_mul(groups[1])
80
-                    params['filesize'] = int(multiplier * float(groups[0]))
90
+                    params['filesize'] = get_torrent_size(groups[0], groups[1])
81
                 except:
91
                 except:
82
                     pass
92
                     pass
83
             elif item.startswith('Date:'):
93
             elif item.startswith('Date:'):