Browse Source

connect with config

master
imDMG 6 years ago
parent
commit
3b69c8ed12
  1. 8
      README.md
  2. 43
      kinozal.py

8
README.md

@ -4,12 +4,12 @@
Russian torrent tracker mostly directed on movies, but have other categories Russian torrent tracker mostly directed on movies, but have other categories
## Installation ## Installation
* Edit `kinozal.py` by replacing `KINOZAL_USERNAME` and `KINOZAL_PASSWORD` with your Kinozal username and password. * Edit `kinozal.json` by replacing `USERNAME` and `PASSWORD` with your Kinozal username and password.
* If kinozal.tv is blocked in your country, in same file: * If kinozal.tv is blocked in your country, in same file:
* find `proxy = False` and switch in `True` (`proxy = True`) * find `"proxy": false` and switch in `true` (`"proxy": true`)
* add proxy links working for you in `proxies` (`proxies = {'http': 'proxy.example.org:8080'}`) * add proxy links working for you in `proxies` (`{'http': 'proxy.example.org:8080'}`)
* *make sure that your proxy work with right protocol* * *make sure that your proxy work with right protocol*
* Move `kinozal.py` and `kinozal.png` to qBittorrent search engines directory: * Move `kinozal.py`, `kinozal.json` and `kinozal.png` to qBittorrent search engines directory:
* Windows: `%localappdata%\qBittorrent\nova3\engines\` * Windows: `%localappdata%\qBittorrent\nova3\engines\`
* Linux: `~/.local/share/data/qBittorrent/nova3/engines/` * Linux: `~/.local/share/data/qBittorrent/nova3/engines/`
* OS X: `~/Library/Application Support/qBittorrent/nova3/engines/` * OS X: `~/Library/Application Support/qBittorrent/nova3/engines/`

43
kinozal.py

@ -6,6 +6,7 @@
import tempfile import tempfile
import os import os
import logging import logging
import json
# import time # import time
from urllib.request import build_opener, HTTPCookieProcessor, ProxyHandler from urllib.request import build_opener, HTTPCookieProcessor, ProxyHandler
@ -19,9 +20,7 @@ from novaprinter import prettyPrinter
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M', datefmt='%m-%d %H:%M',
filename=os.path.abspath( filename=os.path.abspath(os.path.join(os.path.dirname(__file__), '../../logs', 'kinozal.log')),
os.path.join(os.path.dirname(__file__), '../..', 'logs')) + "/kinozal_se.log",
# filename="kinozal_se.log",
filemode='w') filemode='w')
# benchmark # benchmark
@ -39,18 +38,16 @@ class kinozal(object):
'anime': '20', 'anime': '20',
'software': '32'} 'software': '32'}
# Set proxies (default false) # getting config from kinozal.json
# make sure that proxies keys is'nt empty config = None
proxy = False try:
proxies = { # try to load user data from file
'http': '', with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'kinozal.json'))) as f:
'https': '', config = json.load(f)
} except OSError as e:
# file not found
# credentials logging.error(e)
username = "KINOZAL_USERNAME" raise e
password = "KINOZAL_PASSWORD"
ua = 'Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0'
def __init__(self): def __init__(self):
# establish connection # establish connection
@ -60,14 +57,14 @@ class kinozal(object):
self.session = build_opener(HTTPCookieProcessor(cj)) self.session = build_opener(HTTPCookieProcessor(cj))
# add proxy handler if needed # add proxy handler if needed
if self.proxy and any(self.proxies.keys()): if self.config['proxy'] and any(self.config['proxies'].keys()):
self.session.add_handler(ProxyHandler(self.proxies)) self.session.add_handler(ProxyHandler(self.config['proxies']))
# change user-agent # change user-agent
self.session.addheaders.pop() self.session.addheaders.pop()
self.session.addheaders.append(('User-Agent', self.ua)) self.session.addheaders.append(('User-Agent', self.config['ua']))
form_data = {"username": self.username, "password": self.password} form_data = {"username": self.config['username'], "password": self.config['password']}
data_encoded = urlencode(form_data).encode('cp1251') data_encoded = urlencode(form_data).encode('cp1251')
try: try:
@ -82,7 +79,7 @@ class kinozal(object):
raise e raise e
if 'uid' not in [cookie.name for cookie in cj]: if 'uid' not in [cookie.name for cookie in cj]:
logging.debug(cj) logging.warning("we not authorized, please check your credentials")
class WorstParser(HTMLParser): class WorstParser(HTMLParser):
def __init__(self, url=''): def __init__(self, url=''):
@ -232,13 +229,15 @@ class kinozal(object):
parser.feed(response.read().decode('cp1251')) parser.feed(response.read().decode('cp1251'))
parser.close() parser.close()
logging.info("Found torrents: %s" % parser.found_torrents)
# logging.debug("--- %s seconds ---" % (time.time() - start_time)) # logging.debug("--- %s seconds ---" % (time.time() - start_time))
if __name__ == "__main__": if __name__ == "__main__":
""""""
kinozal_se = kinozal() kinozal_se = kinozal()
# print(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..', 'logs'))) # print(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..', 'logs')))
# print(kinozal_se.WorstParser.units_convert("500 КБ")) # print(kinozal_se.WorstParser.units_convert("500 КБ"))
# kinozal_se.search('terror lostfilm', 'tv') kinozal_se.search('supernatural')
# kinozal_se._handle_connection(True)
# kinozal_se.download_torrent('http://dl.kinozal.tv/download.php?id=1609776') # kinozal_se.download_torrent('http://dl.kinozal.tv/download.php?id=1609776')
# print("--- %s seconds ---" % (time.time() - start_time)) # print("--- %s seconds ---" % (time.time() - start_time))

Loading…
Cancel
Save