def doModal(self):
        try:
            if tools.getSetting('general.tempSilent') == 'true':
                self.silent = True
            try:
                self.display_style = int(tools.getSetting('general.scrapedisplay'))
            except:
                pass

            if not self.silent and self.display_style == 1:
                self.background_dialog = tools.bgProgressDialog()
                self.getSources(self.args)

            elif not self.silent and self.display_style == 0:
                super(GetSources, self).doModal()
            else:
                self.getSources(self.args)

            return self.return_data
        except:
            import traceback
            traceback.print_exc()
            self.close()
Esempio n. 2
0
    def sync_activities(self, silent=False):
        sync_errors = False

        update_time = str(datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S'))

        tools.log('STARTING SYNC')

        self._refresh_activites()

        if not silent and \
                str(self.activites['all_activities']) == self.base_date and \
                tools.getSetting('trakt.auth') != '':
            tools.showDialog.notification(tools.addonName, tools.lang(40133))

            # Give the people time to read the damn notification
            tools.kodi.sleep(500)
        try:

            if str(self.activites['all_activities']) == self.base_date:
                self.silent = False

            if not self.silent:
                self.progress_dialog = tools.bgProgressDialog()
                self.progress_dialog.create(tools.addonName + 'Sync',
                                            'Seren: Trakt Sync')

            ############################################################################################################
            # CHECK FOR META REFRESH
            ############################################################################################################

            # Meta removal should only run every 12 hours, otherwise we repeatedly dump information every run

            try:
                if self.activites['shows_meta_update'] == self.base_date:
                    self._update_activity_record('shows_meta_update',
                                                 update_time)
                else:
                    local_date = trakt_sync._parse_local_date_format(
                        self.activites['shows_meta_update'])
                    local_date = local_date + timedelta(hours=2)
                    now = trakt_sync._utc_now_as_trakt_string()
                    local_date = trakt_sync._strf_local_date(local_date)
                    if trakt_sync._requires_update(now, local_date):
                        success = self._remove_old_meta_items('shows')
                        if success:
                            self._update_activity_record(
                                'shows_meta_update', update_time)
            except:
                sync_errors = True
                import traceback
                traceback.print_exc()
                pass

            try:
                if self.activites['movies_meta_update'] == self.base_date:
                    self._update_activity_record('movies_meta_update',
                                                 update_time)
                else:
                    local_date = trakt_sync._parse_local_date_format(
                        self.activites['movies_meta_update'])
                    local_date = local_date + timedelta(hours=2)
                    now = trakt_sync._utc_now_as_trakt_string()
                    local_date = trakt_sync._strf_local_date(local_date)
                    if trakt_sync._requires_update(now, local_date):
                        success = self._remove_old_meta_items('movies')
                        if success:
                            self._update_activity_record(
                                'movies_meta_update', update_time)
            except:
                sync_errors = True
                import traceback
                traceback.print_exc()
                pass

            if tools.getSetting('trakt.auth') == '':
                if self.progress_dialog is not None:
                    self.progress_dialog.close()
                    self.progress_dialog = None
                self._update_activity_record('all_activities', update_time)
                return

            ########################################################################################################
            # SYNC LISTS
            ########################################################################################################

            lists_to_update = []

            try:
                lists_db = lists.TraktSyncDatabase()
                trakt_api = Trakt.TraktAPI()
                my_lists = trakt_api.json_response('users/me/lists',
                                                   limit=True,
                                                   limitOverride=500)
                if my_lists is None:
                    my_lists = []
                my_lists.extend([
                    i['list'] for i in trakt_api.json_response(
                        'users/likes/lists', limit=True, limitOverride=500)
                ])
                for item in my_lists:
                    sync_dates = [
                        lists_db.get_list(item['ids']['trakt'], 'movie',
                                          item['user']['ids']['slug']),
                        lists_db.get_list(item['ids']['trakt'], 'show',
                                          item['user']['ids']['slug'])
                    ]
                    sync_dates = [i for i in sync_dates if i]
                    sync_dates = [i['updated_at'][:19] for i in sync_dates]
                    if len(sync_dates) == 0:
                        lists_to_update.append(item)
                        continue
                    for date in sync_dates:
                        if trakt_sync._requires_update(item['updated_at'],
                                                       date):
                            lists_to_update.append(item)
                            break

                self._sync_lists(lists_to_update)
            except:
                sync_errors = True
                import traceback
                traceback.print_exc()
                pass

            trakt_activities = Trakt.TraktAPI().json_response(
                'sync/last_activities')

            if trakt_activities is None:
                tools.log('Unable to connect to Trakt', 'error')
                if self.progress_dialog is not None:
                    self.progress_dialog.close()
                    self.progress_dialog = None
                return True

            if trakt_sync._requires_update(trakt_activities['all'],
                                           self.activites['all_activities']):

                ########################################################################################################
                # SYNC HIDDEN ITEMS
                ########################################################################################################
                try:
                    if not self.silent:
                        self.progress_dialog.update(0, 'Syncing Hidden Items')
                    if trakt_sync._requires_update(trakt_activities['movies']['hidden_at'],
                                                   self.activites['hidden_sync']) and \
                            trakt_sync._requires_update(trakt_activities['shows']['hidden_at'],
                                                        self.activites['hidden_sync']):
                        self._sync_hidden()

                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass
                ########################################################################################################
                # SYNC WATCHED ITEMS
                ########################################################################################################
                sync_triggered = False

                try:
                    if trakt_sync._requires_update(
                            trakt_activities['episodes']['watched_at'],
                            self.activites['shows_watched']):
                        sync_triggered = True
                        self._sync_watched_episodes()
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass
                try:
                    if trakt_sync._requires_update(
                            trakt_activities['movies']['watched_at'],
                            self.activites['movies_watched']):
                        sync_triggered = True
                        self._sync_watched_movies()
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass
                try:
                    if sync_triggered:
                        if not self.silent:
                            self.progress_dialog.update(
                                0, 'Syncing Unwatched items')
                        self._sync_unwatched()
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass

                ########################################################################################################
                # SYNC COLLECTION
                ########################################################################################################

                sync_triggered = False

                try:
                    if trakt_sync._requires_update(
                            trakt_activities['episodes']['collected_at'],
                            self.activites['shows_collected']):
                        self._sync_collection_shows()
                        sync_triggered = True
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass

                try:
                    if trakt_sync._requires_update(
                            trakt_activities['movies']['collected_at'],
                            self.activites['movies_collected']):
                        self._sync_collection_movies()
                        sync_triggered = True
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass

                try:
                    if sync_triggered:
                        if not self.silent:
                            self.progress_dialog.update(
                                0, 'Syncing Uncollected items')
                        self._sync_uncollected()
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass

                ########################################################################################################
                # SYNC BOOKMARK
                ########################################################################################################

                sync_triggered = False

                try:
                    if trakt_sync._requires_update(
                            trakt_activities['episodes']['paused_at'],
                            self.activites['episodes_bookmarked']):
                        cursor = self._get_cursor()
                        cursor.execute('DELETE FROM bookmark WHERE 1=1')
                        cursor.connection.commit()
                        cursor.close()
                        self._sync_bookmarks('episodes')
                        sync_triggered = True
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass

                try:
                    if trakt_sync._requires_update(
                            trakt_activities['movies']['paused_at'],
                            self.activites['movies_bookmarked']):
                        self._sync_bookmarks('movies')
                        sync_triggered = True
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass

                try:
                    if sync_triggered:
                        if not self.silent:
                            self.progress_dialog.update(
                                100, 'Syncing bookmarked items')
                except:
                    sync_errors = True
                    import traceback
                    traceback.print_exc()
                    pass

                self._update_activity_record('all_activities', update_time)

            if self.progress_dialog is not None:
                self.progress_dialog.close()
                self.progress_dialog = None
        except:
            try:
                if self.progress_dialog is not None:
                    self.progress_dialog.close()
                    self.progress_dialog = None
            except:
                pass
            import traceback
            traceback.print_exc()
            pass

        return sync_errors
Esempio n. 3
0
    def sync_activities(self):

        update_time = str(datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S'))
        trakt_activities = Trakt.TraktAPI().json_response('sync/last_activities')

        if str(self.activites['all_activities']) == self.base_date and tools.getSetting('trakt.auth') != '':
            # Increase the amount of concurrent tasks running during initial and Force Sync processes to speed up task
            tools.showDialog.textviewer(tools.addonName, tools.lang(40133))
            confirmation = tools.showDialog.yesno(tools.addonName, tools.lang(40134))

            if not confirmation:
                return

        if trakt_activities is None:
            tools.log('Unable to connect to Trakt', 'error')
            return
        try:

            if str(self.activites['all_activities']) != self.base_date:
                self.silent = True

            if not self.silent:
                self.progress_dialog = tools.bgProgressDialog()
                self.progress_dialog.create(tools.addonName + 'Sync', 'Seren: Trakt Sync')

            ############################################################################################################
            # CHECK FOR META REFRESH
            ############################################################################################################

            # Meta removal should only run every 12 hours, otherwise we repeatedly dump information every run

            try:
                if self.activites['shows_meta_update'] == self.base_date:
                    self._update_activity_record('shows_meta_update', update_time)
                else:
                    local_date = trakt_sync._parse_local_date_format(self.activites['shows_meta_update'])
                    local_date = local_date + timedelta(hours=2)
                    now = trakt_sync._utc_now_as_trakt_string()
                    local_date = trakt_sync._strf_local_date(local_date)
                    if trakt_sync._requires_update(now, local_date):
                        self._remove_old_meta_items('shows')
                        self._update_activity_record('shows_meta_update', update_time)
            except:
                import traceback
                traceback.print_exc()
                pass

            try:
                if self.activites['movies_meta_update'] == self.base_date:
                    self._update_activity_record('movies_meta_update', update_time)
                else:
                    local_date = trakt_sync._parse_local_date_format(self.activites['movies_meta_update'])
                    local_date = local_date + timedelta(hours=2)
                    now = trakt_sync._utc_now_as_trakt_string()
                    local_date = trakt_sync._strf_local_date(local_date)
                    if trakt_sync._requires_update(now, local_date):
                        self._remove_old_meta_items('movies')
                        self._update_activity_record('movies_meta_update', update_time)
            except:
                import traceback
                traceback.print_exc()
                pass

            if tools.getSetting('trakt.auth') == '':
                return

            if trakt_sync._requires_update(trakt_activities['all'], self.activites['all_activities']):


                ########################################################################################################
                # SYNC HIDDEN ITEMS
                ########################################################################################################
                try:
                    if not self.silent:
                        self.progress_dialog.update(0, 'Syncing Hidden Items')
                    if trakt_sync._requires_update(trakt_activities['movies']['hidden_at'],
                                                   self.activites['hidden_sync']) and \
                            trakt_sync._requires_update(trakt_activities['shows']['hidden_at'],
                                                        self.activites['hidden_sync']):
                        self._sync_hidden()

                except:
                    import traceback
                    traceback.print_exc()
                    pass
                ########################################################################################################
                # SYNC WATCHED ITEMS
                ########################################################################################################
                sync_triggered = False

                try:
                    if trakt_sync._requires_update(trakt_activities['episodes']['watched_at'],
                                                   self.activites['shows_watched']):
                        sync_triggered = True
                        self._sync_watched_episodes()
                except:
                    import traceback
                    traceback.print_exc()
                    pass
                try:
                    if trakt_sync._requires_update(trakt_activities['movies']['watched_at'],
                                                   self.activites['movies_watched']):
                        sync_triggered = True
                        self._sync_watched_movies()
                except:
                    import traceback
                    traceback.print_exc()
                    pass
                try:
                    if sync_triggered:
                        if not self.silent:
                            self.progress_dialog.update(100, 'Syncing Unwatched items')
                        self._sync_unwatched()
                except:
                    import traceback
                    traceback.print_exc()
                    pass

                ########################################################################################################
                # SYNC COLLECTION
                ########################################################################################################

                sync_triggered = False

                try:
                    if trakt_sync._requires_update(trakt_activities['episodes']['collected_at'],
                                                   self.activites['shows_collected']):
                        self._sync_collection_shows()
                        sync_triggered = True
                except:
                    pass

                try:
                    if trakt_sync._requires_update(trakt_activities['movies']['collected_at'],
                                                   self.activites['movies_collected']):
                        self._sync_collection_movies()
                        sync_triggered = True
                except:
                    pass

                try:
                    if sync_triggered:
                        if not self.silent:
                            self.progress_dialog.update(100, 'Syncing Uncollected items')
                        self._sync_uncollected()
                except:
                    pass

                self._update_activity_record('all_activities', update_time)

            if self.progress_dialog is not None:
                self.progress_dialog.close()
                self.progress_dialog = None
        except:
            try:
                if self.progress_dialog is not None:
                    self.progress_dialog.close()
                    self.progress_dialog = None
            except:
                pass
            import traceback
            traceback.print_exc()
            pass