# -*- coding: utf-8 -*-
"""RuTracker search engine plugin for qBittorrent."""
#VERSION: 1.13
#AUTHORS: Skymirrh (skymirrh@gmail.com)
# Replace YOUR_USERNAME_HERE and YOUR_PASSWORD_HERE with your RuTracker username and password
credentials = {
'login_username': u'YOUR_USERNAME_HERE',
'login_password': u'YOUR_PASSWORD_HERE',
}
# List of RuTracker mirrors
mirrors = [
'https://rutracker.org',
'https://rutracker.net',
'https://rutracker.nl',
'https://rutracker.cr',
]
# Logging
import logging
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
# Try blocks are used to circumvent Python2/3 modules discrepancies and use a single script for both versions.
try:
import cookielib
except ImportError:
import http.cookiejar as cookielib
try:
from urllib import urlencode, quote, unquote
from urllib2 import build_opener, HTTPCookieProcessor, URLError, HTTPError
except ImportError:
from urllib.parse import urlencode, quote, unquote
from urllib.request import build_opener, HTTPCookieProcessor
from urllib.error import URLError, HTTPError
try:
from HTMLParser import HTMLParser
except ImportError:
from html.parser import HTMLParser
import tempfile
import os
import re
from novaprinter import prettyPrinter
def dict_encode(dict, encoding='cp1251'):
"""Encode dict values to encoding (default: cp1251)."""
encoded_dict = {}
for key in dict:
encoded_dict[key] = dict[key].encode(encoding)
return encoded_dict
class rutracker(object):
"""RuTracker search engine plugin for qBittorrent."""
name = 'RuTracker'
url = 'https://rutracker.org' # We MUST produce an URL attribute at instantiation time, otherwise qBittorrent will fail to register the engine, see #15
@property
def forum_url(self):
return self.url + '/forum'
@property
def login_url(self):
return self.forum_url + '/login.php'
@property
def download_url(self):
return self.forum_url + '/dl.php'
@property
def search_url(self):
return self.forum_url + '/tracker.php'
def __init__(self):
"""Initialize RuTracker search engine, signing in using given credentials."""
# Initialize various objects.
self.cj = cookielib.CookieJar()
self.opener = build_opener(HTTPCookieProcessor(self.cj))
self.url = self.initialize_url() # Override url with the actual URL to be used (in case official URL isn't accessible)
self.credentials = credentials
# Add submit button additional POST param.
self.credentials['login'] = u'Вход'
# Send POST information and sign in.
try:
logging.info("Trying to connect using given credentials.")
response = self.opener.open(self.login_url, urlencode(dict_encode(self.credentials)).encode())
# Check if response status is OK.
if response.getcode() != 200:
raise HTTPError(response.geturl(), response.getcode(), "HTTP request to {} failed with status: {}".format(self.login_url, response.getcode()), response.info(), None)
# Check if login was successful using cookies.
if not 'bb_session' in [cookie.name for cookie in self.cj]:
logging.debug(self.cj)
raise ValueError("Unable to connect using given credentials.")
else:
logging.info("Login successful.")
except (URLError, HTTPError, ValueError) as e:
logging.error(e)
def initialize_url(self):
"""Try to find a reachable RuTracker mirror."""
for mirror in mirrors:
try:
self.opener.open(mirror)
logging.info("Found reachable mirror: {}".format(mirror))
return mirror
except URLError:
pass
logging.error("Unable to resolve any RuTracker mirror.")
return ''
def download_torrent(self, url):
"""Download file at url and write it to a file, print the path to the file and the url."""
# Make temp file.
file, path = tempfile.mkstemp('.torrent')
file = os.fdopen(file, "wb")
# Set up fake POST params, needed to trick the server into sending the file.
id = re.search(r'dl\.php\?t=(\d+)', url).group(1)
post_params = {'t': id,}
# Download torrent file at url.
try:
response = self.opener.open(url, urlencode(dict_encode(post_params)).encode())
# Only continue if response status is OK.
if response.getcode() != 200:
raise HTTPError(response.geturl(), response.getcode(), "HTTP request to {} failed with status: {}".format(url, response.getcode()), response.info(), None)
except (URLError, HTTPError) as e:
logging.error(e)
raise e
# Write it to a file.
data = response.read()
file.write(data)
file.close()
# Print file path and url.
print(path+" "+url)
class Parser(HTMLParser):
"""Implement a simple HTML parser to parse results pages."""
def __init__(self, engine):
"""Initialize the parser with url and tell him if he's on the first page of results or not."""
# In Python 3 convert_charrefs is set to True by default: handle_data() receives HTML entities as regular data, handle_entityref() does nothing.
# In Python 2 there is no convert_charrefs: HTML entities are always processed by handle_entityref().
# Thus, we make Python 3 work like Python 2 in order to standardize HTML entities handling.
try:
HTMLParser.__init__(self, convert_charrefs=False)
except:
HTMLParser.__init__(self)
self.engine = engine
self.results = []
self.other_pages = []
self.tr_counter = 0
self.cat_re = re.compile(r'tracker\.php\?f=\d+')
self.name_re = re.compile(r'viewtopic\.php\?t=\d+')
self.pages_re = re.compile(r'tracker\.php\?.*?start=(\d+)')
self.size_re = re.compile(r'[^.0-9a-zA-Z]+')
self.reset_current()
def reset_current(self):
"""Reset current_item (i.e. torrent) to default values."""
self.current_item = {'cat': None,
'name': None,
'link': None,
'size': None,
'seeds': None,
'leech': None,
'desc_link': None,}
def handle_data(self, data):
"""Retrieve inner text information based on rules defined in do_tag()."""
for key in self.current_item:
if self.current_item[key] == True:
if key == 'size':
self.current_item['size'] = self.size_re.sub(r'', data)
elif key == 'size_extension':
self.current_item['size'] += data
else:
self.current_item[key] = data
logging.debug('handle_data: ' + str((self.tr_counter, key, data)))
if 'size_extension' in self.current_item:
del self.current_item['size_extension']
def handle_entityref(self, entity):
"""When encountering a after setting size, this means next handle_data() will received size extension (e.g. 'MB', 'GB')"""
if entity == "nbsp" and self.current_item['size'] is not None:
self.current_item['size_extension'] = True
def handle_starttag(self, tag, attrs):
"""Pass along tag and attributes to dedicated handlers. Discard any tag without handler."""
try:
getattr(self, 'do_{}'.format(tag))(attrs)
except:
没有合适的资源?快使用搜索试试~ 我知道了~
qBittorrent搜索引擎插件.zip
共36个文件
py:36个
需积分: 44 37 下载量 80 浏览量
2020-04-01
09:51:46
上传
评论
收藏 71KB ZIP 举报
温馨提示
qBittorrent搜索引擎插件.py文件合集,方便以本地文件方式,快速一键导入qBittorrent。
资源推荐
资源详情
资源评论
收起资源包目录
qBittorrent搜索引擎插件.zip (36个子文件)
qBittorrent搜索引擎插件
cinecalidad.py 3KB
sukebei.py 2KB
extratorrent.py 4KB
cpasbien.py 4KB
idope.py 3KB
corsaroblu.py 5KB
nyaapantsu.py 7KB
smallgames.py 2KB
linuxtracker.py 5KB
torrentfunk.py 4KB
ettv.py 5KB
corsaronero.py 3KB
mejor.py 5KB
rutor.py 5KB
tokyotoshokan.py 5KB
kickass_torrent.py 5KB
tntvillage.py 5KB
nyaa.py 3KB
rockbox.py 5KB
magnetdl.py 2KB
solotorrent.py 4KB
snowfl.py 3KB
nyaasi.py 5KB
pantsu.py 2KB
rutracker.py 14KB
skytorrents.py 5KB
uniondht.py 10KB
mkvcage.py 3KB
yourbittorrent.py 4KB
filelist.py 10KB
qbrutracker.py 7KB
dmhyorg.py 3KB
yggtorrent.py 9KB
btetree.py 4KB
torrent9.py 6KB
bakabt.py 9KB
共 36 条
- 1
资源评论
ExcellenceWJ
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功