| 
				
			 | 
			
			
				@@ -14,8 +14,8 @@ import re 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				14
			 | 
			
			
				 from lxml import html 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				15
			 | 
			
			
				 from searx.engines.xpath import extract_text 
			 | 
		
	
		
			
			| 
				16
			 | 
			
				16
			 | 
			
			
				 from datetime import datetime 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				
			 | 
			
			
				-from searx.engines.nyaa import int_or_zero, get_filesize_mul 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				17
			 | 
			
			
				 from searx.url_utils import urlencode 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+from searx.utils import get_torrent_size 
			 | 
		
	
		
			
			| 
				19
			 | 
			
				19
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				20
			 | 
			
				20
			 | 
			
			
				 # engine dependent config 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				21
			 | 
			
			
				 categories = ['files', 'videos', 'music'] 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -26,6 +26,17 @@ base_url = 'https://www.tokyotosho.info/' 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				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
			 | 
			
				40
			 | 
			
			
				 # do search-request 
			 | 
		
	
		
			
			| 
				30
			 | 
			
				41
			 | 
			
			
				 def request(query, params): 
			 | 
		
	
		
			
			| 
				31
			 | 
			
				42
			 | 
			
			
				     query = urlencode({'page': params['pageno'], 'terms': query}) 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -76,8 +87,7 @@ def response(resp): 
			 | 
		
	
		
			
			| 
				76
			 | 
			
				87
			 | 
			
			
				                 try: 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				88
			 | 
			
			
				                     # ('1.228', 'GB') 
			 | 
		
	
		
			
			| 
				78
			 | 
			
				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
			 | 
			
				91
			 | 
			
			
				                 except: 
			 | 
		
	
		
			
			| 
				82
			 | 
			
				92
			 | 
			
			
				                     pass 
			 | 
		
	
		
			
			| 
				83
			 | 
			
				93
			 | 
			
			
				             elif item.startswith('Date:'): 
			 |