def update_subscriptions(self, suppress_extras=False):
     from datetime import datetime, timedelta
     self.db_type = 'tvshow'
     self.action = 'add'
     self.path = settings.tv_show_directory()
     subscriptions = self.get_subscriptions()
     if not subscriptions:
         return notification('No TV Show Subscriptions to Update', 1200)
     close_all_dialog()
     bg_dialog = xbmcgui.DialogProgressBG()
     bg_dialog.create('Please Wait', 'Preparing Subscription Update...')
     for count, item in enumerate(subscriptions, 1):
         self.tmdb_id = item['media_id']
         self.add_remove_constants()
         self.add_remove_tvshow(silent=True)
         display = 'Fen Updating - [B][I]%s[/I][/B]' % self.rootname
         bg_dialog.update(
             int(float(count) / float(len(subscriptions)) * 100),
             'Please Wait', '%s' % display)
         xbmc.sleep(300)
     if int(__addon__.getSetting('subsciptions.update_type')) == 0:
         hours = settings.subscription_timer()
         __addon__.setSetting(
             'service_time',
             str(datetime.now() + timedelta(hours=hours)).split('.')[0])
     xbmc.sleep(500)
     bg_dialog.close()
     notification('Fen Subscriptions Updated', 4500)
     if settings.update_library_after_service() and not suppress_extras:
         xbmc.executebuiltin('UpdateLibrary(video)')
Exemple #2
0
 def monitor(self):
     self.library_setting = 'library' if 'from_library' in self.meta else None
     self.autoplay_next_episode = True if self.meta[
         'vid_type'] == 'episode' and self.autoplay_nextep else False
     while not self.isPlayingVideo():
         xbmc.sleep(100)
     close_all_dialog()
     while self.isPlayingVideo():
         try:
             xbmc.sleep(1000)
             self.total_time = self.getTotalTime()
             self.curr_time = self.getTime()
             self.current_point = round(
                 float(self.curr_time / self.total_time * 100), 1)
             if self.current_point >= self.set_watched and not self.media_marked:
                 self.mediaWatchedMarker()
             if self.autoplay_next_episode:
                 if self.current_point >= self.nextep_threshold:
                     if not self.nextep_info:
                         self.nextEpPrep()
                     else:
                         pass
         except:
             pass
         if not self.subs_searched: self.fetch_subtitles()
     if not self.media_marked: self.mediaWatchedMarker()
     self.refresh_container()
Exemple #3
0
def clear_all_trakt_cache_data(list_type='progress_watched',
                               confirm=True,
                               silent=False):
    from modules.nav_utils import notification, close_all_dialog

    def _process(use_progress=False):
        window.setProperty('fen_refresh_trakt_info_complete', 'true')
        try:
            try:
                clear_trakt_hidden_data(list_type)
            except:
                pass
            try:
                clear_trakt_calendar()
            except:
                pass
            if use_progress: bg_dialog.update(25, 'Clearing Trakt Cache', '')
            for i in ('movie', 'tvshow'):
                try:
                    clear_trakt_watched_data(i)
                except:
                    pass
                for j in ('collection', 'watchlist'):
                    try:
                        clear_trakt_collection_watchlist_data(j, i)
                    except:
                        pass
            if use_progress: bg_dialog.update(50, 'Clearing Trakt Cache', '')
            try:
                clear_trakt_list_contents_data(clear_all=True)
            except:
                pass
            if use_progress: bg_dialog.update(75, 'Clearing Trakt Cache', '')
            for i in ('my_lists', 'liked_lists'):
                try:
                    clear_trakt_list_data(i)
                except:
                    pass
            try:
                dbcon = database.connect(trakt_cache_file)
                dbcon.execute("VACUUM")
                dbcon.commit()
            except:
                pass
            if use_progress:
                bg_dialog.update(100, 'Clearing Trakt Cache', '')
            return True
        except:
            return False

    if silent:
        return _process()
    if settings.refresh_trakt_on_startup() and not confirm:
        if window.getProperty('fen_refresh_trakt_info_complete') == 'true':
            return
        not_home_window = xbmc.getInfoLabel('Container.PluginName')
        use_progress = False if not_home_window == '' else True
        if use_progress:
            close_all_dialog()
            xbmc.sleep(200)
            bg_dialog = xbmcgui.DialogProgressBG()
            bg_dialog.create('Clearing Trakt Cache', 'Please Wait')
        success = _process(use_progress)
        if use_progress: bg_dialog.close()
        if success:
            if use_progress: return notification('Trakt Cache Refreshed')
            return
        else:
            return notification('Error Refreshing Trakt Cache')
    if confirm:
        if not xbmcgui.Dialog().yesno('Are you sure?',
                                      'Fen will Clear the Trakt Cache.'):
            return False
        close_all_dialog()
        xbmc.sleep(200)
        bg_dialog = xbmcgui.DialogProgressBG()
        bg_dialog.create('Clearing Trakt Cache', 'Please Wait')
        result = _process(use_progress=True)
        bg_dialog.close()
        return result
