Pity, that: Couch potato torrents do not download qbittorrent
DOWNLOAD TAIKO NO TATSUJIN PC | |
HELMET HEROES DOWNLOAD PC | |
EVO 320KBPS FREE DOWNLOAD | |
DOWNLOAD CENTOS 6 ISO |
Source code for couchpotato.core.downloaders.qbittorrent_
frombase64importb16encode,b32decodefromhashlibimportsha1importosfrombencodeimportbencode,bdecodefromcouchpotato.core._base.downloader.mainimportDownloaderBase,ReleaseDownloadListfromcouchpotato.core.helpers.encodingimportspfromcouchpotato.core.helpers.variableimportcleanHostfromcouchpotato.core.loggerimportCPLogfromqbittorrent.clientimportQBittorrentClientlog=CPLog(__name__)autoload='qBittorrent'
[docs]classqBittorrent(DownloaderBase):
protocol=['torrent','torrent_magnet']qb=Nonedef__init__(self):super(qBittorrent,self).__init__()defconnect(self):ifself.qbisnotNone:returnself.qburl=cleanHost(self.conf('host'),protocol=True,ssl=False)ifself.conf('username')andself.conf('password'):self.qb=QBittorrentClient(url)self.qb.login(username=self.conf('username'),password=self.conf('password'))else:self.qb=QBittorrentClient(url)returnself.qbdeftest(self):""" Check if connection works :return: bool """returnself.qb._is_authenticateddefdownload(self,data=None,media=None,filedata=None):""" Send a torrent/nzb file to the downloader :param data: dict returned from provider Contains the release information :param media: media dict with information Used for creating the filename when possible :param filedata: downloaded torrent/nzb filedata The file gets downloaded in the searcher and send to this function This is done to have failed checking before using the downloader, so the downloader doesn't need to worry about that :return: boolean One faile returns false, but the downloaded should log his own errors """ifnotmedia:media={}ifnotdata:data={}log.debug('Sending "%s" to qBittorrent.',(data.get('name')))ifnotself.connect():returnFalseifnotfiledataanddata.get('protocol')=='torrent':log.error('Failed sending torrent, no data')returnFalseifdata.get('protocol')=='torrent_magnet':filedata=self.magnetToTorrent(data.get('url'))iffiledataisFalse:returnFalsedata['protocol']='torrent'info=bdecode(filedata)["info"]torrent_hash=sha1(bencode(info)).hexdigest()# Convert base 32 to hexiflen(torrent_hash)==32:torrent_hash=b16encode(b32decode(torrent_hash))# Send request to qBittorrenttry:self.qb.download_from_file(filedata,label=self.conf('label'))returnself.downloadReturnId(torrent_hash)exceptExceptionase:log.error('Failed to send torrent to qBittorrent: %s',e)returnFalsedefgetTorrentStatus(self,torrent):iftorrent.statein('uploading','queuedUP','stalledUP'):return'seeding'iftorrent.progress==1:return'completed'return'busy'defgetAllDownloadStatus(self,ids):""" Get status of all active downloads :param ids: list of (mixed) downloader ids Used to match the releases for this downloader as there could be other downloaders active that it should ignore :return: list of releases """log.debug('Checking qBittorrent download status.')ifnotself.connect():return[]try:torrents=self.qb.torrents(label=self.conf('label'))release_downloads=ReleaseDownloadList(self)fortorrentintorrents:iftorrent.hashinids:torrent_filelist=self.qb.get_torrent_files(torrent.hash)torrent_files=[]torrent_dir=os.path.join(torrent.save_path,torrent.name)ifos.path.isdir(torrent_dir):torrent.save_path=torrent_diriflen(torrent_filelist)>1andos.path.isdir(torrent_dir):# multi file torrent, path.isdir check makes sure we're not in the root download folderforroot,_,filesinos.walk(torrent.save_path):forfinfiles:torrent_files.append(sp(os.path.join(root,f)))else:# multi or single file placed directly in torrent.save_pathforfintorrent_filelist:file_path=os.path.join(torrent.save_path,f.name)ifos.path.isfile(file_path):torrent_files.append(sp(file_path))release_downloads.append({'id':torrent.hash,'name':torrent.name,'status':self.getTorrentStatus(torrent),'seed_ratio':torrent.ratio,'original_status':torrent.state,'timeleft':torrent.progress*100iftorrent.progresselse-1,# percentage'folder':sp(torrent.save_path),'files':torrent_files})returnrelease_downloadsexceptExceptionase:log.error('Failed to get status from qBittorrent: %s',e)return[]defpause(self,release_download,pause=True):ifnotself.connect():returnFalsetorrent=self.qb.get_torrent(release_download['id'])iftorrentisNone:returnFalseifpause:returnself.qb.pause(release_download['id'])returnself.qb.resume(release_download['id'])defremoveFailed(self,release_download):log.info('%s failed downloading, deleting...',release_download['name'])returnself.processComplete(release_download,delete_files=True)defprocessComplete(self,release_download,delete_files):log.debug('Requesting qBittorrent to remove the torrent %s%s.',(release_download['name'],' and cleanup the downloaded files'ifdelete_fileselse''))ifnotself.connect():returnFalsetorrent=self.qb.get_torrent(release_download['id'])iftorrentisNone:returnFalseifdelete_files:self.qb.delete_permanently(release_download['id'])# deletes torrent with dataelse:self.qb.delete(release_download['id'])# just removes the torrent, doesn't delete datareturnTrueconfig=[{'name':'qbittorrent','groups':[{'tab':'downloaders','list':'download_providers','name':'qbittorrent','label':'qbittorrent','description':'','wizard':True,'options':[{'name':'enabled','default':0,'type':'enabler','radio_group':'torrent',},{'name':'host','default':'http://localhost:8080/','description':'RPC Communication URI. Usually <strong>http://localhost:8080/</strong>'},{'name':'username',},{'name':'password','type':'password',},{'name':'label','label':'Torrent Label','default':'couchpotato',},{'name':'remove_complete','label':'Remove torrent','default':False,'advanced':True,'type':'bool','description':'Remove the torrent after it finishes seeding.',},{'name':'delete_files','label':'Remove files','default':True,'type':'bool','advanced':True,'description':'Also remove the leftover files.',},{'name':'paused','type':'bool','advanced':True,'default':False,'description':'Add the torrent paused.',},{'name':'manual','default':0,'type':'bool','advanced':True,'description':'Disable this downloader for automated searches, but use it when I manually send a release.',},],}],}]© Copyright 2016, Ruud Burger and contributors. Revision .
-
-