|  | @@ -1,7 +1,7 @@
 | 
	
		
			
			| 1 | 1 |  """
 | 
	
		
			
			| 2 |  | - Torrentz.eu (BitTorrent meta-search engine)
 | 
	
		
			
			|  | 2 | + Torrentz2.eu (BitTorrent meta-search engine)
 | 
	
		
			
			| 3 | 3 |  
 | 
	
		
			
			| 4 |  | - @website      https://torrentz.eu/
 | 
	
		
			
			|  | 4 | + @website      https://torrentz2.eu/
 | 
	
		
			
			| 5 | 5 |   @provide-api  no
 | 
	
		
			
			| 6 | 6 |  
 | 
	
		
			
			| 7 | 7 |   @using-api    no
 | 
	
	
		
			
			|  | @@ -14,24 +14,24 @@
 | 
	
		
			
			| 14 | 14 |  import re
 | 
	
		
			
			| 15 | 15 |  from lxml import html
 | 
	
		
			
			| 16 | 16 |  from datetime import datetime
 | 
	
		
			
			| 17 |  | -from searx.engines.nyaa import int_or_zero, get_filesize_mul
 | 
	
		
			
			| 18 | 17 |  from searx.engines.xpath import extract_text
 | 
	
		
			
			| 19 | 18 |  from searx.url_utils import urlencode
 | 
	
		
			
			|  | 19 | +from searx.utils import get_torrent_size
 | 
	
		
			
			| 20 | 20 |  
 | 
	
		
			
			| 21 | 21 |  # engine dependent config
 | 
	
		
			
			| 22 | 22 |  categories = ['files', 'videos', 'music']
 | 
	
		
			
			| 23 | 23 |  paging = True
 | 
	
		
			
			| 24 | 24 |  
 | 
	
		
			
			| 25 | 25 |  # search-url
 | 
	
		
			
			| 26 |  | -# https://torrentz.eu/search?f=EXAMPLE&p=6
 | 
	
		
			
			| 27 |  | -base_url = 'https://torrentz.eu/'
 | 
	
		
			
			|  | 26 | +# https://torrentz2.eu/search?f=EXAMPLE&p=6
 | 
	
		
			
			|  | 27 | +base_url = 'https://torrentz2.eu/'
 | 
	
		
			
			| 28 | 28 |  search_url = base_url + 'search?{query}'
 | 
	
		
			
			| 29 | 29 |  
 | 
	
		
			
			| 30 | 30 |  
 | 
	
		
			
			| 31 | 31 |  # do search-request
 | 
	
		
			
			| 32 | 32 |  def request(query, params):
 | 
	
		
			
			| 33 | 33 |      page = params['pageno'] - 1
 | 
	
		
			
			| 34 |  | -    query = urlencode({'q': query, 'p': page})
 | 
	
		
			
			|  | 34 | +    query = urlencode({'f': query, 'p': page})
 | 
	
		
			
			| 35 | 35 |      params['url'] = search_url.format(query=query)
 | 
	
		
			
			| 36 | 36 |      return params
 | 
	
		
			
			| 37 | 37 |  
 | 
	
	
		
			
			|  | @@ -54,22 +54,29 @@ def response(resp):
 | 
	
		
			
			| 54 | 54 |          # extract url and remove a slash in the beginning
 | 
	
		
			
			| 55 | 55 |          link = links[0].attrib.get('href').lstrip('/')
 | 
	
		
			
			| 56 | 56 |  
 | 
	
		
			
			| 57 |  | -        seed = result.xpath('./dd/span[@class="u"]/text()')[0].replace(',', '')
 | 
	
		
			
			| 58 |  | -        leech = result.xpath('./dd/span[@class="d"]/text()')[0].replace(',', '')
 | 
	
		
			
			|  | 57 | +        seed = 0
 | 
	
		
			
			|  | 58 | +        leech = 0
 | 
	
		
			
			|  | 59 | +        try:
 | 
	
		
			
			|  | 60 | +            seed = int(result.xpath('./dd/span[4]/text()')[0].replace(',', ''))
 | 
	
		
			
			|  | 61 | +            leech = int(result.xpath('./dd/span[5]/text()')[0].replace(',', ''))
 | 
	
		
			
			|  | 62 | +        except:
 | 
	
		
			
			|  | 63 | +            pass
 | 
	
		
			
			| 59 | 64 |  
 | 
	
		
			
			| 60 | 65 |          params = {
 | 
	
		
			
			| 61 | 66 |              'url': base_url + link,
 | 
	
		
			
			| 62 | 67 |              'title': title,
 | 
	
		
			
			| 63 |  | -            'seed': int_or_zero(seed),
 | 
	
		
			
			| 64 |  | -            'leech': int_or_zero(leech),
 | 
	
		
			
			|  | 68 | +            'seed': seed,
 | 
	
		
			
			|  | 69 | +            'leech': leech,
 | 
	
		
			
			| 65 | 70 |              'template': 'torrent.html'
 | 
	
		
			
			| 66 | 71 |          }
 | 
	
		
			
			| 67 | 72 |  
 | 
	
		
			
			| 68 | 73 |          # let's try to calculate the torrent size
 | 
	
		
			
			| 69 | 74 |          try:
 | 
	
		
			
			| 70 |  | -            size_str = result.xpath('./dd/span[@class="s"]/text()')[0]
 | 
	
		
			
			| 71 |  | -            size, suffix = size_str.split()
 | 
	
		
			
			| 72 |  | -            params['filesize'] = int(size) * get_filesize_mul(suffix)
 | 
	
		
			
			|  | 75 | +            filesize_info = result.xpath('./dd/span[3]/text()')[0]
 | 
	
		
			
			|  | 76 | +            filesize, filesize_multiplier = filesize_info.split()
 | 
	
		
			
			|  | 77 | +            filesize = get_torrent_size(filesize, filesize_multiplier)
 | 
	
		
			
			|  | 78 | +
 | 
	
		
			
			|  | 79 | +            params['filesize'] = filesize
 | 
	
		
			
			| 73 | 80 |          except:
 | 
	
		
			
			| 74 | 81 |              pass
 | 
	
		
			
			| 75 | 82 |  
 | 
	
	
		
			
			|  | @@ -80,9 +87,8 @@ def response(resp):
 | 
	
		
			
			| 80 | 87 |  
 | 
	
		
			
			| 81 | 88 |          # extract and convert creation date
 | 
	
		
			
			| 82 | 89 |          try:
 | 
	
		
			
			| 83 |  | -            date_str = result.xpath('./dd/span[@class="a"]/span')[0].attrib.get('title')
 | 
	
		
			
			| 84 |  | -            # Fri, 25 Mar 2016 16:29:01
 | 
	
		
			
			| 85 |  | -            date = datetime.strptime(date_str, '%a, %d %b %Y %H:%M:%S')
 | 
	
		
			
			|  | 90 | +            date_ts = result.xpath('./dd/span[2]')[0].attrib.get('title')
 | 
	
		
			
			|  | 91 | +            date = datetime.fromtimestamp(float(date_ts))
 | 
	
		
			
			| 86 | 92 |              params['publishedDate'] = date
 | 
	
		
			
			| 87 | 93 |          except:
 | 
	
		
			
			| 88 | 94 |              pass
 |