Exemple #1
0
 def furkPacks(self, name, file_id, highlight=None, download=False):
     from apis.furk_api import FurkAPI
     kodi_utils.show_busy_dialog()
     t_files = FurkAPI().t_files(file_id)
     t_files = [i for i in t_files if 'video' in i['ct'] and 'bitrate' in i]
     t_files.sort(key=lambda k: k['name'].lower())
     kodi_utils.hide_busy_dialog()
     if download: return t_files
     default_furk_icon = kodi_utils.translate_path(
         'special://home/addons/script.tikiart/resources/media/furk.png')
     list_items = [{
         'line1':
         '%.2f GB | %s' % (float(item['size']) / 1073741824,
                           clean_file_name(item['name']).upper()),
         'icon':
         default_furk_icon
     } for item in t_files]
     kwargs = {
         'items': json.dumps(list_items),
         'heading': name,
         'highlight': highlight,
         'enumerate': 'true',
         'multi_choice': 'false',
         'multi_line': 'false'
     }
     chosen_result = kodi_utils.select_dialog(t_files, **kwargs)
     if chosen_result is None: return None
     link = chosen_result['url_dl']
     name = chosen_result['name']
     return FenPlayer().run(link, 'video')
Exemple #2
0
def imdb_keywords_choice(db_type, imdb_id, poster):
    from apis.imdb_api import imdb_keywords

    def _builder():
        for item in keywords_info:
            obj = {
                'line':
                item,
                'function':
                json.dumps({
                    'mode': mode,
                    'action': 'imdb_keywords_list_contents',
                    'list_id': item,
                    'iconImage': 'imdb.png'
                })
            }
            yield obj

    kodi_utils.show_busy_dialog()
    keywords_info = imdb_keywords(imdb_id)
    if len(keywords_info) == 0:
        kodi_utils.hide_busy_dialog()
        kodi_utils.notification(32760, 2500)
        return None
    meta_type = 'movie' if db_type == 'movies' else 'tvshow'
    mode = 'build_%s_list' % meta_type
    items = list(_builder())
    kodi_utils.hide_busy_dialog()
    return open_window(['windows.extras', 'ShowSelectMedia'],
                       'select_media.xml',
                       items=items,
                       poster=poster,
                       context_active_action='keywords')
def rescrape_with_disabled(db_type, meta, season=None, episode=None):
    from caches.providers_cache import ExternalProvidersCache
    from modules.sources import Sources
    from modules.nav_utils import clear_cache
    kodi_utils.show_busy_dialog()
    deleted = ExternalProvidersCache().delete_cache_single(
        db_type, str(meta['tmdb_id']))
    if not deleted: return kodi_utils.notification(32574)
    clear_cache('internal_scrapers', silent=True)
    if db_type == 'movie':
        play_params = {
            'mode': 'play_media',
            'vid_type': 'movie',
            'tmdb_id': meta['tmdb_id'],
            'disabled_ignored': 'true',
            'prescrape': 'false'
        }
    else:
        play_params = {
            'mode': 'play_media',
            'vid_type': 'episode',
            'tmdb_id': meta['tmdb_id'],
            'tvshowtitle': meta['rootname'],
            'season': season,
            'episode': episode,
            'disabled_ignored': 'true',
            'prescrape': 'false'
        }
    kodi_utils.hide_busy_dialog()
    Sources().playback_prep(play_params)
Exemple #4
0
def manual_add_magnet_to_cloud(params):
    show_busy_dialog()
    function = [i[2] for i in debrid_list if i[0] == params['provider']][0]
    result = function.create_transfer(params['magnet_url'])
    function.clear_cache()
    hide_busy_dialog()
    if result == 'failed': notification(32490)
    else: notification(32576)
Exemple #5
0
 def new_page(self):
     try:
         show_busy_dialog()
         self.win.reset()
         self.current_page += 1
         self.next_page_params['in_progress'] = 'true'
         self.list_items, self.next_page_params = self.ImagesInstance.run(
             self.next_page_params)
         hide_busy_dialog()
         self.make_page()
     except:
         self.close()
Exemple #6
0
 def run(self):
     self.downPrep()
     self.getDownFolder()
     if not self.getDestinationFolder():
         return kodi_utils.hide_busy_dialog()
     self.getURLandHeaders()
     if self.url in (None, 'None', ''):
         kodi_utils.hide_busy_dialog()
         return kodi_utils.notification(32692, 4000)
     self.getFilename()
     self.getExtension()
     self.download_runner(self.url, self.final_destination, self.extension)
