qbittorrent downloader working
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from base64 import b16encode, b32decode
|
from base64 import b16encode, b32decode
|
||||||
|
from bencode import bencode, bdecode
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -13,7 +14,6 @@ log = CPLog(__name__)
|
|||||||
|
|
||||||
autoload = 'qBittorrent'
|
autoload = 'qBittorrent'
|
||||||
|
|
||||||
|
|
||||||
class qBittorrent(Downloader):
|
class qBittorrent(Downloader):
|
||||||
|
|
||||||
protocol = ['torrent', 'torrent_magnet']
|
protocol = ['torrent', 'torrent_magnet']
|
||||||
@@ -45,7 +45,6 @@ class qBittorrent(Downloader):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def download(self, data = None, media = None, filedata = None):
|
def download(self, data = None, media = None, filedata = None):
|
||||||
if not media: media = {}
|
if not media: media = {}
|
||||||
if not data: data = {}
|
if not data: data = {}
|
||||||
@@ -59,6 +58,15 @@ class qBittorrent(Downloader):
|
|||||||
log.error('Failed sending torrent, no data')
|
log.error('Failed sending torrent, no data')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
if data.get('protocol') == 'torrent_magnet':
|
||||||
|
filedata = self.magnetToTorrent(data.get('url'))
|
||||||
|
|
||||||
|
if filedata is False:
|
||||||
|
return False
|
||||||
|
|
||||||
|
data['protocol'] = 'torrent'
|
||||||
|
|
||||||
info = bdecode(filedata)["info"]
|
info = bdecode(filedata)["info"]
|
||||||
torrent_hash = sha1(bencode(info)).hexdigest().upper()
|
torrent_hash = sha1(bencode(info)).hexdigest().upper()
|
||||||
|
|
||||||
@@ -68,14 +76,7 @@ class qBittorrent(Downloader):
|
|||||||
|
|
||||||
# Send request to qBittorrent
|
# Send request to qBittorrent
|
||||||
try:
|
try:
|
||||||
if data.get('protocol') == 'torrent_magnet':
|
self.qb.add_file(filedata)
|
||||||
torrent = self.qb.add_url(filedata)
|
|
||||||
else:
|
|
||||||
torrent = self.qb.add_file(filedata)
|
|
||||||
|
|
||||||
if not torrent:
|
|
||||||
log.error('Unable to find the torrent, did it fail to load?')
|
|
||||||
return False
|
|
||||||
|
|
||||||
return self.downloadReturnId(torrent_hash)
|
return self.downloadReturnId(torrent_hash)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -100,18 +101,18 @@ class qBittorrent(Downloader):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
torrents = self.qb.get_torrents()
|
torrents = self.qb.get_torrents()
|
||||||
self.qb.update_general() # get extra info
|
|
||||||
|
|
||||||
release_downloads = ReleaseDownloadList(self)
|
release_downloads = ReleaseDownloadList(self)
|
||||||
|
|
||||||
for torrent in torrents:
|
for torrent in torrents:
|
||||||
if torrent.hash in ids:
|
if torrent.hash in ids:
|
||||||
|
self.qb.update_general() # get extra info
|
||||||
torrent_files = []
|
torrent_files = []
|
||||||
t_files = torrent.get_files()
|
t_files = torrent.get_files()
|
||||||
|
|
||||||
check_dir = os.path.join(torrent.save_path, torrent.name)
|
check_dir = os.path.join(torrent.save_path, torrent.name)
|
||||||
if os.path.isdir(check_dir):
|
if os.path.isdir(check_dir):
|
||||||
torrent.save_path = os.path.isdir(check_dir)
|
torrent.save_path = check_dir
|
||||||
|
|
||||||
if len(t_files) > 1 and os.path.isdir(torrent.save_path): # multi file torrent
|
if len(t_files) > 1 and os.path.isdir(torrent.save_path): # multi file torrent
|
||||||
for root, _, files in os.walk(torrent.save_path):
|
for root, _, files in os.walk(torrent.save_path):
|
||||||
|
|||||||
Reference in New Issue
Block a user