Esempio n. 1
0
	def run(self):
		sync = Sync(show_progress=self._isManual, run_silent=self._runSilent, library=self._library, api=globals.traktapi)
		sync.sync()
		
		if utilities.getSettingAsBool('tagging_enable') and utilities.getSettingAsBool('tagging_tag_after_sync'):
			q = queue.SqliteQueue()
			q.append({'action': 'updatetags'})
Esempio n. 2
0
def Main():

    args = getArguments()
    data = {}

    if args['action'] == 'sync':
        data = {'action': 'manualSync'}

    elif args['action'] in ['rate', 'unrate']:
        data = {}
        data['action'] = args['action']
        media_type = None
        if 'media_type' in args and 'dbid' in args:
            media_type = args['media_type']
            try:
                data['dbid'] = int(args['dbid'])
            except ValueError:
                utils.Debug(
                    "Manual %s triggered for library item, but DBID is invalid."
                    % args['action'])
                return
        elif 'media_type' in args and 'remoteid' in args:
            media_type = args['media_type']
            data['remoteid'] = args['remoteid']
            if 'season' in args:
                if not 'episode' in args:
                    utils.Debug(
                        "Manual %s triggered for non-library episode, but missing episode number."
                        % args['action'])
                    return
                try:
                    data['season'] = int(args['season'])
                    data['episode'] = int(args['episode'])
                except ValueError:
                    utilities.Debug(
                        "Error parsing season or episode for manual %s" %
                        args['action'])
                    return
        else:
            media_type = getMediaType()
            if not utils.isValidMediaType(media_type):
                utils.Debug("Error, not in video library.")
                return
            data['dbid'] = int(xbmc.getInfoLabel('ListItem.DBID'))

        if media_type is None:
            utils.Debug(
                "Manual %s triggered on an unsupported content container." %
                args['action'])
        elif utils.isValidMediaType(media_type):
            data['media_type'] = media_type
            if 'dbid' in data:
                utils.Debug("Manual %s of library '%s' with an ID of '%s'." %
                            (args['action'], media_type, data['dbid']))
                if utils.isMovie(media_type):
                    result = utils.getMovieDetailsFromXbmc(
                        data['dbid'], ['imdbnumber', 'title', 'year'])
                    if not result:
                        utils.Debug(
                            "No data was returned from XBMC, aborting manual %s."
                            % args['action'])
                        return
                    data['imdbnumber'] = result['imdbnumber']

                elif utils.isShow(media_type):
                    result = utils.getShowDetailsFromXBMC(
                        data['dbid'], ['imdbnumber', 'tag'])
                    if not result:
                        utils.Debug(
                            "No data was returned from XBMC, aborting manual %s."
                            % args['action'])
                        return
                    data['imdbnumber'] = result['imdbnumber']
                    data['tag'] = result['tag']

                elif utils.isEpisode(media_type):
                    result = utils.getEpisodeDetailsFromXbmc(
                        data['dbid'],
                        ['showtitle', 'season', 'episode', 'tvshowid'])
                    if not result:
                        utils.Debug(
                            "No data was returned from XBMC, aborting manual %s."
                            % args['action'])
                        return
                    data['tvdb_id'] = result['tvdb_id']
                    data['season'] = result['season']
                    data['episode'] = result['episode']

            else:
                if 'season' in data:
                    utils.Debug(
                        "Manual %s of non-library '%s' S%02dE%02d, with an ID of '%s'."
                        % (args['action'], media_type, data['season'],
                           data['episode'], data['remoteid']))
                    data['tvdb_id'] = data['remoteid']
                else:
                    utils.Debug(
                        "Manual %s of non-library '%s' with an ID of '%s'." %
                        (args['action'], media_type, data['remoteid']))
                    data['imdbnumber'] = data['remoteid']

            if args['action'] == 'rate' and 'rating' in args:
                if args['rating'] in [
                        '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'
                ]:
                    data['rating'] = int(args['rating'])

            data = {'action': 'manualRating', 'ratingData': data}

        else:
            utils.Debug("Manual %s of '%s' is unsupported." %
                        (args['action'], media_type))

    elif args['action'] == 'togglewatched':
        media_type = getMediaType()
        if media_type in ['movie', 'show', 'season', 'episode']:
            data = {}
            data['media_type'] = media_type
            if utils.isMovie(media_type):
                dbid = int(xbmc.getInfoLabel('ListItem.DBID'))
                result = utils.getMovieDetailsFromXbmc(
                    dbid, ['imdbnumber', 'title', 'year', 'playcount'])
                if result:
                    if result['playcount'] == 0:
                        data['id'] = result['imdbnumber']
                    else:
                        utils.Debug("Movie alread marked as watched in XBMC.")
                else:
                    utils.Debug("Error getting movie details from XBMC.")
                    return

            elif utils.isEpisode(media_type):
                dbid = int(xbmc.getInfoLabel('ListItem.DBID'))
                result = utils.getEpisodeDetailsFromXbmc(
                    dbid, [
                        'showtitle', 'season', 'episode', 'tvshowid',
                        'playcount'
                    ])
                if result:
                    if result['playcount'] == 0:
                        data['id'] = result['tvdb_id']
                        data['season'] = result['season']
                        data['episode'] = result['episode']
                    else:
                        utils.Debug(
                            "Episode already marked as watched in XBMC.")
                else:
                    utils.Debug("Error getting episode details from XBMC.")
                    return

            elif utils.isSeason(media_type):
                showID = None
                showTitle = xbmc.getInfoLabel('ListItem.TVShowTitle')
                result = utils.xbmcJsonRequest({
                    'jsonrpc': '2.0',
                    'method': 'VideoLibrary.GetTVShows',
                    'params': {
                        'properties': ['title', 'imdbnumber', 'year']
                    },
                    'id': 0
                })
                if result and 'tvshows' in result:
                    for show in result['tvshows']:
                        if show['title'] == showTitle:
                            showID = show['tvshowid']
                            data['id'] = show['imdbnumber']
                            break
                else:
                    utils.Debug("Error getting TV shows from XBMC.")
                    return

                season = xbmc.getInfoLabel('ListItem.Season')
                if season == "":
                    season = 0
                else:
                    season = int(season)

                result = utils.xbmcJsonRequest({
                    'jsonrpc': '2.0',
                    'method': 'VideoLibrary.GetEpisodes',
                    'params': {
                        'tvshowid': showID,
                        'season': season,
                        'properties': ['season', 'episode', 'playcount']
                    },
                    'id': 0
                })
                if result and 'episodes' in result:
                    episodes = []
                    for episode in result['episodes']:
                        if episode['playcount'] == 0:
                            episodes.append(episode['episode'])

                    if len(episodes) == 0:
                        utils.Debug(
                            "'%s - Season %d' is already marked as watched." %
                            (showTitle, season))
                        return

                    data['season'] = season
                    data['episodes'] = episodes
                else:
                    utils.Debug(
                        "Error getting episodes from '%s' for Season %d" %
                        (showTitle, season))
                    return

            elif utils.isShow(media_type):
                dbid = int(xbmc.getInfoLabel('ListItem.DBID'))
                result = utils.getShowDetailsFromXBMC(dbid,
                                                      ['year', 'imdbnumber'])
                if not result:
                    utils.Debug("Error getting show details from XBMC.")
                    return
                showTitle = result['label']
                data['id'] = result['imdbnumber']
                result = utils.xbmcJsonRequest({
                    'jsonrpc': '2.0',
                    'method': 'VideoLibrary.GetEpisodes',
                    'params': {
                        'tvshowid': dbid,
                        'properties': ['season', 'episode', 'playcount']
                    },
                    'id': 0
                })
                if result and 'episodes' in result:
                    i = 0
                    s = {}
                    for e in result['episodes']:
                        season = str(e['season'])
                        if not season in s:
                            s[season] = []
                        if e['playcount'] == 0:
                            s[season].append(e['episode'])
                            i = i + 1

                    if i == 0:
                        utils.Debug("'%s' is already marked as watched." %
                                    showTitle)
                        return

                    data['seasons'] = dict(
                        (k, v) for k, v in s.iteritems() if v)
                else:
                    utils.Debug(
                        "Error getting episode details for '%s' from XBMC." %
                        showTitle)
                    return

            if len(data) > 1:
                utils.Debug(
                    "Marking '%s' with the following data '%s' as watched on trakt.tv"
                    % (media_type, str(data)))
                data['action'] = 'markWatched'

        # execute toggle watched action
        xbmc.executebuiltin("Action(ToggleWatched)")

    elif args['action'] == 'updatetags':
        data = {'action': 'updatetags'}

    elif args['action'] == 'managelists':
        data = {'action': 'managelists'}

    elif args['action'] == 'timertest':
        utils.Debug("Timing JSON requests.")
        import time
        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetTVShowDetails',
            'params': {
                'tvshowid': 254,
                'properties': ['tag']
            },
            'id': 1
        })
        #data = utils.getShowDetailsFromXBMC(254, ['tag', 'imdbnumber'])
        e = time.time() - t
        utils.Debug("VideoLibrary.GetTVShowDetails with tags: %0.3f seconds." %
                    e)

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetMovieDetails',
            'params': {
                'movieid': 634,
                'properties': ['tag']
            },
            'id': 1
        })
        #data = utils.getMovieDetailsFromXbmc(634, ['tag', 'imdbnumber', 'title', 'year'])
        e = time.time() - t
        utils.Debug("VideoLibrary.GetMovieDetails with tags: %0.3f seconds." %
                    e)

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetTVShows',
            'params': {
                'properties': ['tag', 'title', 'imdbnumber', 'year']
            },
            'id': 0
        })
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetTVShows with tags: %0.3f seconds, %d items at %0.5f seconds per item"
            % (e, len(data['tvshows']), e / len(data['tvshows'])))

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'id': 0,
            'method': 'VideoLibrary.GetMovies',
            'params': {
                'properties': ['tag', 'title', 'imdbnumber', 'year']
            }
        })
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetMovies with tags: %0.3f seconds, %d items at %0.5f seconds per item"
            % (e, len(data['movies']), e / len(data['movies'])))

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetTVShows',
            'params': {
                'properties': ['title', 'imdbnumber', 'year']
            },
            'id': 0
        })
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetTVShows without tags: %0.3f seconds, %d items at %0.5f seconds per item"
            % (e, len(data['tvshows']), e / len(data['tvshows'])))

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'id': 0,
            'method': 'VideoLibrary.GetMovies',
            'params': {
                'properties': ['title', 'imdbnumber', 'year']
            }
        })
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetMovies without tags: %0.3f seconds, %d items at %0.5f seconds per item"
            % (e, len(data['movies']), e / len(data['movies'])))

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetTVShowDetails',
            'params': {
                'tvshowid': 254,
                'properties': ['imdbnumber']
            },
            'id': 1
        })
        #data = utils.getShowDetailsFromXBMC(254, ['imdbnumber'])
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetTVShowDetails without tags: %0.3f seconds." % e)

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetMovieDetails',
            'params': {
                'movieid': 634,
                'properties': ['imdbnumber', 'title', 'year']
            },
            'id': 1
        })
        #data = utils.getMovieDetailsFromXbmc(634, ['imdbnumber', 'title', 'year'])
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetMovieDetails without tags: %0.3f seconds." % e)

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetTVShows',
            'params': {
                'properties': ['title', 'imdbnumber', 'year']
            },
            'id': 0
        })
        data = data['tvshows']
        for item in data:
            item_data = utils.xbmcJsonRequest({
                'jsonrpc': '2.0',
                'method': 'VideoLibrary.GetTVShowDetails',
                'params': {
                    'tvshowid': item['tvshowid'],
                    'properties': ['tag']
                },
                'id': 1
            })
            item['tag'] = item_data['tvshowdetails']['tag']
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetTVShows with tags from loop: %0.3f seconds, %d items at %0.5f seconds per item"
            % (e, len(data), e / len(data)))

        t = time.time()
        data = utils.xbmcJsonRequest({
            'jsonrpc': '2.0',
            'method': 'VideoLibrary.GetMovies',
            'params': {
                'properties': ['title', 'imdbnumber', 'year']
            },
            'id': 0
        })
        data = data['movies']
        for item in data:
            item_data = utils.xbmcJsonRequest({
                'jsonrpc': '2.0',
                'method': 'VideoLibrary.GetMovieDetails',
                'params': {
                    'movieid': item['movieid'],
                    'properties': ['tag']
                },
                'id': 1
            })
            item['tag'] = item_data['moviedetails']['tag']
        e = time.time() - t
        utils.Debug(
            "VideoLibrary.GetMovies with tags from: %0.3f seconds, %d items at %0.5f seconds per item."
            % (e, len(data), e / len(data)))

    elif args['action'] in ['itemlists', 'addtolist', 'removefromlist']:
        data = {}
        data['action'] = args['action']
        media_type = None
        dbid = None
        if 'media_type' in args and 'dbid' in args:
            media_type = args['media_type']
            try:
                dbid = int(args['dbid'])
            except ValueError:
                utils.Debug(
                    "'%s' triggered for library item, but DBID is invalid." %
                    args['action'])
                return
        else:
            media_type = getMediaType()
            if not media_type in ['movie', 'show']:
                utils.Debug("Error, not in video library.")
                return
            try:
                dbid = int(xbmc.getInfoLabel('ListItem.DBID'))
            except ValueError:
                utils.Debug(
                    "'%s' triggered for library item, but there is a problem with ListItem.DBID."
                    % args['action'])
                return

        if not media_type in ['movie', 'show']:
            utils.Debug("'%s' is not a valid media type for '%s'." %
                        (media_type, args['action']))
            return

        if args['action'] in ['addtolist', 'removefromlist']:
            if 'list' in args:
                data['list'] = args['list']
            else:
                utils.Debug("'%s' requires a list parameter." % data['action'])

        data['type'] = media_type

        if utils.isMovie(media_type):
            result = utils.getMovieDetailsFromXbmc(
                dbid, ['imdbnumber', 'title', 'year', 'tag'])
            if not result:
                utils.Debug("Error getting movie details from XBMC.")
                return
            data['tag'] = result['tag']
            data['movieid'] = result['movieid']
            data['title'] = result['title']
            data['year'] = result['year']
            if result['imdbnumber'].startswith("tt"):
                data['imdb_id'] = result['imdbnumber']
            elif result['imdbnumber'].isdigit():
                data['tmdb_id'] = result['imdbnumber']

        elif utils.isShow(media_type):
            result = utils.getShowDetailsFromXBMC(
                dbid, ['imdbnumber', 'title', 'tag'])
            if not result:
                utils.Debug("Error getting show details from XBMC.")
                return
            data['tag'] = result['tag']
            data['tvshowid'] = result['tvshowid']
            data['title'] = result['title']
            if result['imdbnumber'].startswith("tt"):
                data['imdb_id'] = result['imdbnumber']
            elif result['imdbnumber'].isdigit():
                data['tvdb_id'] = result['imdbnumber']

    q = queue.SqliteQueue()
    if 'action' in data:
        utils.Debug("Queuing for dispatch: %s" % data)
        q.append(data)