Exemple #7
0
 def debridPacks(self,
                 debrid_provider,
                 name,
                 magnet_url,
                 info_hash,
                 highlight=None,
                 download=False):
     if debrid_provider == 'Real-Debrid':
         from apis.real_debrid_api import RealDebridAPI as debrid_function
         icon = 'realdebrid.png'
     elif debrid_provider == 'Premiumize.me':
         from apis.premiumize_api import PremiumizeAPI as debrid_function
         icon = 'premiumize.png'
     elif debrid_provider == 'AllDebrid':
         from apis.alldebrid_api import AllDebridAPI as debrid_function
         icon = 'alldebrid.png'
     kodi_utils.show_busy_dialog()
     try:
         debrid_files = debrid_function().display_magnet_pack(
             magnet_url, info_hash)
     except:
         debrid_files = None
     kodi_utils.hide_busy_dialog()
     if not debrid_files: return kodi_utils.notification(32574)
     debrid_files.sort(key=lambda k: k['filename'].lower())
     if download: return debrid_files, debrid_function
     default_debrid_icon = kodi_utils.translate_path(
         'special://home/addons/script.tikiart/resources/media/%s' % icon)
     list_items = [{
         'line1':
         '%.2f GB | %s' % (float(item['size']) / 1073741824,
                           clean_file_name(item['filename']).upper()),
         'icon':
         default_debrid_icon
     } for item in debrid_files]
     kwargs = {
         'items': json.dumps(list_items),
         'heading': name,
         'highlight': highlight,
         'enumerate': 'true',
         'multi_choice': 'false',
         'multi_line': 'false'
     }
     chosen_result = kodi_utils.select_dialog(debrid_files, **kwargs)
     if chosen_result is None: return None
     url_dl = chosen_result['link']
     if debrid_provider in ('Real-Debrid', 'AllDebrid'):
         link = debrid_function().unrestrict_link(url_dl)
     elif debrid_provider == 'Premiumize.me':
         link = debrid_function().add_headers_to_url(url_dl)
     name = chosen_result['filename']
     return FenPlayer().run(link, 'video')
 def _return_failed(message=32574, cancelled=False):
     try:
         progressDialog.close()
     except Exception:
         pass
     hide_busy_dialog()
     sleep(500)
     if cancelled:
         if confirm_dialog(text=32044, top_space=True):
             ok_dialog(heading=32733, text=ls(32732) % ls(32054))
         else:
             self.delete_torrent(torrent_id)
     else:
         ok_dialog(heading=32733, text=message)
     return False
Exemple #9
0
def open_settings(query, addon='plugin.video.fen'):
    kodi_utils.sleep(250)
    if query:
        try:
            button, control = 100, 80
            kodi_utils.hide_busy_dialog()
            menu, function = query.split('.')
            kodi_utils.execute_builtin('Addon.OpenSettings(%s)' % addon)
            kodi_utils.execute_builtin('SetFocus(%i)' % (int(menu) - button))
            kodi_utils.execute_builtin('SetFocus(%i)' %
                                       (int(function) - control))
        except:
            kodi_utils.execute_builtin('Addon.OpenSettings(%s)' % addon)
    else:
        kodi_utils.execute_builtin('Addon.OpenSettings(%s)' % addon)
