def real_debrid_downloader(self, torrent_object): from resources.lib.common import source_utils tools.showDialog.notification(tools.addonName, tools.lang(32072).encode('utf-8')) current_percent = 0 debrid = real_debrid.RealDebrid() magnet = debrid.addMagnet(torrent_object['magnet']) info = debrid.torrentInfo(magnet['id']) torrent_id = info['id'] database.add_assist_torrent(torrent_id, 'real_debrid', 'queued', torrent_object['release_title'], str(current_percent)) key_list = [] for file in info['files']: filename = file['path'] key = file['id'] if any(filename.lower().endswith(extension) for extension in source_utils.COMMON_VIDEO_EXTENSIONS): key_list.append(key) break debrid.torrentSelect(torrent_id, ','.join(key_list)) downloading_status = ['queued', 'downloading'] current_percent = 0 timestamp = time.time() while not monitor.abortRequested(): if monitor.waitForAbort(120): break try: info = debrid.torrentInfo(torrent_id) if info['status'] == 'downloaded': tools.showDialog.notification( tools.addonName + ': %s' % self.title, tools.lang(32072).encode('utf-8') + ' %s' % self.title, time=5000) database.add_assist_torrent( torrent_id, 'real_debrid', 'finished', torrent_object['release_title'], str(current_percent)) debrid.deleteTorrent(torrent_id) break if info['status'] in downloading_status: if info['progress'] == current_percent: if timestamp == (time.time() + 10800): database.add_assist_torrent( torrent_id, 'real_debrid', 'failed', torrent_object['release_title'], str(current_percent)) debrid.deleteTorrent(torrent_id) tools.showDialog.notification( tools.addonName, 'Cache assist for %s has failed due to no progress' % self.title) break continue else: database.add_assist_torrent( torrent_id, 'real_debrid', 'downloading', torrent_object['release_title'], str(current_percent)) current_percent = info['progress'] continue else: database.add_assist_torrent( torrent_id, 'real_debrid', 'failed', torrent_object['release_title'], str(current_percent)) debrid.deleteTorrent(torrent_id) tools.log( 'Could not create cache for magnet- %s' % torrent_object['magnet'], 'info') tools.showDialog.notification( tools.addonName, 'Cache assist for %s has failed according to Real Debrid' % self.title) break except: debrid.deleteTorrent(torrent_id)
def premiumize_downloader(self, torrent_object): current_percent = 0 debrid = premiumize.PremiumizeFunctions() try: transfer_id = debrid.create_transfer( torrent_object['magnet'])['id'] tools.showDialog.notification(tools.addonName, tools.lang(32072).encode('utf-8')) database.add_assist_torrent(transfer_id, 'premiumize', 'queued', torrent_object['release_title'], str(current_percent)) except: tools.log('Failed to start premiumize debrid transfer', 'error') return timestamp = time.time() while not monitor.abortRequested(): try: if monitor.waitForAbort(120): break transfer_status = [ i for i in debrid.list_transfers()['transfers'] if i['id'] == transfer_id ][0] current_percent = transfer_status['progress'] if transfer_status['status'] == 'finished': database.add_assist_torrent( transfer_id, 'premiumize', transfer_status['status'], torrent_object['release_title'], str(current_percent)) if self.notified == False: tools.showDialog.notification( tools.addonName + ': %s' % self.title, 'New cached sources have been created for %s' % self.title, time=5000) debrid.delete_transfer(transfer_id) database.add_premiumize_transfer(transfer_id) from resources.lib.common import maintenance maintenance.premiumize_transfer_cleanup() break if current_percent == transfer_status['progress']: if timestamp == (time.time() + 10800): database.add_assist_torrent( transfer_id, 'premiumize', 'failed', torrent_object['release_title'], str(current_percent)) debrid.delete_transfer(transfer_id) tools.showDialog.notification( tools.addonName, 'Cache assist for %s has failed due to no progress' % self.title) break continue else: database.add_assist_torrent( transfer_id, 'premiumize', transfer_status['status'], torrent_object['release_title'], str(current_percent)) except: database.add_assist_torrent(transfer_id, 'premiumize', 'failed', torrent_object['release_title'], str(current_percent)) debrid.delete_transfer(transfer_id) break return
def real_debrid_downloader(self, torrent_object, args): from resources.lib.common import source_utils tools.log('REAL DEBRID CACHE ASSIST STARTING') tools.showDialog.notification( tools.addonName, 'Cache Assist is attempting to build a torrent source') current_percent = 0 episodeStrings, seasonStrings = source_utils.torrentCacheStrings(args) debrid = real_debrid.RealDebrid() magnet = debrid.addMagnet(torrent_object['magnet']) info = debrid.torrentInfo(magnet['id']) torrent_id = info['id'] file_key = None database.add_assist_torrent(torrent_id, 'real_debrid', 'queued', torrent_object['release_title'], str(current_percent)) for file in info['files']: filename = file['path'] key = file['id'] if any( source_utils.cleanTitle(episodeString) in source_utils.cleanTitle(filename) for episodeString in episodeStrings): if any(filename.lower().endswith(extension) for extension in source_utils.COMMON_VIDEO_EXTENSIONS): file_key = key break debrid.torrentSelect(torrent_id, file_key) downloading_status = ['queued', 'downloading'] current_percent = 0 timestamp = time.time() while not monitor.abortRequested(): if monitor.waitForAbort(120): break try: info = debrid.torrentInfo(torrent_id) if info['status'] == 'downloaded': tools.showDialog.notification( tools.addonName + ': %s' % self.title, 'New cached sources have been created for %s' % self.title, time=5000) database.add_assist_torrent( torrent_id, 'real_debrid', 'finished', torrent_object['release_title'], str(current_percent)) debrid.deleteTorrent(torrent_id) break if info['status'] in downloading_status: if info['progress'] == current_percent: if timestamp == (time.time() + 10800): database.add_assist_torrent( torrent_id, 'real_debrid', 'failed', torrent_object['release_title'], str(current_percent)) debrid.deleteTorrent(torrent_id) tools.showDialog.notification( tools.addonName, 'Cache assist for %s has failed due to no progress' % self.title) break continue else: database.add_assist_torrent( torrent_id, 'real_debrid', 'downloading', torrent_object['release_title'], str(current_percent)) current_percent = info['progress'] continue else: database.add_assist_torrent( torrent_id, 'real_debrid', 'failed', torrent_object['release_title'], str(current_percent)) debrid.deleteTorrent(torrent_id) tools.log( 'Could not create cache for magnet- %s' % torrent_object['magnet'], 'info') tools.showDialog.notification( tools.addonName, 'Cache assist for %s has failed according to Real Debrid' % self.title) break except: debrid.deleteTorrent(torrent_id)