def _return_failed(message='Unknown Error.'): try: progressDialog.close() except Exception: pass self.delete_torrent(torrent_id) hide_busy_dialog() xbmc.sleep(500) xbmcgui.Dialog().ok('FEN Cloud Transfer', message) return False
def add_uncached_torrent(self, magnet_url): import xbmc from modules.nav_utils import show_busy_dialog, hide_busy_dialog from modules.utils import supported_video_extensions def _transfer_info(transfer_id): info = self.transfer_info() if 'status' in info and info['status'] == 'success': for item in info['transfers']: if item['id'] == transfer_id: return item return {} def _return_failed(message='Unknown Error.'): try: progressDialog.close() except Exception: pass self.delete_transfer(transfer_id) hide_busy_dialog() xbmc.sleep(500) xbmcgui.Dialog().ok('FEN Cloud Transfer', message) return False show_busy_dialog() extensions = supported_video_extensions() transfer_id = self.create_transfer(magnet_url) if not transfer_id['status'] == 'success': return _return_failed('ERROR Transferring Torrent.') transfer_id = transfer_id['id'] transfer_info = _transfer_info(transfer_id) if not transfer_info: return _return_failed('ERROR Transferring Torrent.') interval = 5 line1 = 'Saving Torrent to the Premiumize Cloud...' line2 = transfer_info['name'] line3 = transfer_info['message'] progressDialog.create('FEN Cloud Transfer', line1, line2, line3) while not transfer_info['status'] == 'seeding': xbmc.sleep(1000 * interval) transfer_info = _transfer_info(transfer_id) line3 = transfer_info['message'] progressDialog.update(int(float(transfer_info['progress']) * 100), line3=line3) if xbmc.abortRequested == True: return sys.exit() try: if progressDialog.iscanceled(): return _return_failed('Transfer Cancelled.') except Exception: pass if transfer_info.get('status') == 'stalled': return _return_failed('ERROR Transferring Torrent.') xbmc.sleep(1000 * interval) try: progressDialog.close() except Exception: pass hide_busy_dialog() return True
def add_uncached_torrent(self, magnet_url): import xbmc from modules.nav_utils import show_busy_dialog, hide_busy_dialog def _return_failed(message='Unknown Error.'): try: progressDialog.close() except Exception: pass self.delete_transfer(transfer_id) hide_busy_dialog() xbmc.sleep(500) xbmcgui.Dialog().ok('FEN Cloud Transfer', message) return False show_busy_dialog() transfer_id = self.create_transfer(magnet_url) transfer_info = self.list_transfer(transfer_id) if not transfer_info: return _return_failed('ERROR Transferring Torrent.') interval = 5 line1 = 'Saving Torrent to the All-Debrid Cloud (UptoBox)...' line2 = transfer_info['filename'] line3 = transfer_info['status'] progressDialog.create('FEN Cloud Transfer', line1, line2, line3) while not transfer_info['statusCode'] == 4: xbmc.sleep(1000 * interval) transfer_info = self.list_transfer(transfer_id) file_size = transfer_info['size'] line2 = transfer_info['filename'] if transfer_info['statusCode'] == 1: download_speed = round(float(transfer_info['downloadSpeed']) / (1000**2), 2) progress = int(float(transfer_info['downloaded']) / file_size * 100) if file_size > 0 else 0 line3 = "Downloading at %s MB/s from %s peers, %s%% of %sGB completed" % (download_speed, transfer_info['seeders'], progress, round(float(file_size) / (1000 ** 3), 2)) elif transfer_info['statusCode'] == 3: upload_speed = round(float(transfer_info['uploadSpeed']) / (1000 ** 2), 2) progress = int(float(transfer_info['uploaded']) / file_size * 100) if file_size > 0 else 0 line3 = "Uploading at %s MB/s, %s%% of %s GB completed" % (upload_speed, progress, round(float(file_size) / (1000 ** 3), 2)) else: line3 = transfer_info['status'] progress = 0 progressDialog.update(progress, line2=line2, line3=line3) if xbmc.abortRequested == True: return sys.exit() try: if progressDialog.iscanceled(): return _return_failed('Transfer Cancelled.') except Exception: pass if 5 <= transfer_info['statusCode'] <= 10: return _return_failed('ERROR Transferring Torrent.') xbmc.sleep(1000 * interval) try: progressDialog.close() except Exception: pass hide_busy_dialog() return True
def add_uncached_torrent(self, magnet_url): import xbmc from modules.nav_utils import show_busy_dialog, hide_busy_dialog from modules.utils import supported_video_extensions def _return_failed(message='Unknown Error.'): try: progressDialog.close() except Exception: pass self.delete_torrent(torrent_id) hide_busy_dialog() xbmc.sleep(500) xbmcgui.Dialog().ok('FEN Cloud Transfer', message) return False show_busy_dialog() extensions = supported_video_extensions() torrent = self.add_magnet(magnet_url) torrent_id = torrent['id'] if not torrent_id: return _return_failed('ERROR Transferring Torrent.') interval = 5 stalled = ['magnet_error', 'error', 'virus', 'dead'] torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'magnet_conversion': line1 = 'Converting MAGNET...' line2 = torrent_info['filename'] line3 = '%s seeders' % torrent_info['seeders'] timeout = 100 progressDialog.create('FEN Cloud Transfer', line1, line2, line3) while status == 'magnet_conversion' and timeout > 0: progressDialog.update(timeout, line3=line3) if xbmc.abortRequested == True: return sys.exit() try: if progressDialog.iscanceled(): return _return_failed('Transfer Cancelled.') except Exception: pass if any(x in status for x in stalled): return _return_failed('ERROR Transferring Torrent.') timeout -= interval xbmc.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] line3 = '%s seeders' % torrent_info['seeders'] try: progressDialog.close() except Exception: pass if status == 'magnet_conversion': return _return_failed('ERROR Converting Magnet.') if status == 'waiting_files_selection': video_files = [] all_files = torrent_info['files'] for item in all_files: if any(item['path'].lower().endswith(x) for x in extensions): video_files.append(item) try: video = max(video_files, key=lambda x: x['bytes']) file_id = video['id'] except ValueError: return _return_failed('No Video File Found.') self.add_torrent_select(torrent_id, str(file_id)) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloaded': return True file_size = round(float(video['bytes']) / (1000 ** 3), 2) line1 = 'Saving Torrent to the Real-Debrid Cloud...' line2 = torrent_info['filename'] line3 = status progressDialog.create('FEN Cloud Transfer', line1, line2, line3) while not status == 'downloaded': xbmc.sleep(1000 * interval) torrent_info = self.torrent_info(torrent_id) status = torrent_info['status'] if status == 'downloading': line3 = 'Downloading %s GB @ %s mbps from %s peers, %s %% completed' % (file_size, round(float(torrent_info['speed']) / (1000**2), 2), torrent_info['seeders'], torrent_info['progress']) else: line3 = status progressDialog.update(int(float(torrent_info['progress'])), line3=line3) if xbmc.abortRequested == True: return sys.exit() # try: if progressDialog.iscanceled(): return _return_failed('Transfer Cancelled.') # except Exception: # pass if any(x in status for x in stalled): return _return_failed('ERROR Transferring Torrent.') try: progressDialog.close() except Exception: pass hide_busy_dialog() return True hide_busy_dialog() return False
def download(url): from modules.nav_utils import hide_busy_dialog, notification from modules.utils import clean_file_name, clean_title from modules import settings # from modules.utils import logger if url == None: hide_busy_dialog() notification('No URL found for Download. Pick another Source', 6000) return params = dict(parse_qsl(sys.argv[2].replace('?',''))) json_meta = params.get('meta') if json_meta: meta = json.loads(json_meta) db_type = meta.get('vid_type') title = meta.get('search_title') year = meta.get('year') image = meta.get('poster') season = meta.get('season') episode = meta.get('episode') name = params.get('name') else: db_type = params.get('db_type') image = params.get('image') title = params.get('name') title = clean_file_name(title) media_folder = settings.download_directory(db_type) if not media_folder: hide_busy_dialog() resp = xbmcgui.Dialog().yesno( "No Download folder set!", "Fen requires you to set Download Folders.", "Would you like to set a folder now?") if resp: from modules.nav_utils import open_settings return open_settings('7.0') else: return if db_type in ('movie', 'episode'): folder_rootname = '%s (%s)' % (title, year) folder = os.path.join(media_folder, folder_rootname + '/') else: folder = media_folder if db_type == 'episode': folder = os.path.join(folder, 'Season ' + str(season)) try: headers = dict(parse_qsl(url.rsplit('|', 1)[1])) except: headers = dict('') dest = None url = url.split('|')[0] if not 'http' in url: from apis.furk_api import FurkAPI from indexers.furk import filter_furk_tlist, seas_ep_query_list t_files = FurkAPI().t_files(url) t_files = [i for i in t_files if 'video' in i['ct'] and 'bitrate' in i] name, url = filter_furk_tlist(t_files, (None if db_type == 'movie' else seas_ep_query_list(season, episode)))[0:2] dest = os.path.join(folder, name) if db_type == 'archive': ext = 'zip' if db_type == 'audio': ext = os.path.splitext(urlparse(url).path)[1][1:] if not ext in ['wav', 'mp3', 'ogg', 'flac', 'wma', 'aac']: ext = 'mp3' else: ext = os.path.splitext(urlparse(url).path)[1][1:] if not ext in ['mp4', 'mkv', 'flv', 'avi', 'mpg']: ext = 'mp4' if not dest: name_url = unquote(url) file_name = clean_title(name_url.split('/')[-1]) if clean_title(title).lower() in file_name.lower(): transname = os.path.splitext(urlparse(name_url).path)[0].split('/')[-1] else: try: transname = name.translate(None, '\/:*?"<>|').strip('.') except: transname = os.path.splitext(urlparse(name_url).path)[0].split('/')[-1] dest = os.path.join(folder, transname + '.' + ext) sysheaders = quote_plus(json.dumps(headers)) sysurl = quote_plus(url) systitle = quote_plus(transname) sysimage = quote_plus(image) sysfolder = quote_plus(folder) sysdest = quote_plus(dest) script = inspect.getfile(inspect.currentframe()) cmd = 'RunScript(%s, %s, %s, %s, %s, %s, %s)' % (script, sysurl, sysdest, systitle, sysimage, sysfolder, sysheaders) xbmc.executebuiltin(cmd)
def subscriptions_add_list(db_type): from modules.trakt_cache import clear_trakt_list_data from apis.trakt_api import get_trakt_list_selection from modules.nav_utils import show_busy_dialog, hide_busy_dialog, open_settings movie_subscriptions = Subscriptions('movie') tvshow_subscriptions = Subscriptions('tvshow') variables = ('Movies', 'movies', 'movie', 'trakt.subscriptions_movie', 'trakt.subscriptions_movie_display', '8.14', movie_subscriptions) if db_type == 'movie' else ( 'TV Shows', 'shows', 'show', 'trakt.subscriptions_show', 'trakt.subscriptions_show_display', '8.15', tvshow_subscriptions) dialog_display = variables[0] trakt_list_type = variables[1] trakt_dbtype = variables[2] main_setting = variables[3] display_setting = variables[4] open_setting = variables[5] subscription_function = variables[6] clear_library, cancelled, supplied_list = (False for _ in range(3)) path = settings.movies_directory( ) if db_type == 'movie' else settings.tv_show_directory() if xbmcgui.Dialog().yesno( 'Fen Subscriptions', 'Are you sure you have set your Fen [B]%s[/B] Subscription Folder as a Source for the Kodi Library?' % db_type.upper(), '', '', 'Already Done', 'I\'ll Do It Now'): return xbmc.executebuiltin('ActivateWindow(videos,files,return)') for i in ('my_lists', 'liked_lists'): try: clear_trakt_list_data(i) except: pass trakt_list = get_trakt_list_selection(list_choice='subscriptions') if not trakt_list: return open_settings(open_setting) __addon__.setSetting(main_setting, json.dumps(trakt_list)) __addon__.setSetting(display_setting, trakt_list['name']) if trakt_list['name'].lower() == 'none': return open_settings(open_setting) if not xbmcgui.Dialog().yesno( 'Are you sure?', 'Fen will add all [B]%s[/B] from [B]%s[/B] to your Fen Subscriptions, and monitor this list for changes. Do you wish to continue?' % (dialog_display, trakt_list['name'])): __addon__.setSetting(main_setting, '') __addon__.setSetting(display_setting, 'none') return open_settings(open_setting) current_subscriptions = subscription_function.get_subscriptions() if len(current_subscriptions) > 0: if not xbmcgui.Dialog().yesno( 'Current Subscriptions Found!', 'You have items in your [B]%s[/B] Subscription. Fen will delete these before continuing (may take some time). Do you wish to continue?' % (dialog_display)): return open_settings(open_setting) clear_library = True show_busy_dialog() subscription_function.clear_subscriptions(confirm=False, silent=True, db_type=db_type) hide_busy_dialog() dialog = xbmcgui.DialogProgressBG() dialog.create('Please Wait', 'Preparing Trakt List Info...') if trakt_list['name'] in ('Collection', 'Watchlist'): from modules.trakt_cache import clear_trakt_collection_watchlist_data from apis.trakt_api import trakt_fetch_collection_watchlist list_contents = trakt_fetch_collection_watchlist( trakt_list['name'].lower(), trakt_list_type) else: from apis.trakt_api import get_trakt_list_contents from modules.trakt_cache import clear_trakt_list_contents_data list_contents = get_trakt_list_contents(trakt_list['user'], trakt_list['slug']) list_contents = [{ 'media_ids': i[trakt_dbtype]['ids'], 'title': i[trakt_dbtype]['title'] } for i in list_contents if i['type'] == trakt_dbtype] for i in list_contents: if i['media_ids']['tmdb'] == None: i['media_ids']['tmdb'] = get_trakt_tvshow_id(i['media_ids']) threads = [] list_length = len(list_contents) for count, item in enumerate(list_contents, 1): subscription_function.add_trakt_subscription_listitem( db_type, item['media_ids'], count, list_length, path, dialog) dialog.close() end_dialog = 'Operation Cancelled! Not all items from [B]%s[/B] were added.' if cancelled else '[B]%s[/B] added to Subscriptions.' xbmcgui.Dialog().ok('Fen Subscriptions', end_dialog % trakt_list['name']) if clear_library: if xbmcgui.Dialog().yesno( 'Fen Subscriptions', 'Do you wish to clear Kodi\'s Library of your previous Subscription items?' ): import time xbmc.executebuiltin('CleanLibrary(video)') time.sleep(3) while xbmc.getCondVisibility("Window.IsVisible(ProgressDialog)"): time.sleep(1) if xbmcgui.Dialog().yesno( 'Fen Subscriptions', 'Do you wish to scan your new Subscription list into Kodi\'s Library?' ): xbmc.executebuiltin('UpdateLibrary(video)')