Esempio n. 3
0
class traktService:

    scrobbler = None
    tagger = None
    updateTagsThread = None
    watcher = None
    syncThread = None
    dispatchQueue = queue.SqliteQueue()
    _interval = 10 * 60  # how often to send watching call

    def __init__(self):
        threading.Thread.name = 'trakt'

    def _dispatchQueue(self, data):
        utilities.Debug("Queuing for dispatch: %s" % data)
        self.dispatchQueue.append(data)

    def _dispatch(self, data):
        utilities.Debug("Dispatch: %s" % data)
        action = data['action']
        if action == 'started':
            del data['action']
            self.scrobbler.playbackStarted(data)
            self.watcher = threading.Timer(self._interval, self.doWatching)
            self.watcher.name = "trakt-watching"
            self.watcher.start()
        elif action == 'ended' or action == 'stopped':
            self.scrobbler.playbackEnded()
            if self.watcher:
                if self.watcher.isAlive():
                    self.watcher.cancel()
                    self.watcher = None
        elif action == 'paused':
            self.scrobbler.playbackPaused()
        elif action == 'resumed':
            self.scrobbler.playbackResumed()
        elif action == 'seek' or action == 'seekchapter':
            self.scrobbler.playbackSeek()
        elif action == 'databaseUpdated':
            self.doSync()
        elif action == 'scanStarted':
            pass
        elif action == 'settingsChanged':
            utilities.Debug("Settings changed, reloading.")
            globals.traktapi.updateSettings()
            self.tagger.updateSettings()
        elif action == 'markWatched':
            del data['action']
            self.doMarkWatched(data)
        elif action == 'manualRating':
            ratingData = data['ratingData']
            self.doManualRating(ratingData)
        elif action == 'manualSync':
            if not self.syncThread.isAlive():
                utilities.Debug("Performing a manual sync.")
                self.doSync(manual=True)
            else:
                utilities.Debug("There already is a sync in progress.")
        elif action == 'updatetags':
            if self.updateTagsThread and self.updateTagsThread.isAlive():
                utilities.Debug("Currently updating tags already.")
            else:
                self.updateTagsThread = threading.Thread(
                    target=self.tagger.updateTagsFromTrakt,
                    name="trakt-updatetags")
                self.updateTagsThread.start()
        elif action == 'managelists':
            self.tagger.manageLists()
        elif action == 'itemlists':
            del data['action']
            self.tagger.itemLists(data)
        elif action == 'addtolist':
            del data['action']
            list = data['list']
            del data['list']
            self.tagger.manualAddToList(list, data)
        elif action == 'removefromlist':
            del data['action']
            list = data['list']
            del data['list']
            self.tagger.manualRemoveFromList(list, data)
        else:
            utilities.Debug("Unknown dispatch action, '%s'." % action)

    def run(self):
        startup_delay = utilities.getSettingAsInt('startup_delay')
        if startup_delay:
            utilities.Debug("Delaying startup by %d seconds." % startup_delay)
            xbmc.sleep(startup_delay * 1000)

        utilities.Debug("Service thread starting.")

        # setup event driven classes
        self.Player = traktPlayer(action=self._dispatchQueue)
        self.Monitor = traktMonitor(action=self._dispatchQueue)

        # init traktapi class
        globals.traktapi = traktAPI()

        # init sync thread
        self.syncThread = syncThread()

        # init scrobbler class
        self.scrobbler = Scrobbler(globals.traktapi)

        # init tagging class
        self.tagger = Tagger(globals.traktapi)

        # purge queue
        self.dispatchQueue.purge()

        # start loop for events
        while (not xbmc.abortRequested):
            while len(self.dispatchQueue) and (not xbmc.abortRequested):
                data = self.dispatchQueue.get()
                utilities.Debug("Queued dispatch: %s" % data)
                self._dispatch(data)

            if xbmc.Player().isPlayingVideo():
                self.scrobbler.update()

            xbmc.sleep(500)

        # we are shutting down
        utilities.Debug("Beginning shut down.")

        # check if watcher is set and active, if so, cancel it.
        if self.watcher:
            if self.watcher.isAlive():
                self.watcher.cancel()

        # delete player/monitor
        del self.Player
        del self.Monitor

        # check update tags thread.
        if self.updateTagsThread and self.updateTagsThread.isAlive():
            self.updateTagsThread.join()

        # check if sync thread is running, if so, join it.
        if self.syncThread.isAlive():
            self.syncThread.join()

    def doWatching(self):
        # check if we're still playing a video
        if not xbmc.Player().isPlayingVideo():
            self.watcher = None
            return

        # call watching method
        self.scrobbler.watching()

        # start a new timer thread
        self.watcher = threading.Timer(self._interval, self.doWatching)
        self.watcher.name = "trakt-watching"
        self.watcher.start()

    def doManualRating(self, data):

        action = data['action']
        media_type = data['media_type']
        summaryInfo = None

        if not utilities.isValidMediaType(media_type):
            utilities.Debug(
                "doManualRating(): Invalid media type '%s' passed for manual %s."
                % (media_type, action))
            return

        if not data['action'] in ['rate', 'unrate']:
            utilities.Debug("doManualRating(): Unknown action passed.")
            return

        if 'dbid' in data:
            utilities.Debug(
                "Getting data for manual %s of library '%s' with ID of '%s'" %
                (action, media_type, data['dbid']))
        elif 'remoteitd' in data:
            if 'season' in data:
                utilities.Debug(
                    "Getting data for manual %s of non-library '%s' S%02dE%02d, with ID of '%s'."
                    % (action, media_type, data['season'], data['episode'],
                       data['remoteid']))
            else:
                utilities.Debug(
                    "Getting data for manual %s of non-library '%s' with ID of '%s'"
                    % (action, media_type, data['remoteid']))

        if utilities.isEpisode(media_type):
            summaryInfo = globals.traktapi.getEpisodeSummary(
                data['tvdb_id'], data['season'], data['episode'])
        elif utilities.isShow(media_type):
            summaryInfo = globals.traktapi.getShowSummary(data['imdbnumber'])
        elif utilities.isMovie(media_type):
            summaryInfo = globals.traktapi.getMovieSummary(data['imdbnumber'])

        if not summaryInfo is None:
            if utilities.isMovie(media_type) or utilities.isShow(media_type):
                summaryInfo['xbmc_id'] = data['dbid']

            if action == 'rate':
                if not 'rating' in data:
                    rateMedia(media_type, summaryInfo)
                else:
                    rateMedia(media_type, summaryInfo, rating=data['rating'])
            elif action == 'unrate':
                rateMedia(media_type, summaryInfo, unrate=True)
        else:
            utilities.Debug(
                "doManualRating(): Summary info was empty, possible problem retrieving data from trakt.tv"
            )

    def doMarkWatched(self, data):

        media_type = data['media_type']
        simulate = utilities.getSettingAsBool('simulate_sync')
        markedNotification = utilities.getSettingAsBool(
            'show_marked_notification')

        if utilities.isMovie(media_type):
            summaryInfo = globals.traktapi.getMovieSummary(data['id'])
            if summaryInfo:
                if not summaryInfo['watched']:
                    s = utilities.getFormattedItemName(media_type, summaryInfo)
                    utilities.Debug(
                        "doMarkWatched(): '%s' is not watched on trakt, marking it as watched."
                        % s)
                    movie = {}
                    movie['imdb_id'] = data['id']
                    movie['title'] = summaryInfo['title']
                    movie['year'] = summaryInfo['year']
                    movie['plays'] = 1
                    movie['last_played'] = int(time())
                    params = {'movies': [movie]}
                    utilities.Debug("doMarkWatched(): %s" % str(params))

                    if not simulate:
                        result = globals.traktapi.updateSeenMovie(params)
                        if result:
                            if markedNotification:
                                utilities.notification(
                                    utilities.getString(1550), s)
                        else:
                            utilities.notification(utilities.getString(1551),
                                                   s)
                    else:
                        if markedNotification:
                            utilities.notification(utilities.getString(1550),
                                                   s)

        elif utilities.isEpisode(media_type):
            summaryInfo = globals.traktapi.getEpisodeSummary(
                data['id'], data['season'], data['episode'])
            if summaryInfo:
                if not summaryInfo['episode']['watched']:
                    s = utilities.getFormattedItemName(media_type, summaryInfo)
                    utilities.Debug(
                        "doMarkWathced(): '%s' is not watched on trakt, marking it as watched."
                        % s)
                    params = {}
                    params['imdb_id'] = summaryInfo['show']['imdb_id']
                    params['tvdb_id'] = summaryInfo['show']['tvdb_id']
                    params['title'] = summaryInfo['show']['title']
                    params['year'] = summaryInfo['show']['year']
                    params['episodes'] = [{
                        'season': data['season'],
                        'episode': data['episode']
                    }]
                    utilities.Debug("doMarkWatched(): %s" % str(params))

                    if not simulate:
                        result = globals.traktapi.updateSeenEpisode(params)
                        if result:
                            if markedNotification:
                                utilities.notification(
                                    utilities.getString(1550), s)
                        else:
                            utilities.notification(utilities.getString(1551),
                                                   s)
                    else:
                        if markedNotification:
                            utilities.notification(utilities.getString(1550),
                                                   s)

        elif utilities.isSeason(media_type):
            showInfo = globals.traktapi.getShowSummary(data['id'])
            if not showInfo:
                return
            summaryInfo = globals.traktapi.getSeasonInfo(
                data['id'], data['season'])
            if summaryInfo:
                showInfo['season'] = data['season']
                s = utilities.getFormattedItemName(media_type, showInfo)
                params = {}
                params['imdb_id'] = showInfo['imdb_id']
                params['tvdb_id'] = showInfo['tvdb_id']
                params['title'] = showInfo['title']
                params['year'] = showInfo['year']
                params['episodes'] = []
                for ep in summaryInfo:
                    if ep['episode'] in data['episodes']:
                        if not ep['watched']:
                            params['episodes'].append({
                                'season': ep['season'],
                                'episode': ep['episode']
                            })

                utilities.Debug(
                    "doMarkWatched(): '%s - Season %d' has %d episode(s) that are going to be marked as watched."
                    % (showInfo['title'], data['season'],
                       len(params['episodes'])))

                if len(params['episodes']) > 0:
                    utilities.Debug("doMarkWatched(): %s" % str(params))
                    if not simulate:
                        result = globals.traktapi.updateSeenEpisode(params)
                        if result:
                            if markedNotification:
                                utilities.notification(
                                    utilities.getString(1550),
                                    utilities.getString(1552) %
                                    (len(params['episodes']), s))
                        else:
                            utilities.notification(
                                utilities.getString(1551),
                                utilities.getString(1552) %
                                (len(params['episodes']), s))
                    else:
                        if markedNotification:
                            utilities.notification(
                                utilities.getString(1550),
                                utilities.getString(1552) %
                                (len(params['episodes']), s))

        elif utilities.isShow(media_type):
            summaryInfo = globals.traktapi.getShowSummary(data['id'],
                                                          extended=True)
            if summaryInfo:
                s = utilities.getFormattedItemName(media_type, summaryInfo)
                params = {}
                params['imdb_id'] = summaryInfo['imdb_id']
                params['tvdb_id'] = summaryInfo['tvdb_id']
                params['title'] = summaryInfo['title']
                params['year'] = summaryInfo['year']
                params['episodes'] = []
                for season in summaryInfo['seasons']:
                    for ep in season['episodes']:
                        if str(season['season']) in data['seasons']:
                            if ep['episode'] in data['seasons'][str(
                                    season['season'])]:
                                if not ep['watched']:
                                    params['episodes'].append({
                                        'season':
                                        ep['season'],
                                        'episode':
                                        ep['episode']
                                    })
                utilities.Debug(
                    "doMarkWatched(): '%s' has %d episode(s) that are going to be marked as watched."
                    % (summaryInfo['title'], len(params['episodes'])))

                if len(params['episodes']) > 0:
                    utilities.Debug("doMarkWatched(): %s" % str(params))
                    if not simulate:
                        result = globals.traktapi.updateSeenEpisode(params)
                        if result:
                            if markedNotification:
                                utilities.notification(
                                    utilities.getString(1550),
                                    utilities.getString(1552) %
                                    (len(params['episodes']), s))
                        else:
                            utilities.notification(
                                utilities.getString(1551),
                                utilities.getString(1552) %
                                (len(params['episodes']), s))
                    else:
                        if markedNotification:
                            utilities.notification(
                                utilities.getString(1550),
                                utilities.getString(1552) %
                                (len(params['episodes']), s))

    def doSync(self, manual=False):
        self.syncThread = syncThread(manual)
        self.syncThread.start()