Exemple #10
0
 def playback_prep(self, params=None):
     self._clear_properties()
     if params: self.params = params
     self.prescrape = self.params.get('prescrape', self.prescrape) == 'true'
     self.background = self.params.get('background', 'false') == 'true'
     if self.background: kodi_utils.hide_busy_dialog()
     else: kodi_utils.show_busy_dialog()
     self.disabled_ignored = self.params.get(
         'disabled_ignored', self.disabled_ignored) == 'true'
     self.from_library = self.params.get('library', 'False') == 'True'
     self.vid_type = self.params['vid_type']
     self.tmdb_id = self.params['tmdb_id']
     self.ep_name = self.params.get('ep_name')
     self.plot = self.params.get('plot')
     self.custom_title = self.params.get('custom_title', None)
     self.custom_year = self.params.get('custom_year', None)
     if 'autoplay' in self.params:
         self.autoplay = self.params.get('autoplay', 'False') == 'True'
     else:
         self.autoplay = settings.auto_play(self.vid_type)
     if 'season' in self.params: self.season = int(self.params['season'])
     else: self.season = ''
     if 'episode' in self.params: self.episode = int(self.params['episode'])
     else: self.episode = ''
     if 'meta' in self.params: self.meta = json.loads(self.params['meta'])
     else: self._grab_meta()
     self.active_internal_scrapers = settings.active_internal_scrapers()
     self.active_external = 'external' in self.active_internal_scrapers
     self.provider_sort_ranks = settings.provider_sort_ranks()
     self.sleep_time = settings.display_sleep_time()
     self.scraper_settings = settings.scraping_settings()
     self.include_prerelease_results = settings.include_prerelease_results()
     self.ignore_filters = settings.ignore_results_filter()
     self.filter_hevc = settings.filter_status('hevc')
     self.filter_hdr = settings.filter_status('hdr')
     self.filter_dv = settings.filter_status('dv')
     self.hybrid_allowed = self.filter_hdr in (0, 2)
     self.sort_function = settings.results_sort_order()
     self.display_uncached_torrents = settings.display_uncached_torrents()
     self.quality_filter = self._quality_filter()
     self.filter_size = get_setting('results.filter.size', '0') == 'true'
     self.include_unknown_size = get_setting(
         'results.include.unknown.size') == 'true'
     self.include_3D_results = get_setting('include_3d_results') == 'true'
     self._update_meta()
     self._search_info()
     kodi_utils.set_property('fen_playback_meta', json.dumps(self.meta))
     self.get_sources()
Exemple #11
0
 def _return_failed(message=32574, cancelled=False):
     try:
         kodi_utils.progressDialog.close()
     except Exception:
         pass
     kodi_utils.hide_busy_dialog()
     kodi_utils.sleep(500)
     if cancelled:
         if kodi_utils.confirm_dialog(text=32044, top_space=True):
             kodi_utils.ok_dialog(heading=32733,
                                  text=ls(32732) % ls(32063),
                                  top_space=True)
         else:
             self.delete_transfer(transfer_id)
     else:
         kodi_utils.ok_dialog(heading=2733, text=message)
     return False
