Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
elif mode == 'clear_all_cache':
    from modules.nav_utils import clear_all_cache
    clear_all_cache()
elif mode == 'show_text':
    from modules.nav_utils import show_text
    show_text()
elif mode == 'movie_reviews':
    from modules.nav_utils import movie_reviews
    movie_reviews(params['tmdb_id'], params['rootname'], params['poster'])
elif mode == 'settings_layout':
    from modules.nav_utils import settings_layout
    settings_layout(params.get('settings_type', None))
elif mode == 'download_file':
    from modules.nav_utils import show_busy_dialog
    from modules import downloader
    show_busy_dialog()
    if params.get('db_type') in ('furk_file', 'easynews_file',
                                 'realdebrid_direct_file', 'archive', 'audio'):
        downloader.download(params.get('url'))
    elif params.get('db_type') == 'realdebrid_file':
        from indexers.real_debrid import resolve_rd
        downloader.download(resolve_rd(params.get('url'), False))
    elif params.get('db_type') == 'premiumize_file':
        from apis.premiumize_api import PremiumizeAPI
        downloader.download(PremiumizeAPI().add_headers_to_url(
            params.get('url')))
    elif params.get('db_type') == 'alldebrid_file':
        from indexers.alldebrid import resolve_ad
        downloader.download(resolve_ad(params.get('url'), False))
    else:
        import json
Ejemplo n.º 5
0
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)')