def subscriptions_update_list():
    def _get_trakt_list_contents(db_type, item):
        append_list = trakt_movie_list_contents if db_type in (
            'movie', 'movies') else trakt_tvshow_list_contents
        try:
            if item['name'].lower() == 'none': return append_list
            if item['name'] in ('Collection', 'Watchlist'):
                from modules.trakt_cache import clear_trakt_collection_watchlist_data
                from apis.trakt_api import trakt_fetch_collection_watchlist
                clear_trakt_collection_watchlist_data(item['name'].lower(),
                                                      db_type)
                list_contents = trakt_fetch_collection_watchlist(
                    item['name'].lower(), db_type)
            else:
                from apis.trakt_api import get_trakt_list_contents
                from modules.trakt_cache import clear_trakt_list_contents_data
                trakt_dbtype = 'movie' if db_type in ('movie',
                                                      'movies') else 'show'
                clear_trakt_list_contents_data(user=item['user'],
                                               list_slug=item['slug'])
                list_contents = get_trakt_list_contents(
                    item['user'], item['slug'])
                list_contents = [{
                    'media_ids': i[trakt_dbtype]['ids'],
                    'title': i[trakt_dbtype]['title']
                } for i in list_contents if i['type'] == trakt_dbtype]
            append_list.extend(list_contents)
        except:
            return append_list

    close_all_dialog()
    dialog = xbmcgui.DialogProgressBG()
    dialog.create('Please Wait', 'Preparing for Subscription Update...')
    trakt_dbtype = ('movie', 'show')
    main_setting = ('trakt.subscriptions_movie', 'trakt.subscriptions_show')
    display_setting = ('trakt.subscriptions_movie_display',
                       'trakt.subscriptions_show_display')
    trakt_movie_list_contents = []
    trakt_tvshow_list_contents = []
    update_movies, update_tvshows, movies_added, tvshows_added, movies_removed, tvshows_removed = (
        False for _ in range(6))
    movie_subscriptions_object = Subscriptions('movie')
    tvshow_subscriptions_object = Subscriptions('tvshow')
    movie_subscriptions = movie_subscriptions_object.get_subscriptions()
    tvshow_subscriptions = tvshow_subscriptions_object.get_subscriptions()
    try:
        movie_list = json.loads(__addon__.getSetting(main_setting[0]))
    except:
        movie_list = []
    try:
        tvshow_list = json.loads(__addon__.getSetting(main_setting[1]))
    except:
        tvshow_list = []
    movie_list_name = __addon__.getSetting(display_setting[0])
    tvshow_list_name = __addon__.getSetting(display_setting[1])
    for i in [('movies', movie_list), ('shows', tvshow_list)]:
        _get_trakt_list_contents(i[0], i[1])
    trakt_movie_compare_contents = sorted([
        str(get_trakt_movie_id(i['media_ids']))
        for i in trakt_movie_list_contents
    ])
    subscriptions_movie_compare_contents = sorted(
        [str(i['media_id']) for i in movie_subscriptions])
    trakt_tvshow_compare_contents = sorted([
        str(get_trakt_tvshow_id(i['media_ids']))
        for i in trakt_tvshow_list_contents
    ])
    subscriptions_tvshow_compare_contents = sorted(
        [str(i['media_id']) for i in tvshow_subscriptions])
    if not trakt_movie_compare_contents == subscriptions_movie_compare_contents:
        if len(trakt_movie_compare_contents) > 0: update_movies = True
    if not trakt_tvshow_compare_contents == subscriptions_tvshow_compare_contents:
        if len(trakt_tvshow_compare_contents) > 0: update_tvshows = True
    if any([update_movies, update_tvshows]):

        def _process_additions(db_type, ids, count, list_length, path, dialog):
            if db_type in ('movie', 'movies'):
                movie_subscriptions_object.add_trakt_subscription_listitem(
                    db_type, ids, count, list_length, path, dialog)
            else:
                tvshow_subscriptions_object.add_trakt_subscription_listitem(
                    db_type, ids, count, list_length, path, dialog)

        def _process_removals(db_type, ids, count, list_length, path, dialog):
            if db_type in ('movie', 'movies'):
                movie_subscriptions_object.remove_trakt_subscription_listitem(
                    db_type, ids, count, list_length, path, dialog)
            else:
                tvshow_subscriptions_object.remove_trakt_subscription_listitem(
                    db_type, ids, count, list_length, path, dialog)

        def _process_additions_removals(db_type, action, list_contents):
            function = _process_additions if action == 'add' else _process_removals
            media_id_key = 'media_ids' if action == 'add' else 'media_id'
            dialog_db = '[B]Movies[/B]' if db_type in (
                'movie', 'movies') else '[B]TV Shows[/B]'
            dialog_line2 = 'Adding [B]%s[/B] %s' if action == 'add' else 'Removing [B]%s[/B] %s'
            path = settings.movies_directory() if db_type in (
                'movie', 'movies') else settings.tv_show_directory()
            threads = []
            list_length = len(list_contents)
            dialog.update(0, dialog_db,
                          dialog_line2 % (list_length, dialog_db))
            for count, item in enumerate(list_contents, 1):
                function(db_type, item[media_id_key], count, list_length, path,
                         dialog)

        if update_movies:
            add_to_subscriptions = [
                i for i in trakt_movie_compare_contents
                if not i in subscriptions_movie_compare_contents
            ]
            remove_from_subscriptions = [
                i for i in subscriptions_movie_compare_contents
                if not i in trakt_movie_compare_contents
            ]
            if len(add_to_subscriptions) > 0:
                movies_added = True
                list_contents = [
                    i for i in trakt_movie_list_contents
                    if str(i['media_ids']['tmdb']) in add_to_subscriptions
                ]
                _process_additions_removals('movies', 'add', list_contents)
            xbmc.sleep(1500)
            if len(remove_from_subscriptions) > 0:
                movies_removed = True
                list_contents = [
                    i for i in movie_subscriptions
                    if str(i['media_id']) in remove_from_subscriptions
                ]
                _process_additions_removals('movies', 'remove', list_contents)
        if update_tvshows:
            add_to_subscriptions = [
                i for i in trakt_tvshow_compare_contents
                if not i in subscriptions_tvshow_compare_contents
            ]
            remove_from_subscriptions = [
                i for i in subscriptions_tvshow_compare_contents
                if not i in trakt_tvshow_compare_contents
            ]
            if len(add_to_subscriptions) > 0:
                tvshows_added = True
                list_contents = [
                    i for i in trakt_tvshow_list_contents
                    if str(i['media_ids']['tmdb']) in add_to_subscriptions
                ]
                _process_additions_removals('tvshows', 'add', list_contents)
            xbmc.sleep(1500)
            if len(remove_from_subscriptions) > 0:
                tvshows_removed = True
                list_contents = [
                    i for i in tvshow_subscriptions
                    if str(i['media_id']) in remove_from_subscriptions
                ]
                _process_additions_removals('tvshows', 'remove', list_contents)
    dialog.update(100, 'Please Wait..', 'Finished Syncing Subscriptions')
    xbmc.sleep(1500)
    dialog.close()
    tvshow_subscriptions_object.update_subscriptions(suppress_extras=True)
    if settings.clean_library_after_service():
        if any([movies_removed, tvshows_removed]):
            import time
            xbmc.executebuiltin('CleanLibrary(video)')
            time.sleep(3)
            while xbmc.getCondVisibility("Window.IsVisible(ProgressDialog)"):
                time.sleep(1)
        else:
            notification('Nothing Removed. Skipping Clean', 4500)
    if settings.update_library_after_service():
        return xbmc.executebuiltin('UpdateLibrary(video)')
    return
Exemple #5
0
 def onPlayBackStarted(self):
     try:
         close_all_dialog()
     except:
         pass
Exemple #6
0
 def onAVStarted(self):
     try:
         close_all_dialog()
     except:
         pass