Browse Source

v1.3: magnet link (opt.)

master
imDMG 6 years ago
parent
commit
3f1bb30179
  1. 8
      kinozal.json
  2. 47
      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"
} }

47
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,23 +187,32 @@ 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
# Create a torrent file # choose download method
file, path = tempfile.mkstemp('.torrent') if self.config.get("magnet"):
file = os.fdopen(file, "wb") 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]
# Download url magnet = 'magnet:?xt=urn:btih:' + res.read().decode()[18:58]
response = self._catch_error_request(url) # return magnet link
logging.debug(magnet + " " + url)
# Write it to a file print(magnet + " " + url)
file.write(response.read()) else:
file.close() # Create a torrent file
file, path = tempfile.mkstemp('.torrent')
# return file path file = os.fdopen(file, "wb")
logging.debug(path + " " + url)
print(path + " " + url) # Download url
response = self._catch_error_request(url)
# Write it to a file
file.write(response.read())
file.close()
# return file path
logging.debug(path + " " + url)
print(path + " " + url)
def search(self, what, cat='all'): def search(self, what, cat='all'):
if self.blocked: if self.blocked:
@ -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