Exemple #12
0
    def add_uncached_torrent(self, magnet_url, pack=False):
        def _return_failed(message=32574, cancelled=False):
            try:
                kodi_utils.progressDialog.close()
            except Exception:
                pass
            kodi_utils.hide_busy_dialog()
            kodi_utils.sleep(500)
            if cancelled:
                if kodi_utils.confirm_dialog(text=32044, top_space=True):
                    kodi_utils.ok_dialog(heading=32733,
                                         text=ls(32732) % ls(32063),
                                         top_space=True)
                else:
                    self.delete_transfer(transfer_id)
            else:
                kodi_utils.ok_dialog(heading=2733, text=message)
            return False

        kodi_utils.show_busy_dialog()
        transfer_id = self.create_transfer(magnet_url)
        if not transfer_id: return _return_failed()
        transfer_info = self.list_transfer(transfer_id)
        if not transfer_info: return _return_failed()
        if pack:
            self.clear_cache()
            kodi_utils.hide_busy_dialog()
            kodi_utils.ok_dialog(text=ls(32732) % ls(32063))
            return True
        interval = 5
        line = '%s[CR]%s[CR]%s'
        line1 = '%s...' % (ls(32732) % ls(32063))
        line2 = transfer_info['filename']
        line3 = transfer_info['status']
        kodi_utils.progressDialog.create(ls(32733),
                                         line % (line1, line2, line3))
        while not transfer_info['statusCode'] == 4:
            kodi_utils.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 = ls(32734) % (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 = ls(32735) % (upload_speed, progress,
                                     round(float(file_size) / (1000**3), 2))
            else:
                line3 = transfer_info['status']
                progress = 0
            kodi_utils.progressDialog.update(progress,
                                             line % (line1, line2, line3))
            if kodi_utils.monitor.abortRequested() == True: return sysexit()
            try:
                if kodi_utils.progressDialog.iscanceled():
                    return _return_failed(32736, cancelled=True)
            except Exception:
                pass
            if 5 <= transfer_info['statusCode'] <= 10:
                return _return_failed()
        kodi_utils.sleep(1000 * interval)
        try:
            kodi_utils.progressDialog.close()
        except Exception:
            pass
        kodi_utils.hide_busy_dialog()
        return True
    def add_uncached_torrent(self, magnet_url, pack=False):
        from modules.kodi_utils import show_busy_dialog, hide_busy_dialog
        from modules.source_utils import supported_video_extensions

        def _return_failed(message=32574, cancelled=False):
            try:
                progressDialog.close()
            except Exception:
                pass
            hide_busy_dialog()
            sleep(500)
            if cancelled:
                if confirm_dialog(text=32044, top_space=True):
                    ok_dialog(heading=32733, text=ls(32732) % ls(32054))
                else:
                    self.delete_torrent(torrent_id)
            else:
                ok_dialog(heading=32733, text=message)
            return False

        show_busy_dialog()
        try:
            active_count = self.torrents_activeCount()
            if active_count['nb'] >= active_count['limit']:
                return _return_failed()
        except:
            pass
        interval = 5
        stalled = ('magnet_error', 'error', 'virus', 'dead')
        extensions = supported_video_extensions()
        torrent = self.add_magnet(magnet_url)
        torrent_id = torrent['id']
        if not torrent_id: return _return_failed()
        torrent_info = self.torrent_info(torrent_id)
        if 'error_code' in torrent_info: return _return_failed()
        status = torrent_info['status']
        line = '%s[CR]%s[CR]%s'
        if status == 'magnet_conversion':
            line1 = ls(32737)
            line2 = torrent_info['filename']
            line3 = ls(32738) % torrent_info['seeders']
            timeout = 100
            progressDialog.create(ls(32733), line % (line1, line2, line3))
            while status == 'magnet_conversion' and timeout > 0:
                progressDialog.update(timeout, line % (line1, line2, line3))
                if monitor.abortRequested() == True: return sysexit()
                try:
                    if progressDialog.iscanceled():
                        return _return_failed(32736, cancelled=True)
                except Exception:
                    pass
                timeout -= interval
                sleep(1000 * interval)
                torrent_info = self.torrent_info(torrent_id)
                status = torrent_info['status']
                if any(x in status for x in stalled):
                    return _return_failed()
                line3 = ls(32738) % torrent_info['seeders']
            try:
                progressDialog.close()
            except Exception:
                pass
        if status == 'downloaded':
            hide_busy_dialog()
            return True
        if status == 'magnet_conversion':
            return _return_failed()
        if any(x in status for x in stalled):
            return _return_failed(str(status))
        if status == 'waiting_files_selection':
            video_files = []
            append = video_files.append
            all_files = torrent_info['files']
            for item in all_files:
                if any(item['path'].lower().endswith(x) for x in extensions):
                    append(item)
            if pack:
                try:
                    if len(video_files) == 0: return _return_failed()
                    video_files.sort(key=lambda x: x['path'])
                    torrent_keys = [str(i['id']) for i in video_files]
                    if not torrent_keys: return _return_failed(ls(32736))
                    torrent_keys = ','.join(torrent_keys)
                    self.add_torrent_select(torrent_id, torrent_keys)
                    ok_dialog(text=ls(32732) % ls(32054))
                    self.clear_cache()
                    hide_busy_dialog()
                    return True
                except Exception:
                    return _return_failed()
            else:
                try:
                    video = max(video_files, key=lambda x: x['bytes'])
                    file_id = video['id']
                except ValueError:
                    return _return_failed()
                self.add_torrent_select(torrent_id, str(file_id))
            sleep(2000)
            torrent_info = self.torrent_info(torrent_id)
            status = torrent_info['status']
            if status == 'downloaded':
                hide_busy_dialog()
                return True
            file_size = round(float(video['bytes']) / (1000**3), 2)
            line1 = '%s...' % (ls(32732) % ls(32054))
            line2 = torrent_info['filename']
            line3 = status
            progressDialog.create(ls(32733), line % (line1, line2, line3))
            while not status == 'downloaded':
                sleep(1000 * interval)
                torrent_info = self.torrent_info(torrent_id)
                status = torrent_info['status']
                if status == 'downloading':
                    line3 = ls(32739) % (
                        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'])),
                                      line % (line1, line2, line3))
                if monitor.abortRequested() == True: return sys.exit()
                try:
                    if progressDialog.iscanceled():
                        return _return_failed(32736, cancelled=True)
                except:
                    pass
                if any(x in status for x in stalled): return _return_failed()
            try:
                progressDialog.close()
            except:
                pass
            hide_busy_dialog()
            return True
        hide_busy_dialog()
        return False
Exemple #14
0
def options_menu(params, meta=None):
    def _builder():
        for item in listing:
            line1 = item[0]
            line2 = item[1]
            if line2 == '': line2 = line1
            yield {'line1': line1, 'line2': line2}

    content = params.get('content', None)
    if not content: content = kodi_utils.container_content()[:-1]
    season = params.get('season', None)
    episode = params.get('episode', None)
    if not meta:
        function = metadata.movie_meta if content == 'movie' else metadata.tvshow_meta
        meta_user_info = metadata.retrieve_user_info()
        meta = function('tmdb_id', params['tmdb_id'], meta_user_info)
    watched_indicators = settings.watched_indicators()
    on_str, off_str, currently_str, open_str, settings_str = ls(32090), ls(
        32027), ls(32598), ls(32641), ls(32247)
    autoplay_status, autoplay_toggle, quality_setting = (on_str, 'false', 'autoplay_quality_%s' % content) if settings.auto_play(content) \
                else (off_str, 'true', 'results_quality_%s' % content)
    quality_filter_setting = 'autoplay_quality_%s' % content if autoplay_status == on_str else 'results_quality_%s' % content
    autoplay_next_status, autoplay_next_toggle = (
        on_str, 'false') if settings.autoplay_next_episode() else (off_str,
                                                                   'true')
    results_xml_style_status = get_setting('results.xml_style', 'Default')
    results_filter_ignore_status, results_filter_ignore_toggle = (
        on_str, 'false') if settings.ignore_results_filter() else (off_str,
                                                                   'true')
    results_sorting_status = get_setting('results.sort_order_display').replace(
        '$ADDON[plugin.video.fen 32582]', ls(32582))
    current_results_highlights_action = get_setting('highlight.type')
    results_highlights_status = ls(
        32240) if current_results_highlights_action == '0' else ls(
            32583) if current_results_highlights_action == '1' else ls(32241)
    current_subs_action = get_setting('subtitles.subs_action')
    current_subs_action_status = 'Auto' if current_subs_action == '0' else ls(
        32193) if current_subs_action == '1' else off_str
    active_internal_scrapers = [
        i.replace('_', '') for i in settings.active_internal_scrapers()
    ]
    current_scrapers_status = ', '.join([
        i for i in active_internal_scrapers
    ]) if len(active_internal_scrapers) > 0 else 'N/A'
    current_quality_status = ', '.join(
        settings.quality_filter(quality_setting))
    uncached_torrents_status, uncached_torrents_toggle = (
        on_str, 'false') if settings.display_uncached_torrents() else (off_str,
                                                                       'true')
    listing = []
    base_str1 = '%s%s'
    base_str2 = '%s: [B]%s[/B]' % (currently_str, '%s')
    if content in ('movie', 'episode'):
        multi_line = 'true'
        listing += [(ls(32014), '', 'clear_and_rescrape')]
        listing += [(ls(32006), '', 'rescrape_with_disabled')]
        listing += [(ls(32135), '', 'scrape_with_custom_values')]
        listing += [(base_str1 % (ls(32175), ' (%s)' % content),
                     base_str2 % autoplay_status, 'toggle_autoplay')]
        if autoplay_status == on_str and content == 'episode':
            listing += [
                (base_str1 % (ls(32178), ''), base_str2 % autoplay_next_status,
                 'toggle_autoplay_next')
            ]
        listing += [(base_str1 % (ls(32105), ' (%s)' % content),
                     base_str2 % current_quality_status, 'set_quality')]
        listing += [(base_str1 % ('', '%s %s' % (ls(32055), ls(32533))),
                     base_str2 % current_scrapers_status, 'enable_scrapers')]
        if autoplay_status == off_str:
            listing += [(base_str1 % ('', ls(32140)),
                         base_str2 % results_xml_style_status,
                         'set_results_xml_display')]
            listing += [
                (base_str1 % ('', ls(32151)),
                 base_str2 % results_sorting_status, 'set_results_sorting')
            ]
            listing += [(base_str1 % ('', ls(32138)),
                         base_str2 % results_highlights_status,
                         'set_results_highlights')]
        listing += [(base_str1 % ('', ls(32686)),
                     base_str2 % results_filter_ignore_status,
                     'set_results_filter_ignore')]
        listing += [(base_str1 % ('', ls(32183)),
                     base_str2 % current_subs_action_status, 'set_subs_action')
                    ]
        if 'external' in active_internal_scrapers:
            listing += [(base_str1 % ('', ls(32160)),
                         base_str2 % uncached_torrents_status,
                         'toggle_torrents_display_uncached')]
    else:
        multi_line = 'false'
    listing += [(ls(32046), '', 'extras_lists_choice')]
    if content in ('movie', 'tvshow') and meta:
        listing += [
            (ls(32604) %
             (ls(32028) if meta['mediatype'] == 'movie' else ls(32029)), '',
             'clear_media_cache')
        ]
    if watched_indicators == 1:
        listing += [(ls(32497) % ls(32037), '', 'clear_trakt_cache')]
    if content in ('movie', 'episode'):
        listing += [(ls(32637), '', 'clear_scrapers_cache')]
    listing += [('%s %s' % (ls(32118), ls(32513)), '',
                 'open_external_scrapers_manager')]
    listing += [('%s %s %s' % (open_str, ls(32522), settings_str), '',
                 'open_scraper_settings')]
    listing += [('%s %s %s' % (open_str, ls(32036), settings_str), '',
                 'open_fen_settings')]
    listing += [(ls(32640), '', 'save_and_exit')]
    list_items = list(_builder())
    heading = ls(32646).replace('[B]', '').replace('[/B]', '')
    kwargs = {
        'items': json.dumps(list_items),
        'heading': heading,
        'enumerate': 'false',
        'multi_choice': 'false',
        'multi_line': multi_line
    }
    choice = kodi_utils.select_dialog([i[2] for i in listing], **kwargs)
    if choice in (None, 'save_and_exit'): return
    elif choice == 'clear_and_rescrape':
        return clear_and_rescrape(content, meta, season, episode)
    elif choice == 'rescrape_with_disabled':
        return rescrape_with_disabled(content, meta, season, episode)
    elif choice == 'scrape_with_custom_values':
        return scrape_with_custom_values(content, meta, season, episode)
    elif choice == 'toggle_autoplay':
        set_setting('auto_play_%s' % content, autoplay_toggle)
    elif choice == 'toggle_autoplay_next':
        set_setting('autoplay_next_episode', autoplay_next_toggle)
    elif choice == 'enable_scrapers':
        enable_scrapers_choice()
    elif choice == 'set_results_xml_display':
        results_layout_choice()
    elif choice == 'set_results_sorting':
        results_sorting_choice()
    elif choice == 'set_results_filter_ignore':
        set_setting('ignore_results_filter', results_filter_ignore_toggle)
    elif choice == 'set_results_highlights':
        results_highlights_choice()
    elif choice == 'set_quality':
        set_quality_choice(quality_filter_setting)
    elif choice == 'set_subs_action':
        set_subtitle_choice()
    elif choice == 'extras_lists_choice':
        extras_lists_choice()
    elif choice == 'clear_media_cache':
        return refresh_cached_data(meta['mediatype'], 'tmdb_id',
                                   meta['tmdb_id'], meta['tvdb_id'],
                                   settings.get_language())
    elif choice == 'toggle_torrents_display_uncached':
        set_setting('torrent.display.uncached', uncached_torrents_toggle)
    elif choice == 'clear_trakt_cache':
        return clear_cache('trakt')
    elif choice == 'clear_scrapers_cache':
        return clear_scrapers_cache()
    elif choice == 'open_external_scrapers_manager':
        return external_scrapers_manager()
    elif choice == 'open_scraper_settings':
        return kodi_utils.execute_builtin(
            'Addon.OpenSettings(script.module.fenomscrapers)')
    elif choice == 'open_fen_settings':
        return open_settings('0.0')
    if choice == 'clear_trakt_cache' and content in ('movie', 'tvshow',
                                                     'season', 'episode'):
        kodi_utils.execute_builtin('Container.Refresh')
    kodi_utils.show_busy_dialog()
    kodi_utils.sleep(200)
    kodi_utils.hide_busy_dialog()
    options_menu(params, meta=meta)
    def add_uncached_torrent(self, magnet_url, pack=False):
        from modules.kodi_utils import show_busy_dialog, hide_busy_dialog
        from modules.source_utils import supported_video_extensions

        def _transfer_info(transfer_id):
            info = self.transfers_list()
            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=32574, cancelled=False):
            try:
                progressDialog.close()
            except Exception:
                pass
            hide_busy_dialog()
            sleep(500)
            if cancelled:
                if confirm_dialog(heading=32733, text=32044, top_space=True):
                    ok_dialog(heading=32733, text=ls(32732) % ls(32061))
                else:
                    self.delete_transfer(transfer_id)
            else:
                ok_dialog(heading=32733, text=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(transfer_id.get('message'))
        transfer_id = transfer_id['id']
        transfer_info = _transfer_info(transfer_id)
        if not transfer_info: return _return_failed()
        if pack:
            self.clear_cache()
            hide_busy_dialog()
            ok_dialog(text=ls(32732) % ls(32061))
            return True
        interval = 5
        line = '%s[CR]%s[CR]%s'
        line1 = '%s...' % (ls(32732) % ls(32061))
        line2 = transfer_info['name']
        line3 = transfer_info['message']
        progressDialog.create(ls(32733), line % (line1, line2, line3))
        while not transfer_info['status'] == 'seeding':
            sleep(1000 * interval)
            transfer_info = _transfer_info(transfer_id)
            line3 = transfer_info['message']
            progressDialog.update(int(float(transfer_info['progress']) * 100),
                                  line % (line1, line2, line3))
            if monitor.abortRequested() == True: return sysexit()
            try:
                if progressDialog.iscanceled():
                    return _return_failed(ls(32736), cancelled=True)
            except Exception:
                pass
            if transfer_info.get('status') == 'stalled':
                return _return_failed()
        sleep(1000 * interval)
        try:
            progressDialog.close()
        except Exception:
            pass
        hide_busy_dialog()
        return True
Exemple #16
0
 def _scraperDialog():
     while not self.scraping_started:
         if self.threads_completed: return
         kodi_utils.sleep(100)
     kodi_utils.hide_busy_dialog()
     self.make_progress_dialog()
     string1, string2 = ls(32676), ls(32677)
     if self.internal_activated or self.internal_prescraped:
         string3 = int_format % (self.int_dialog_highlight, '%s')
         string4 = ext_format % (self.ext_dialog_highlight, '%s')
     else:
         string4 = ext_scr_format % (self.ext_dialog_highlight,
                                     ls(32118))
     line1 = line2 = line3 = ''
     start_time = time.time()
     end_time = start_time + self.timeout
     unfinshed_import_time = 0
     close_dialog = True
     while not self.progress_dialog.iscanceled():
         try:
             if kodi_utils.monitor.abortRequested() is True: break
             remaining_internal_scrapers = self.process_internal_results(
             )
             internalSource_4k_label = self.int_total_format % self.internal_sources_4K
             internalSource_1080_label = self.int_total_format % self.internal_sources_1080p
             internalSource_720_label = self.int_total_format % self.internal_sources_720p
             internalSource_sd_label = self.int_total_format % self.internal_sources_sd
             internalSource_total_label = self.int_total_format % self.internal_sources_total
             source_4k_label = self.ext_total_format % self.sources_4k
             source_1080_label = self.ext_total_format % self.sources_1080p
             source_720_label = self.ext_total_format % self.sources_720p
             source_sd_label = self.ext_total_format % self.sources_sd
             source_total_label = self.ext_total_format % self.sources_total
             current_time = time.time()
             current_progress = max(
                 (current_time - start_time - unfinshed_import_time), 0)
             try:
                 info = [x.getName() for x in threads if x.is_alive()]
                 percent = (current_progress /
                            float(self.timeout)) * 100
                 if self.internal_activated or self.internal_prescraped:
                     info.extend(remaining_internal_scrapers)
                     line1 = string3 % diag_format % (
                         internalSource_4k_label,
                         internalSource_1080_label,
                         internalSource_720_label,
                         internalSource_sd_label, string2,
                         internalSource_total_label)
                     line2 = string4 % diag_format % (
                         source_4k_label, source_1080_label,
                         source_720_label, source_sd_label, string2,
                         source_total_label)
                 else:
                     line1 = string4
                     line2 = diag_format % (
                         source_4k_label, source_1080_label,
                         source_720_label, source_sd_label, string2,
                         source_total_label)
                 len_alive_threads = len(info)
                 if not self.threads_completed:
                     unfinshed_import_time += self.pause_scrape
                     line3 = string1 % unfinshed_import_format % str(
                         len_alive_threads)
                 elif len_alive_threads > 6:
                     line3 = string1 % str(len_alive_threads)
                 else:
                     line3 = string1 % ', '.join(info).upper()
                 self.progress_dialog.update(
                     format_line % (line1, line2, line3), percent)
                 kodi_utils.sleep(self.sleep_time)
                 if self.threads_completed:
                     if self.finish_early and percent >= 50:
                         if len_alive_threads <= 5:
                             close_dialog = False
                             break
                         if len(self.sources
                                ) >= 100 * len_alive_threads:
                             close_dialog = False
                             break
                     if len_alive_threads == 0:
                         close_dialog = False
                         break
                     if percent >= 100:
                         close_dialog = False
                         break
             except:
                 pass
         except:
             pass
     if close_dialog: self.kill_progress_dialog()
     return
Exemple #17
0
 def doDownload(self, url, dest):
     headers = self.headers
     file = dest.rsplit(os.sep, 1)[-1]
     resp = self.getResponse(url, headers, 0)
     if not resp:
         kodi_utils.hide_busy_dialog()
         kodi_utils.ok_dialog(text=32490, top_space=True)
         return
     try:
         content = int(resp.headers['Content-Length'])
     except:
         content = 0
     try:
         resumable = 'bytes' in resp.headers['Accept-Ranges'].lower()
     except:
         resumable = False
     if content < 1:
         kodi_utils.hide_busy_dialog()
         kodi_utils.ok_dialog(text=32490, top_space=True)
         return
     size = 1024 * 1024
     mb = content / (1024 * 1024)
     if content < size:
         size = content
     kodi_utils.hide_busy_dialog()
     if not self.confirmDownload(mb): return
     if self.action not in ('image', 'meta.pack'):
         show_notifications = True
         notification_frequency = 25
     else:
         if self.action == 'meta.pack':
             kodi_utils.notification(32134, 3500, self.image)
         show_notifications = False
         notification_frequency = 0
     notify, total, errors, count, resume, sleep_time = 25, 0, 0, 0, 0, 0
     f = kodi_utils.open_file(dest, 'w')
     chunk = None
     chunks = []
     while True:
         downloaded = total
         for c in chunks:
             downloaded += len(c)
         percent = min(round(float(downloaded) * 100 / content), 100)
         playing = kodi_utils.player.isPlaying()
         if show_notifications:
             if percent >= notify:
                 notify += notification_frequency
                 try:
                     line1 = '%s - [I]%s[/I]' % (str(percent) + '%',
                                                 self.final_name)
                     if not playing:
                         kodi_utils.notification(line1, 3000, self.image)
                 except:
                     pass
         chunk = None
         error = False
         try:
             chunk = resp.read(size)
             if not chunk:
                 if percent < 99:
                     error = True
                 else:
                     while len(chunks) > 0:
                         c = chunks.pop(0)
                         f.write(c)
                         del c
                     f.close()
                     try:
                         progressDialog.close()
                     except:
                         pass
                     return self.done(self.final_name, self.db_type, True,
                                      self.image)
         except Exception as e:
             error = True
             sleep_time = 10
             errno = 0
             if hasattr(e, 'errno'):
                 errno = e.errno
             if errno == 10035:  # 'A non-blocking socket operation could not be completed immediately'
                 pass
             if errno == 10054:  #'An existing connection was forcibly closed by the remote host'
                 errors = 10  #force resume
                 sleep_time = 30
             if errno == 11001:  # 'getaddrinfo failed'
                 errors = 10  #force resume
                 sleep_time = 30
         if chunk:
             errors = 0
             chunks.append(chunk)
             if len(chunks) > 5:
                 c = chunks.pop(0)
                 f.write(c)
                 total += len(c)
                 del c
         if error:
             errors += 1
             count += 1
             kodi_utils.sleep(sleep_time * 1000)
         if (resumable and errors > 0) or errors >= 10:
             if (not resumable and resume >= 50) or resume >= 500:
                 try:
                     progressDialog.close()
                 except:
                     pass
                 return self.done(self.final_name, self.db_type, False,
                                  self.image)
             resume += 1
             errors = 0
             if resumable:
                 chunks = []
                 resp = self.getResponse(url, headers, total)
             else:
                 pass
Exemple #18
0
 def run(self):
     self.doModal()
     hide_busy_dialog()
     return self.selected