mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-24 02:06:07 +03:00
Merge pull request #2512 from ngosang/torrentz
New feature: Torrentz search engine
This commit is contained in:
commit
112d4b8c71
7 changed files with 232 additions and 0 deletions
BIN
src/searchengine/nova/engines/torrentz.png
Normal file
BIN
src/searchengine/nova/engines/torrentz.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 226 B |
113
src/searchengine/nova/engines/torrentz.py
Normal file
113
src/searchengine/nova/engines/torrentz.py
Normal file
|
@ -0,0 +1,113 @@
|
|||
#VERSION: 2.11
|
||||
#AUTHORS: Diego de las Heras (diegodelasheras@gmail.com)
|
||||
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the author nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from novaprinter import prettyPrinter
|
||||
from helpers import retrieve_url, download_file
|
||||
from HTMLParser import HTMLParser
|
||||
from urllib import urlencode
|
||||
|
||||
class torrentz(object):
|
||||
# mandatory properties
|
||||
url = 'https://torrentz.eu'
|
||||
name = 'Torrentz'
|
||||
supported_categories = {'all': ''}
|
||||
|
||||
trackers_list = ['udp://open.demonii.com:1337/announce',
|
||||
'udp://tracker.openbittorrent.com:80/announce',
|
||||
'udp://tracker.publicbt.com:80/announce',
|
||||
'udp://tracker.istole.it:80/announce']
|
||||
|
||||
class MyHtmlParser(HTMLParser):
|
||||
def __init__(self, results, url, trackers):
|
||||
HTMLParser.__init__(self)
|
||||
self.results = results
|
||||
self.url = url
|
||||
self.trackers = trackers
|
||||
self.td_counter = None
|
||||
self.current_item = None
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
if tag == 'a':
|
||||
params = dict(attrs)
|
||||
if 'href' in params:
|
||||
self.current_item = {}
|
||||
self.td_counter = 0
|
||||
self.current_item['link'] = 'magnet:?xt=urn:btih:' + \
|
||||
params['href'].strip(' /') + self.trackers
|
||||
self.current_item['desc_link'] = self.url + params['href'].strip()
|
||||
elif tag == 'span':
|
||||
if isinstance(self.td_counter,int):
|
||||
self.td_counter += 1
|
||||
if self.td_counter > 6: # safety
|
||||
self.td_counter = None
|
||||
|
||||
def handle_data(self, data):
|
||||
if self.td_counter == 0:
|
||||
if 'name' not in self.current_item:
|
||||
self.current_item['name'] = ''
|
||||
self.current_item['name'] += data
|
||||
elif self.td_counter == 4:
|
||||
if 'size' not in self.current_item:
|
||||
self.current_item['size'] = data.strip()
|
||||
elif self.td_counter == 5:
|
||||
if 'seeds' not in self.current_item:
|
||||
self.current_item['seeds'] = data.strip().replace(',', '')
|
||||
elif self.td_counter == 6:
|
||||
if 'leech' not in self.current_item:
|
||||
self.current_item['leech'] = data.strip().replace(',', '')
|
||||
|
||||
# display item
|
||||
self.td_counter = None
|
||||
self.current_item['engine_url'] = self.url
|
||||
if self.current_item['name'].find(' \xc2'):
|
||||
self.current_item['name'] = self.current_item['name'].split(' \xc2')[0]
|
||||
self.current_item['link'] += '&' + urlencode({'dn' : self.current_item['name']})
|
||||
if not self.current_item['seeds'].isdigit():
|
||||
self.current_item['seeds'] = 0
|
||||
if not self.current_item['leech'].isdigit():
|
||||
self.current_item['leech'] = 0
|
||||
prettyPrinter(self.current_item)
|
||||
self.results.append('a')
|
||||
|
||||
def download_torrent(self, info):
|
||||
print(download_file(info))
|
||||
|
||||
def search(self, what, cat='all'):
|
||||
# initialize trackers for magnet links
|
||||
trackers = '&' + '&'.join(urlencode({'tr' : tracker}) for tracker in self.trackers_list)
|
||||
|
||||
i = 0
|
||||
while i < 6:
|
||||
results_list = []
|
||||
# "what" is already urlencoded
|
||||
html = retrieve_url(self.url + '/search?f=%s&p=%d' % (what, i))
|
||||
parser = self.MyHtmlParser(results_list, self.url, trackers)
|
||||
parser.feed(html)
|
||||
parser.close()
|
||||
if len(results_list) < 1:
|
||||
break
|
||||
i += 1
|
|
@ -5,3 +5,4 @@ extratorrent: 1.2
|
|||
kickasstorrents: 1.26
|
||||
btdigg: 1.24
|
||||
legittorrents: 1.02
|
||||
torrentz: 2.11
|
||||
|
|
BIN
src/searchengine/nova3/engines/torrentz.png
Normal file
BIN
src/searchengine/nova3/engines/torrentz.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 226 B |
113
src/searchengine/nova3/engines/torrentz.py
Normal file
113
src/searchengine/nova3/engines/torrentz.py
Normal file
|
@ -0,0 +1,113 @@
|
|||
#VERSION: 2.11
|
||||
#AUTHORS: Diego de las Heras (diegodelasheras@gmail.com)
|
||||
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the author nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from novaprinter import prettyPrinter
|
||||
from helpers import retrieve_url, download_file
|
||||
from html.parser import HTMLParser
|
||||
from urllib.parse import urlencode
|
||||
|
||||
class torrentz(object):
|
||||
# mandatory properties
|
||||
url = 'https://torrentz.eu'
|
||||
name = 'Torrentz'
|
||||
supported_categories = {'all': ''}
|
||||
|
||||
trackers_list = ['udp://open.demonii.com:1337/announce',
|
||||
'udp://tracker.openbittorrent.com:80/announce',
|
||||
'udp://tracker.publicbt.com:80/announce',
|
||||
'udp://tracker.istole.it:80/announce']
|
||||
|
||||
class MyHtmlParser(HTMLParser):
|
||||
def __init__(self, results, url, trackers):
|
||||
HTMLParser.__init__(self)
|
||||
self.results = results
|
||||
self.url = url
|
||||
self.trackers = trackers
|
||||
self.td_counter = None
|
||||
self.current_item = None
|
||||
|
||||
def handle_starttag(self, tag, attrs):
|
||||
if tag == 'a':
|
||||
params = dict(attrs)
|
||||
if 'href' in params:
|
||||
self.current_item = {}
|
||||
self.td_counter = 0
|
||||
self.current_item['link'] = 'magnet:?xt=urn:btih:' + \
|
||||
params['href'].strip(' /') + self.trackers
|
||||
self.current_item['desc_link'] = self.url + params['href'].strip()
|
||||
elif tag == 'span':
|
||||
if isinstance(self.td_counter,int):
|
||||
self.td_counter += 1
|
||||
if self.td_counter > 6: # safety
|
||||
self.td_counter = None
|
||||
|
||||
def handle_data(self, data):
|
||||
if self.td_counter == 0:
|
||||
if 'name' not in self.current_item:
|
||||
self.current_item['name'] = ''
|
||||
self.current_item['name'] += data
|
||||
elif self.td_counter == 4:
|
||||
if 'size' not in self.current_item:
|
||||
self.current_item['size'] = data.strip()
|
||||
elif self.td_counter == 5:
|
||||
if 'seeds' not in self.current_item:
|
||||
self.current_item['seeds'] = data.strip().replace(',', '')
|
||||
elif self.td_counter == 6:
|
||||
if 'leech' not in self.current_item:
|
||||
self.current_item['leech'] = data.strip().replace(',', '')
|
||||
|
||||
# display item
|
||||
self.td_counter = None
|
||||
self.current_item['engine_url'] = self.url
|
||||
if self.current_item['name'].find(' »'):
|
||||
self.current_item['name'] = self.current_item['name'].split(' »')[0]
|
||||
self.current_item['link'] += '&' + urlencode({'dn' : self.current_item['name']})
|
||||
if not self.current_item['seeds'].isdigit():
|
||||
self.current_item['seeds'] = 0
|
||||
if not self.current_item['leech'].isdigit():
|
||||
self.current_item['leech'] = 0
|
||||
prettyPrinter(self.current_item)
|
||||
self.results.append('a')
|
||||
|
||||
def download_torrent(self, info):
|
||||
print(download_file(info))
|
||||
|
||||
def search(self, what, cat='all'):
|
||||
# initialize trackers for magnet links
|
||||
trackers = '&' + '&'.join(urlencode({'tr' : tracker}) for tracker in self.trackers_list)
|
||||
|
||||
i = 0
|
||||
while i < 6:
|
||||
results_list = []
|
||||
# "what" is already urlencoded
|
||||
html = retrieve_url(self.url + '/search?f=%s&p=%d' % (what, i))
|
||||
parser = self.MyHtmlParser(results_list, self.url, trackers)
|
||||
parser.feed(html)
|
||||
parser.close()
|
||||
if len(results_list) < 1:
|
||||
break
|
||||
i += 1
|
|
@ -5,3 +5,4 @@ extratorrent: 1.2
|
|||
kickasstorrents: 1.26
|
||||
btdigg: 1.23
|
||||
legittorrents: 1.03
|
||||
torrentz: 2.11
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
<file>nova/engines/piratebay.py</file>
|
||||
<file>nova/engines/torrentreactor.png</file>
|
||||
<file>nova/engines/torrentreactor.py</file>
|
||||
<file>nova/engines/torrentz.png</file>
|
||||
<file>nova/engines/torrentz.py</file>
|
||||
<file>nova3/helpers.py</file>
|
||||
<file>nova3/nova2.py</file>
|
||||
<file>nova3/nova2dl.py</file>
|
||||
|
@ -40,5 +42,7 @@
|
|||
<file>nova3/engines/piratebay.py</file>
|
||||
<file>nova3/engines/torrentreactor.png</file>
|
||||
<file>nova3/engines/torrentreactor.py</file>
|
||||
<file>nova3/engines/torrentz.png</file>
|
||||
<file>nova3/engines/torrentz.py</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in a new issue