Browse Source

v1.3: magnet link (opt.)

master
imDMG 6 years ago
parent
commit
3f1bb30179
  1. 8
      kinozal.json
  2. 19
      kinozal.py

8
kinozal.json

@ -1,11 +1,11 @@
{ {
"username": "USERNAME", "username": "USERNAME",
"password": "PASSWORD", "password": "PASSWORD",
"proxy": false, "proxy": true,
"proxies": { "proxies": {
"http": "proxy.example.org:8080", "http": "",
"https": "proxy.example.org:2020" "https": ""
}, },
"log": "os.path.abspath(os.path.join(os.path.dirname(__file__), '../../logs', 'kinozal.log'))", "magnet": true,
"ua": "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0" "ua": "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0"
} }

19
kinozal.py

@ -1,4 +1,4 @@
# VERSION: 1.2 # VERSION: 1.3
# AUTHORS: imDMG [imdmgg@gmail.com] # AUTHORS: imDMG [imdmgg@gmail.com]
# Kinozal.tv search engine plugin for qBittorrent # Kinozal.tv search engine plugin for qBittorrent
@ -7,6 +7,7 @@ import tempfile
import os import os
import logging import logging
import json import json
# import re
import time import time
from urllib.request import build_opener, HTTPCookieProcessor, ProxyHandler from urllib.request import build_opener, HTTPCookieProcessor, ProxyHandler
@ -43,7 +44,7 @@ class kinozal(object):
try: try:
# try to load user data from file # try to load user data from file
with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'kinozal.json'))) as f: with open(os.path.abspath(os.path.join(os.path.dirname(__file__), 'kinozal.json'))) as f:
config = json.load(f) config: dict = json.load(f)
except OSError as e: except OSError as e:
# file not found # file not found
logging.error(e) logging.error(e)
@ -186,9 +187,18 @@ class kinozal(object):
def error(self, message): def error(self, message):
pass pass
def download_torrent(self, url): def download_torrent(self, url: str):
if self.blocked: if self.blocked:
return return
# choose download method
if self.config.get("magnet"):
res = self._catch_error_request(self.url + "/get_srv_details.php?action=2&id=" + url.split("=")[1])
# magnet = re.search(":\s([A-Z0-9]{40})\<", res.read().decode())[1]
magnet = 'magnet:?xt=urn:btih:' + res.read().decode()[18:58]
# return magnet link
logging.debug(magnet + " " + url)
print(magnet + " " + url)
else:
# Create a torrent file # Create a torrent file
file, path = tempfile.mkstemp('.torrent') file, path = tempfile.mkstemp('.torrent')
file = os.fdopen(file, "wb") file = os.fdopen(file, "wb")
@ -249,4 +259,5 @@ class kinozal(object):
if __name__ == "__main__": if __name__ == "__main__":
kinozal_se = kinozal() kinozal_se = kinozal()
kinozal_se.search('supernatural') # kinozal_se.download_torrent("http://kinozal.tv/details.php?id=1263407")
# kinozal_se.search('supernatural')

Loading…
Cancel
Save