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 __rateOnTrakt(rating, media_type, media, unrate=False): logger.debug("Sending rating (%s) to Trakt.tv" % rating) params = media if utils.isMovie(media_type): key = 'movies' params['rating'] = rating elif utils.isShow(media_type): key = 'shows' params['rating'] = rating elif utils.isSeason(media_type): key = 'shows' params['seasons'] = [{'rating': rating, 'number': media['season']}] elif utils.isEpisode(media_type): key = 'episodes' params['rating'] = rating else: return root = {key: [params]} if not unrate: data = globals.traktapi.addRating(root) else: data = globals.traktapi.removeRating(root) if data: s = utils.getFormattedItemName(media_type, media) if 'not_found' in data and not data['not_found']['movies'] and not data['not_found']['episodes'] and not data['not_found']['shows']: if not unrate: utils.notification(utils.getString(32040), s) else: utils.notification(utils.getString(32042), s) else: utils.notification(utils.getString(32044), s)
def onInit(self): mange_string = getString(32133) if isMovie( self.media_type) else getString(32134) rate_string = getString(32137) if isShow(self.media_type): rate_string = getString(32138) elif isSeason(self.media_type): rate_string = getString(32149) elif isEpisode(self.media_type): rate_string = getString(32139) actions = [ mange_string, getString(32135), getString(32136), rate_string, getString(32140), getString(32141), getString(32142), getString(32143) ] keys = [ "itemlists", "removefromlist", "addtowatchlist", "rate", "togglewatched", "managelists", "updatetags", "sync" ] l = self.getControl(ACTION_LIST) for i in range(len(actions)): if keys[i] in self.buttons: l.addItem(self.newListItem(actions[i], id=keys[i])) self.setFocus(l)
def onInit(self): lang = utils.getString mange_string = lang(2000) if utils.isMovie(self.media_type) else lang(2001) rate_string = lang(2030) if utils.isShow(self.media_type): rate_string = lang(2031) elif utils.isEpisode(self.media_type): rate_string = lang(2032) actions = [mange_string, lang(2010), lang(2020), rate_string, lang(2040), lang(2050), lang(2060), lang(2070)] keys = ["itemlists", "removefromlist", "addtolist", "rate", "togglewatched", "managelists", "updatetags", "sync"] l = self.getControl(ACTION_LIST) for i in range(len(actions)): if keys[i] in self.buttons: l.addItem(self.newListItem(actions[i], id=keys[i])) h = ((len(self.buttons)) * 46) - 6 l.setHeight(h) d = self.getControl(DIALOG_IMAGE) d.setHeight(h + 40) offset = (316 - h) / 2 d.setPosition(0, offset - 20) l.setPosition(20, offset) self.setFocus(l)
def onInit(self): lang = utils.getString mange_string = lang(32133) if utils.isMovie(self.media_type) else lang(32134) rate_string = lang(32137) if utils.isShow(self.media_type): rate_string = lang(32138) elif utils.isSeason(self.media_type): rate_string = lang(32149) elif utils.isEpisode(self.media_type): rate_string = lang(32139) actions = [mange_string, lang(32135), lang(32136), rate_string, lang(32140), lang(32141), lang(32142), lang(32143)] keys = ["itemlists", "removefromlist", "addtolist", "rate", "togglewatched", "managelists", "updatetags", "sync"] l = self.getControl(ACTION_LIST) for i in range(len(actions)): if keys[i] in self.buttons: l.addItem(self.newListItem(actions[i], id=keys[i])) h = ((len(self.buttons)) * 46) - 6 l.setHeight(h) d = self.getControl(DIALOG_IMAGE) d.setHeight(h + 40) self.setFocus(l)
def doManualRating(self, data): action = data['action'] media_type = data['media_type'] summaryInfo = None if not utilities.isValidMediaType(media_type): logger.debug("doManualRating(): Invalid media type '%s' passed for manual %s." % (media_type, action)) return if not data['action'] in ['rate', 'unrate']: logger.debug("doManualRating(): Unknown action passed.") return logger.debug("Getting data for manual %s of %s: video_id: |%s| dbid: |%s|" % (action, media_type, data.get('video_id'), data.get('dbid'))) id_type = utilities.parseIdToTraktIds(str(data['video_id']), media_type)[1] if not id_type: logger.debug("doManualRating(): Unrecognized id_type: |%s|-|%s|." % (media_type, data['video_id'])) return ids = globals.traktapi.getIdLookup(data['video_id'], id_type) if not ids: logger.debug("doManualRating(): No Results for: |%s|-|%s|." % (media_type, data['video_id'])) return trakt_id = dict(ids[0].keys)['trakt'] if utilities.isEpisode(media_type): summaryInfo = globals.traktapi.getEpisodeSummary(trakt_id, data['season'], data['episode']) userInfo = globals.traktapi.getEpisodeRatingForUser(trakt_id, data['season'], data['episode'], 'trakt') elif utilities.isSeason(media_type): summaryInfo = globals.traktapi.getShowSummary(trakt_id) userInfo = globals.traktapi.getSeasonRatingForUser(trakt_id, data['season'], 'trakt') elif utilities.isShow(media_type): summaryInfo = globals.traktapi.getShowSummary(trakt_id) userInfo = globals.traktapi.getShowRatingForUser(trakt_id, 'trakt') elif utilities.isMovie(media_type): summaryInfo = globals.traktapi.getMovieSummary(trakt_id) userInfo = globals.traktapi.getMovieRatingForUser(trakt_id, 'trakt') if summaryInfo is not None: summaryInfo = summaryInfo.to_dict() summaryInfo['user'] = {'ratings': userInfo} if utilities.isEpisode(media_type): summaryInfo['season'] = data['season'] summaryInfo['number'] = data['episode'] elif utilities.isSeason(media_type): summaryInfo['season'] = data['season'] if action == 'rate': if not 'rating' in data: rateMedia(media_type, [summaryInfo]) else: rateMedia(media_type, [summaryInfo], rating=data['rating']) else: logger.debug("doManualRating(): Summary info was empty, possible problem retrieving data from Trakt.tv")
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 __rateOnTrakt(rating, media_type, media, unrate=False): utils.Debug("[Rating] Sending rating (%s) to trakt.tv" % rating) params = {} if utils.isMovie(media_type): params = media params['rating'] = rating root = {} listing = [params] root['movies'] = listing elif utils.isShow(media_type): params['rating'] = rating params['title'] = media['title'] params['year'] = media['year'] params['ids'] = {} params['ids']['tmdb'] = media['ids']['tmdb'] params['ids']['imdb'] = media['ids']['imdb'] params['ids']['tvdb'] = media['ids']['tvdb'] root = {} listing = [params] root['shows'] = listing elif utils.isEpisode(media_type): params = media params['rating'] = rating root = {} listing = [params] root['episodes'] = listing else: return if not unrate: data = globals.traktapi.addRating(root) else: data = globals.traktapi.removeRating(root) if data: utils.Debug("data rate: %s" % data) s = utils.getFormattedItemName(media_type, media) if 'not_found' in data and not data['not_found']['movies'] and not data[ 'not_found']['episodes'] and not data['not_found']['shows']: if not unrate: utils.notification(utils.getString(1350), s) else: utils.notification(utils.getString(1352), s) else: utils.notification(utils.getString(1354), s)
def __rateOnTrakt(rating, media_type, media, unrate=False): logger.debug("Sending rating (%s) to Trakt.tv" % rating) params = {} if utils.isMovie(media_type): params = media params['rating'] = rating root = {} listing = [params] root['movies'] = listing elif utils.isShow(media_type): params['rating'] = rating params['title'] = media['title'] params['year'] = media['year'] params['ids'] = {} params['ids']['tmdb'] = media['ids']['tmdb'] params['ids']['imdb'] = media['ids']['imdb'] params['ids']['tvdb'] = media['ids']['tvdb'] root = {} listing = [params] root['shows'] = listing elif utils.isEpisode(media_type): params = media params['rating'] = rating root = {} listing = [params] root['episodes'] = listing else: return if not unrate: data = globals.traktapi.addRating(root) else: data = globals.traktapi.removeRating(root) if data: s = utils.getFormattedItemName(media_type, media) if 'not_found' in data and not data['not_found']['movies'] and not data['not_found']['episodes'] and not data['not_found']['shows']: if not unrate: utils.notification(utils.getString(32040), s) else: utils.notification(utils.getString(32042), s) else: utils.notification(utils.getString(32044), s)
def doAddToWatchlist(self, data): media_type = data['media_type'] if utilities.isMovie(media_type): summaryInfo = globals.traktapi.getMovieSummary(data['id']).to_dict() if summaryInfo: s = utilities.getFormattedItemName(media_type, summaryInfo) logger.debug("doAddToWatchlist(): '%s' trying to add to users watchlist." % s) params = {'movies': [summaryInfo]} logger.debug("doAddToWatchlist(): %s" % str(params)) result = globals.traktapi.addToWatchlist(params) if result: kodiUtilities.notification(kodiUtilities.getString(32165), s) else: kodiUtilities.notification(kodiUtilities.getString(32166), s) elif utilities.isEpisode(media_type): summaryInfo = {'shows': [{'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0], 'seasons': [{'number': data['season'], 'episodes': [{'number':data['number']}]}]}]} logger.debug("doAddToWatchlist(): %s" % str(summaryInfo)) s = utilities.getFormattedItemName(media_type, data) result = globals.traktapi.addToWatchlist(summaryInfo) if result: kodiUtilities.notification(kodiUtilities.getString(32165), s) else: kodiUtilities.notification(kodiUtilities.getString(32166), s) elif utilities.isSeason(media_type): summaryInfo = {'shows': [{'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0], 'seasons': [{'number': data['season']}]}]} s = utilities.getFormattedItemName(media_type, data) logger.debug("doAddToWatchlist(): '%s - Season %d' trying to add to users watchlist." % (data['id'], data['season'])) result = globals.traktapi.addToWatchlist(summaryInfo) if result: kodiUtilities.notification(kodiUtilities.getString(32165), s) else: kodiUtilities.notification(kodiUtilities.getString(32166), s) elif utilities.isShow(media_type): summaryInfo = {'shows': [{'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0]}]} s = utilities.getFormattedItemName(media_type, data) logger.debug("doAddToWatchlist(): %s" % str(summaryInfo)) result = globals.traktapi.addToWatchlist(summaryInfo) if result: kodiUtilities.notification(kodiUtilities.getString(32165), s) else: kodiUtilities.notification(kodiUtilities.getString(32166), s)
def doAddToWatchlist(self, data): media_type = data['media_type'] if utilities.isMovie(media_type): summaryInfo = globals.traktapi.getMovieSummary(data['id']).to_dict() if summaryInfo: s = utilities.getFormattedItemName(media_type, summaryInfo) logger.debug("doAddToWatchlist(): '%s' trying to add to users watchlist." % s) params = {'movies': [summaryInfo]} logger.debug("doAddToWatchlist(): %s" % str(params)) result = globals.traktapi.addToWatchlist(params) if result: utilities.notification(utilities.getString(32165), s) else: utilities.notification(utilities.getString(32166), s) elif utilities.isEpisode(media_type): summaryInfo = {'shows': [{'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0], 'seasons': [{'number': data['season'], 'episodes': [{'number':data['number']}]}]}]} logger.debug("doAddToWatchlist(): %s" % str(summaryInfo)) s = utilities.getFormattedItemName(media_type, data) result = globals.traktapi.addToWatchlist(summaryInfo) if result: utilities.notification(utilities.getString(32165), s) else: utilities.notification(utilities.getString(32166), s) elif utilities.isSeason(media_type): summaryInfo = {'shows': [{'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0], 'seasons': [{'number': data['season']}]}]} s = utilities.getFormattedItemName(media_type, data) logger.debug("doAddToWatchlist(): '%s - Season %d' trying to add to users watchlist." % (data['id'], data['season'])) result = globals.traktapi.addToWatchlist(summaryInfo) if result: utilities.notification(utilities.getString(32165), s) else: utilities.notification(utilities.getString(32166), s) elif utilities.isShow(media_type): summaryInfo = {'shows': [{'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0]}]} s = utilities.getFormattedItemName(media_type, data) logger.debug("doAddToWatchlist(): %s" % str(summaryInfo)) result = globals.traktapi.addToWatchlist(summaryInfo) if result: utilities.notification(utilities.getString(32165), s) else: utilities.notification(utilities.getString(32166), s)
def doMarkWatched(self, data): media_type = data['media_type'] if utilities.isMovie(media_type): summaryInfo = globals.traktapi.getMovieSummary(data['id']).to_dict() if summaryInfo: if not summaryInfo['watched']: s = utilities.getFormattedItemName(media_type, summaryInfo) logger.debug("doMarkWatched(): '%s' is not watched on Trakt, marking it as watched." % s) params = {'movies': [summaryInfo]} logger.debug("doMarkWatched(): %s" % str(params)) result = globals.traktapi.addToHistory(params) if result: kodiUtilities.notification(kodiUtilities.getString(32113), s) else: kodiUtilities.notification(kodiUtilities.getString(32114), s) elif utilities.isEpisode(media_type): summaryInfo = {'shows': [{'ids':utilities.parseIdToTraktIds(data['id'],media_type)[0], 'seasons': [{'number': data['season'], 'episodes': [{'number':data['number']}]}]}]} logger.debug("doMarkWatched(): %s" % str(summaryInfo)) s = utilities.getFormattedItemName(media_type, data) result = globals.traktapi.addToHistory(summaryInfo) if result: kodiUtilities.notification(kodiUtilities.getString(32113), s) else: kodiUtilities.notification(kodiUtilities.getString(32114), s) elif utilities.isSeason(media_type): summaryInfo = {'shows': [{'ids':utilities.parseIdToTraktIds(data['id'],media_type)[0], 'seasons': [{'number': data['season'], 'episodes': []}]}]} s = utilities.getFormattedItemName(media_type, data) for ep in data['episodes']: summaryInfo['shows'][0]['seasons'][0]['episodes'].append({'number': ep}) logger.debug("doMarkWatched(): '%s - Season %d' has %d episode(s) that are going to be marked as watched." % (data['id'], data['season'], len(summaryInfo['shows'][0]['seasons'][0]['episodes']))) self.addEpisodesToHistory(summaryInfo, s) elif utilities.isShow(media_type): summaryInfo = {'shows': [{'ids':utilities.parseIdToTraktIds(data['id'],media_type)[0], 'seasons': []}]} if summaryInfo: s = utilities.getFormattedItemName(media_type, data) logger.debug('data: %s' % data) for season in data['seasons']: episodeJson = [] for episode in data['seasons'][season]: episodeJson.append({'number': episode}) summaryInfo['shows'][0]['seasons'].append({'number': season, 'episodes': episodeJson}) self.addEpisodesToHistory(summaryInfo, s)
def rateOnTrakt(rating, media_type, media, unrate=False): utils.Debug("[Rating] Sending rating (%s) to trakt.tv" % rating) params = {} params["rating"] = rating if utils.isMovie(media_type): params["title"] = media["title"] params["year"] = media["year"] params["tmdb_id"] = media["tmdb_id"] params["imdb_id"] = media["imdb_id"] data = globals.traktapi.rateMovie(params) elif utils.isShow(media_type): params["title"] = media["title"] params["year"] = media["year"] params["tvdb_id"] = media["tvdb_id"] params["imdb_id"] = media["imdb_id"] data = globals.traktapi.rateShow(params) elif utils.isEpisode(media_type): params["title"] = media["show"]["title"] params["year"] = media["show"]["year"] params["season"] = media["episode"]["season"] params["episode"] = media["episode"]["number"] params["tvdb_id"] = media["show"]["tvdb_id"] params["imdb_id"] = media["show"]["imdb_id"] data = globals.traktapi.rateEpisode(params) else: return if data: s = utils.getFormattedItemName(media_type, media) if "status" in data and data["status"] == "success": if not unrate: utils.notification(utils.getString(1350), s) else: utils.notification(utils.getString(1352), s) elif "status" in data and data["status"] == "failure": utils.notification(utils.getString(1354), s) else: # status not in data, different problem, do nothing for now pass
def onFocus(self, controlID): if controlID in self.focus_labels: s = utils.getString(self.focus_labels[controlID]) if self.rerate: if self.media['rating'] == self.buttons[controlID] or self.media['rating_advanced'] == self.buttons[controlID]: if utils.isMovie(self.media_type): s = utils.getString(1325) elif utils.isShow(self.media_type): s = utils.getString(1326) elif utils.isEpisode(self.media_type): s = utils.getString(1327) else: pass self.getControl(10013).setLabel(s) else: self.getControl(10013).setLabel('')
def onFocus(self, controlID): if controlID in self.focus_labels: s = utils.getString(self.focus_labels[controlID]) if self.rerate: if self.media['user']['ratings'] and self.media['user']['ratings']['rating'] == self.buttons[controlID]: if utils.isMovie(self.media_type): s = utils.getString(32037) elif utils.isShow(self.media_type): s = utils.getString(32038) elif utils.isEpisode(self.media_type): s = utils.getString(32039) else: pass self.getControl(10013).setLabel(s) else: self.getControl(10013).setLabel('')
def doManualRating(self, data): action = data['action'] media_type = data['media_type'] summaryInfo = None if not utilities.isValidMediaType(media_type): logger.debug("doManualRating(): Invalid media type '%s' passed for manual %s." % (media_type, action)) return if not data['action'] in ['rate', 'unrate']: logger.debug("doManualRating(): Unknown action passed.") return logger.debug("Getting data for manual %s of %s: imdb: |%s| dbid: |%s|" % (action, media_type, data.get('remoteid'), data.get('dbid'))) if utilities.isEpisode(media_type): summaryInfo = globals.traktapi.getEpisodeSummary(data['imdbnumber'], data['season'], data['episode']) userInfo = globals.traktapi.getEpisodeRatingForUser(data['imdbnumber'], data['season'], data['episode'], 'imdb') elif utilities.isSeason(media_type): summaryInfo = globals.traktapi.getShowSummary(data['imdbnumber']) userInfo = globals.traktapi.getSeasonRatingForUser(data['imdbnumber'], data['season'], 'imdb') elif utilities.isShow(media_type): summaryInfo = globals.traktapi.getShowSummary(data['imdbnumber']) userInfo = globals.traktapi.getShowRatingForUser(data['imdbnumber'], 'imdb') elif utilities.isMovie(media_type): summaryInfo = globals.traktapi.getMovieSummary(data['imdbnumber']) userInfo = globals.traktapi.getMovieRatingForUser(data['imdbnumber']) if summaryInfo is not None: summaryInfo = summaryInfo.to_dict() summaryInfo['user'] = {'ratings': userInfo} if utilities.isEpisode(media_type): summaryInfo['season'] = data['season'] summaryInfo['number'] = data['episode'] elif utilities.isSeason(media_type): summaryInfo['season'] = data['season'] if action == 'rate': if not 'rating' in data: rateMedia(media_type, [summaryInfo]) else: rateMedia(media_type, [summaryInfo], rating=data['rating']) else: logger.debug("doManualRating(): Summary info was empty, possible problem retrieving data from Trakt.tv")
def onInit(self): mange_string = getString(32133) if isMovie(self.media_type) else getString(32134) rate_string = getString(32137) if isShow(self.media_type): rate_string = getString(32138) elif isSeason(self.media_type): rate_string = getString(32149) elif isEpisode(self.media_type): rate_string = getString(32139) actions = [mange_string, getString(32135), getString(32136), rate_string, getString(32140), getString(32141), getString(32142), getString(32143)] keys = ["itemlists", "removefromlist", "addtowatchlist", "rate", "togglewatched", "managelists", "updatetags", "sync"] l = self.getControl(ACTION_LIST) for i in range(len(actions)): if keys[i] in self.buttons: l.addItem(self.newListItem(actions[i], id=keys[i])) self.setFocus(l)
def __rateOnTrakt(rating, media_type, media, unrate=False): logger.debug("Sending rating (%s) to Trakt.tv" % rating) params = media if utilities.isMovie(media_type): key = 'movies' params['rating'] = rating if 'movieid' in media: kodiUtilities.kodiJsonRequest({"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetMovieDetails", "params": {"movieid": media['movieid'], "userrating": rating}}) elif utilities.isShow(media_type): key = 'shows' params['rating'] = rating if 'tvshowid' in media: kodiUtilities.kodiJsonRequest({"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetTVShowDetails", "params": {"tvshowid": media['tvshowid'], "userrating": rating}}) elif utilities.isSeason(media_type): key = 'shows' params['seasons'] = [{'rating': rating, 'number': media['season']}] elif utilities.isEpisode(media_type): key = 'episodes' params['rating'] = rating if 'episodeid' in media: kodiUtilities.kodiJsonRequest({"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetEpisodeDetails", "params": {"episodeid": media['episodeid'], "userrating": rating}}) else: return root = {key: [params]} if not unrate: data = globals.traktapi.addRating(root) else: data = globals.traktapi.removeRating(root) if data: s = utilities.getFormattedItemName(media_type, media) if 'not_found' in data and not data['not_found']['movies'] and not data['not_found']['episodes'] and not data['not_found']['shows']: if not unrate: kodiUtilities.notification(kodiUtilities.getString(32040), s) else: kodiUtilities.notification(kodiUtilities.getString(32042), s) else: kodiUtilities.notification(kodiUtilities.getString(32044), s)
def __rateOnTrakt(rating, media_type, media, unrate=False): logger.debug("Sending rating (%s) to Trakt.tv" % rating) params = media if utils.isMovie(media_type): key = 'movies' params['rating'] = rating if 'movieid' in media: utils.kodiJsonRequest({"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetMovieDetails", "params": {"movieid": media['movieid'], "userrating": rating}}) elif utils.isShow(media_type): key = 'shows' params['rating'] = rating if 'tvshowid' in media: utils.kodiJsonRequest({"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetTVShowDetails", "params": {"tvshowid": media['tvshowid'], "userrating": rating}}) elif utils.isSeason(media_type): key = 'shows' params['seasons'] = [{'rating': rating, 'number': media['season']}] elif utils.isEpisode(media_type): key = 'episodes' params['rating'] = rating if 'episodeid' in media: utils.kodiJsonRequest({"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetEpisodeDetails", "params": {"episodeid": media['episodeid'], "userrating": rating}}) else: return root = {key: [params]} if not unrate: data = globals.traktapi.addRating(root) else: data = globals.traktapi.removeRating(root) if data: s = utils.getFormattedItemName(media_type, media) if 'not_found' in data and not data['not_found']['movies'] and not data['not_found']['episodes'] and not data['not_found']['shows']: if not unrate: utils.notification(utils.getString(32040), s) else: utils.notification(utils.getString(32042), s) else: utils.notification(utils.getString(32044), s)
def onInit(self): lang = utils.getString mange_string = lang(2000) if utils.isMovie( self.media_type) else lang(2001) rate_string = lang(2030) if utils.isShow(self.media_type): rate_string = lang(2031) elif utils.isEpisode(self.media_type): rate_string = lang(2032) actions = [ mange_string, lang(2010), lang(2020), rate_string, lang(2040), lang(2050), lang(2060), lang(2070) ] keys = [ "itemlists", "removefromlist", "addtolist", "rate", "togglewatched", "managelists", "updatetags", "sync" ] l = self.getControl(ACTION_LIST) for i in range(len(actions)): if keys[i] in self.buttons: l.addItem(self.newListItem(actions[i], id=keys[i])) h = ((len(self.buttons)) * 46) - 6 l.setHeight(h) d = self.getControl(DIALOG_IMAGE) d.setHeight(h + 40) offset = (316 - h) / 2 d.setPosition(0, offset - 20) l.setPosition(20, offset) self.setFocus(l)
def onInit(self): lang = utils.getString mange_string = lang(32133) if utils.isMovie( self.media_type) else lang(32134) rate_string = lang(32137) if utils.isShow(self.media_type): rate_string = lang(32138) elif utils.isSeason(self.media_type): rate_string = lang(32149) elif utils.isEpisode(self.media_type): rate_string = lang(32139) actions = [ mange_string, lang(32135), lang(32136), rate_string, lang(32140), lang(32141), lang(32142), lang(32143) ] keys = [ "itemlists", "removefromlist", "addtolist", "rate", "togglewatched", "managelists", "updatetags", "sync" ] l = self.getControl(ACTION_LIST) for i in range(len(actions)): if keys[i] in self.buttons: l.addItem(self.newListItem(actions[i], id=keys[i])) h = ((len(self.buttons)) * 46) - 6 l.setHeight(h) d = self.getControl(DIALOG_IMAGE) d.setHeight(h + 40) self.setFocus(l)
def __rateOnTrakt(rating, media_type, media, unrate=False): logger.debug("Sending rating (%s) to Trakt.tv" % rating) params = media if utils.isMovie(media_type): key = 'movies' params['rating'] = rating elif utils.isShow(media_type): key = 'shows' params['rating'] = rating elif utils.isSeason(media_type): key = 'shows' params['seasons'] = [{'rating': rating, 'number': media['season']}] elif utils.isEpisode(media_type): key = 'episodes' params['rating'] = rating else: return root = {key: [params]} if not unrate: data = globals.traktapi.addRating(root) else: data = globals.traktapi.removeRating(root) if data: s = utils.getFormattedItemName(media_type, media) if 'not_found' in data and not data['not_found']['movies'] and not data[ 'not_found']['episodes'] and not data['not_found']['shows']: if not unrate: utils.notification(utils.getString(32040), s) else: utils.notification(utils.getString(32042), s) else: utils.notification(utils.getString(32044), s)
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 test_isShow(): assert utilities.isShow('show')
def doMarkWatched(self, data): media_type = data['media_type'] if utilities.isMovie(media_type): summaryInfo = globals.traktapi.getMovieSummary( data['id']).to_dict() if summaryInfo: if not summaryInfo['watched']: s = utilities.getFormattedItemName(media_type, summaryInfo) logger.debug( "doMarkWatched(): '%s' is not watched on Trakt, marking it as watched." % s) params = {'movies': [summaryInfo]} logger.debug("doMarkWatched(): %s" % str(params)) result = globals.traktapi.addToHistory(params) if result: utilities.notification(utilities.getString(32113), s) else: utilities.notification(utilities.getString(32114), s) elif utilities.isEpisode(media_type): summaryInfo = { 'shows': [{ 'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0], 'seasons': [{ 'number': data['season'], 'episodes': [{ 'number': data['number'] }] }] }] } logger.debug("doMarkWatched(): %s" % str(summaryInfo)) s = utilities.getFormattedItemName(media_type, data) result = globals.traktapi.addToHistory(summaryInfo) if result: utilities.notification(utilities.getString(32113), s) else: utilities.notification(utilities.getString(32114), s) elif utilities.isSeason(media_type): summaryInfo = { 'shows': [{ 'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0], 'seasons': [{ 'number': data['season'], 'episodes': [] }] }] } s = utilities.getFormattedItemName(media_type, data) for ep in data['episodes']: summaryInfo['shows'][0]['seasons'][0]['episodes'].append( {'number': ep}) logger.debug( "doMarkWatched(): '%s - Season %d' has %d episode(s) that are going to be marked as watched." % (data['id'], data['season'], len(summaryInfo['shows'][0]['seasons'][0]['episodes']))) if len(summaryInfo['shows'][0]['seasons'][0]['episodes']) > 0: logger.debug("doMarkWatched(): %s" % str(summaryInfo)) result = globals.traktapi.addToHistory(summaryInfo) if result: utilities.notification( utilities.getString(32113), utilities.getString(32115) % (result['added']['episodes'], s)) else: utilities.notification(utilities.getString(32114), s) elif utilities.isShow(media_type): summaryInfo = { 'shows': [{ 'ids': utilities.parseIdToTraktIds(data['id'], media_type)[0], 'seasons': [] }] } if summaryInfo: s = utilities.getFormattedItemName(media_type, data) logger.debug('data: %s' % data) for season in data['seasons']: episodeJson = [] for episode in data['seasons'][season]: episodeJson.append({'number': episode}) summaryInfo['shows'][0]['seasons'].append({ 'number': season, 'episodes': episodeJson }) if len(summaryInfo['shows'][0]['seasons'][0]['episodes']) > 0: logger.debug("doMarkWatched(): %s" % str(summaryInfo)) result = globals.traktapi.addToHistory(summaryInfo) if result: utilities.notification( utilities.getString(32113), utilities.getString(32115) % (result['added']['episodes'], s)) else: utilities.notification(utilities.getString(32114), s)
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)
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 rateOnTrakt(rating, media_type, media, unrate=False): utils.Debug("[Rating] Sending rating (%s) to trakt.tv" % rating) params = {} params['rating'] = rating if utils.isMovie(media_type): params['title'] = media['title'] params['year'] = media['year'] params['tmdb_id'] = media['tmdb_id'] params['imdb_id'] = media['imdb_id'] data = globals.traktapi.rateMovie(params) elif utils.isShow(media_type): params['title'] = media['title'] params['year'] = media['year'] params['tvdb_id'] = media['tvdb_id'] params['imdb_id'] = media['imdb_id'] data = globals.traktapi.rateShow(params) elif utils.isEpisode(media_type): params['title'] = media['show']['title'] params['year'] = media['show']['year'] params['season'] = media['episode']['season'] params['episode'] = media['episode']['number'] params['tvdb_id'] = media['show']['tvdb_id'] params['imdb_id'] = media['show']['imdb_id'] data = globals.traktapi.rateEpisode(params) else: return if data: s = utils.getFormattedItemName(media_type, media) if 'status' in data and data['status'] == "success": if tagging.isTaggingEnabled() and tagging.isRatingsEnabled(): if utils.isMovie(media_type) or utils.isShow(media_type): id = media['xbmc_id'] f = utils.getMovieDetailsFromXbmc if utils.isMovie(media_type) else utils.getShowDetailsFromXBMC result = f(id, ['tag']) if result: tags = result['tag'] new_rating = rating if new_rating == "love": new_rating = 10 elif new_rating == "hate": new_rating = 1 new_rating_tag = tagging.ratingToTag(new_rating) if unrate: new_rating_tag = "" update = False if tagging.hasTraktRatingTag(tags): old_rating_tag = tagging.getTraktRatingTag(tags) if not old_rating_tag == new_rating_tag: tags.remove(old_rating_tag) update = True if not unrate and new_rating >= tagging.getMinRating(): tags.append(new_rating_tag) update = True if update: tagging.xbmcSetTags(id, media_type, s, tags) else: utils.Debug("No data was returned from XBMC, aborting tag udpate.") if not unrate: utils.notification(utils.getString(1350), s) else: utils.notification(utils.getString(1352), s) elif 'status' in data and data['status'] == "failure": utils.notification(utils.getString(1354), s) else: # status not in data, different problem, do nothing for now pass
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)
def Main(): args = __getArguments() data = {} if args["action"] == "pin_info": xbmc.executebuiltin("Dialog.Close(all, true)") pinInfo = xbmcgui.WindowXMLDialog("PinInfoWindow.xml", __addon__.getAddonInfo("path")) pinInfo.doModal() del pinInfo if args["action"] == "contextmenu": buttons = [] media_type = __getMediaType() if media_type in ["movie", "show", "season", "episode"]: buttons.append("rate") if media_type in ["movie", "show", "season", "episode"]: buttons.append("togglewatched") buttons.append("sync") contextMenu = traktContextMenu(media_type=media_type, buttons=buttons) contextMenu.doModal() _action = contextMenu.action del contextMenu if _action is None: return logger.debug("'%s' selected from trakt.tv action menu" % _action) args["action"] = _action if args["action"] == "sync": data = {"action": "manualSync", "silent": False} if "silent" in args: data["silent"] = args["silent"].lower() == "true" data["library"] = "all" if "library" in args and args["library"] in ["episodes", "movies"]: data["library"] = args["library"] elif args["action"] in ["rate", "unrate"]: 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: logger.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"] try: data["season"] = int(args["season"]) data["episode"] = int(args["episode"]) except ValueError: logger.debug("Error parsing season or episode for manual %s" % args["action"]) return except KeyError: pass else: media_type = __getMediaType() if not utils.isValidMediaType(media_type): logger.debug("Error, not in video library.") return data["dbid"] = int(xbmc.getInfoLabel("ListItem.DBID")) if media_type is None: logger.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: logger.debug( "Manual %s of library '%s' with an ID of '%s'." % (args["action"], media_type, data["dbid"]) ) if utils.isMovie(media_type): result = utils.getMovieDetailsFromKodi(data["dbid"], ["imdbnumber", "title", "year"]) if not result: logger.debug("No data was returned from Kodi, aborting manual %s." % args["action"]) return data["imdbnumber"] = result["imdbnumber"] elif utils.isShow(media_type) or utils.isSeason(media_type): result = utils.getShowDetailsFromKodi(data["dbid"], ["imdbnumber", "tag"]) if not result: logger.debug("No data was returned from Kodi, aborting manual %s." % args["action"]) return data["imdbnumber"] = result["imdbnumber"] data["tag"] = result["tag"] elif utils.isEpisode(media_type): result = utils.getEpisodeDetailsFromKodi( data["dbid"], ["showtitle", "season", "episode", "tvshowid", "uniqueid", "file", "playcount"] ) if not result: logger.debug("No data was returned from Kodi, aborting manual %s." % args["action"]) return data["imdbnumber"] = result["episodeid"] data["season"] = result["season"] data["episode"] = result["episode"] else: data["imdbnumber"] = data["remoteid"] if "season" in data and "episode" in data: logger.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"]) ) elif "season" in data: logger.debug( "Manual %s of non-library '%s' S%02d, with an ID of '%s'." % (args["action"], media_type, data["season"], data["remoteid"]) ) else: logger.debug( "Manual %s of non-library '%s' with an ID of '%s'." % (args["action"], media_type, 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: logger.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 = {"media_type": media_type} if utils.isMovie(media_type): dbid = int(xbmc.getInfoLabel("ListItem.DBID")) result = utils.getMovieDetailsFromKodi(dbid, ["imdbnumber", "title", "year", "playcount"]) if result: if result["playcount"] == 0: data["id"] = result["imdbnumber"] else: logger.debug("Movie alread marked as watched in Kodi.") else: logger.debug("Error getting movie details from Kodi.") return elif utils.isEpisode(media_type): dbid = int(xbmc.getInfoLabel("ListItem.DBID")) result = utils.getEpisodeDetailsFromKodi( dbid, ["showtitle", "season", "episode", "tvshowid", "playcount"] ) if result: if result["playcount"] == 0: data["id"] = result["imdbnumber"] data["season"] = result["season"] data["number"] = result["episode"] data["title"] = result["showtitle"] else: logger.debug("Episode already marked as watched in Kodi.") else: logger.debug("Error getting episode details from Kodi.") return elif utils.isSeason(media_type): showID = None showTitle = xbmc.getInfoLabel("ListItem.TVShowTitle") result = utils.kodiJsonRequest( { "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"] data["title"] = show["title"] break else: logger.debug("Error getting TV shows from Kodi.") return season = xbmc.getInfoLabel("ListItem.Season") if season == "": season = 0 else: season = int(season) result = utils.kodiJsonRequest( { "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: logger.debug("'%s - Season %d' is already marked as watched." % (showTitle, season)) return data["season"] = season data["episodes"] = episodes else: logger.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.getShowDetailsFromKodi(dbid, ["year", "imdbnumber"]) if not result: logger.debug("Error getting show details from Kodi.") return showTitle = result["label"] data["id"] = result["imdbnumber"] result = utils.kodiJsonRequest( { "jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": dbid, "properties": ["season", "episode", "playcount", "showtitle"]}, "id": 0, } ) if result and "episodes" in result: i = 0 s = {} for e in result["episodes"]: data["title"] = e["showtitle"] season = str(e["season"]) if not season in s: s[season] = [] if e["playcount"] == 0: s[season].append(e["episode"]) i += 1 if i == 0: logger.debug("'%s' is already marked as watched." % showTitle) return data["seasons"] = dict((k, v) for k, v in s.iteritems() if v) else: logger.debug("Error getting episode details for '%s' from Kodi." % showTitle) return if len(data) > 1: logger.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)") q = sqlitequeue.SqliteQueue() if "action" in data: logger.debug("Queuing for dispatch: %s" % data) q.append(data)
def Main(): args = getArguments() data = {} if args["action"] == "contextmenu": buttons = [] media_type = getMediaType() if utils.getSettingAsBool("tagging_enable"): if utils.isMovie(media_type): buttons.append("itemlists") dbid = int(xbmc.getInfoLabel("ListItem.DBID")) result = utils.getMovieDetailsFromXbmc(dbid, ["tag"]) if tagging.hasTraktWatchlistTag(result["tag"]): buttons.append("removefromlist") else: buttons.append("addtolist") elif utils.isShow(media_type): buttons.append("itemlists") dbid = int(xbmc.getInfoLabel("ListItem.DBID")) result = utils.getShowDetailsFromXBMC(dbid, ["tag"]) if tagging.hasTraktWatchlistTag(result["tag"]): buttons.append("removefromlist") else: buttons.append("addtolist") if media_type in ["movie", "show", "episode"]: buttons.append("rate") if media_type in ["movie", "show", "season", "episode"]: buttons.append("togglewatched") if utils.getSettingAsBool("tagging_enable"): buttons.append("managelists") buttons.append("updatetags") buttons.append("sync") contextMenu = traktContextMenu(media_type=media_type, buttons=buttons) contextMenu.doModal() _action = contextMenu.action del contextMenu if _action is None: return utils.Debug("'%s' selected from trakt.tv action menu" % _action) args["action"] = _action if _action in ["addtolist", "removefromlist"]: args["list"] = "watchlist" if args["action"] == "sync": data = {"action": "manualSync"} data["silent"] = False if "silent" in args: data["silent"] = args["silent"].lower() == "true" elif args["action"] == "loadsettings": data = {"action": "loadsettings", "force": True} utils.notification(utils.getString(1201), utils.getString(1111)) 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)
def doManualRating(self): data = json.loads(utilities.getProperty('traktManualRateData')) 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): result = {} if 'dbid' in data: result = utilities.getEpisodeDetailsFromXbmc(data['dbid'], ['showtitle', 'season', 'episode', 'tvshowid']) if not result: utilities.Debug("doManualRating(): No data was returned from XBMC, aborting manual %s." % action) return else: result['tvdb_id'] = data['remoteid'] result['season'] = data['season'] result['episode'] = data['episode'] summaryInfo = globals.traktapi.getEpisodeSummary(result['tvdb_id'], result['season'], result['episode']) elif utilities.isShow(media_type): result = {} if 'dbid' in data: result = utilities.getShowDetailsFromXBMC(data['dbid'], ['imdbnumber']) if not result: utilities.Debug("doManualRating(): No data was returned from XBMC, aborting manual %s." % action) return else: result['imdbnumber'] = data['remoteid'] summaryInfo = globals.traktapi.getShowSummary(result['imdbnumber']) elif utilities.isMovie(media_type): result = {} if 'dbid' in data: result = utilities.getMovieDetailsFromXbmc(data['dbid'], ['imdbnumber', 'title', 'year']) if not result: utilities.Debug("doManualRating(): No data was returned from XBMC, aborting manual %s." % action) return else: result['imdbnumber'] = data['remoteid'] summaryInfo = globals.traktapi.getMovieSummary(result['imdbnumber']) if not summaryInfo is None: 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 Main(): args = __getArguments() data = {} if args['action'] == 'auth_info': data['action'] = 'auth_info' if args['action'] == 'contextmenu': buttons = [] media_type = kodiUtilities.getMediaType() if media_type in ['movie', 'show', 'season', 'episode']: buttons.append("rate") buttons.append("togglewatched") buttons.append("addtowatchlist") buttons.append("sync") contextMenu = traktContextMenu(media_type=media_type, buttons=buttons) contextMenu.doModal() _action = contextMenu.action del contextMenu if _action is None: return logger.debug("'%s' selected from trakt.tv action menu" % _action) args['action'] = _action if args['action'] == 'sync': data = {'action': 'manualSync', 'silent': False} if 'silent' in args: data['silent'] = (args['silent'].lower() == 'true') data['library'] = "all" if 'library' in args and args['library'] in ['episodes', 'movies']: data['library'] = args['library'] elif args['action'] in ['rate', 'unrate']: 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: logger.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'] try: data['season'] = int(args['season']) data['episode'] = int(args['episode']) except ValueError: logger.debug("Error parsing season or episode for manual %s" % args['action']) return except KeyError: pass else: media_type = kodiUtilities.getMediaType() if not utilities.isValidMediaType(media_type): logger.debug("Error, not in video library.") return data['dbid'] = int(xbmc.getInfoLabel('ListItem.DBID')) if media_type is None: logger.debug( "Manual %s triggered on an unsupported content container." % args['action']) elif utilities.isValidMediaType(media_type): data['media_type'] = media_type if 'dbid' in data: logger.debug("Manual %s of library '%s' with an ID of '%s'." % (args['action'], media_type, data['dbid'])) if utilities.isMovie(media_type): result = kodiUtilities.getMovieDetailsFromKodi( data['dbid'], ['imdbnumber', 'title', 'year']) if not result: logger.debug( "No data was returned from Kodi, aborting manual %s." % args['action']) return elif utilities.isShow(media_type): tvshow_id = data['dbid'] elif utilities.isSeason(media_type): result = kodiUtilities.getSeasonDetailsFromKodi( data['dbid'], ['tvshowid', 'season']) if not result: logger.debug( "No data was returned from Kodi, aborting manual %s." % args['action']) return tvshow_id = result['tvshowid'] data['season'] = result['season'] elif utilities.isEpisode(media_type): result = kodiUtilities.getEpisodeDetailsFromKodi( data['dbid'], ['season', 'episode', 'tvshowid']) if not result: logger.debug( "No data was returned from Kodi, aborting manual %s." % args['action']) return tvshow_id = result['tvshowid'] data['season'] = result['season'] data['episode'] = result['episode'] if utilities.isShow(media_type) or utilities.isSeason( media_type) or utilities.isEpisode(media_type): result = kodiUtilities.getShowDetailsFromKodi( tvshow_id, ['imdbnumber']) if not result: logger.debug( "No data was returned from Kodi, aborting manual %s." % args['action']) return data['video_id'] = result['imdbnumber'] else: data['video_id'] = data['remoteid'] if 'season' in data and 'episode' in data: logger.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'])) elif 'season' in data: logger.debug( "Manual %s of non-library '%s' S%02d, with an ID of '%s'." % (args['action'], media_type, data['season'], data['remoteid'])) else: logger.debug( "Manual %s of non-library '%s' with an ID of '%s'." % (args['action'], media_type, 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: logger.debug("Manual %s of '%s' is unsupported." % (args['action'], media_type)) elif args['action'] == 'togglewatched': media_type = kodiUtilities.getMediaType() if media_type in ['movie', 'show', 'season', 'episode']: data = {'media_type': media_type} if utilities.isMovie(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getMovieDetailsFromKodi( dbid, ['imdbnumber', 'title', 'year', 'playcount']) if result: if result['playcount'] == 0: data['id'] = result['imdbnumber'] else: logger.debug("Movie alread marked as watched in Kodi.") else: logger.debug("Error getting movie details from Kodi.") return elif utilities.isEpisode(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getEpisodeDetailsFromKodi( dbid, [ 'showtitle', 'season', 'episode', 'tvshowid', 'playcount' ]) if result: if result['playcount'] == 0: data['id'] = result['imdbnumber'] data['season'] = result['season'] data['number'] = result['episode'] data['title'] = result['showtitle'] else: logger.debug( "Episode already marked as watched in Kodi.") else: logger.debug("Error getting episode details from Kodi.") return elif utilities.isSeason(media_type): showID = None showTitle = xbmc.getInfoLabel('ListItem.TVShowTitle') result = kodiUtilities.kodiJsonRequest({ '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'] data['title'] = show['title'] break else: logger.debug("Error getting TV shows from Kodi.") return season = xbmc.getInfoLabel('ListItem.Season') if season == "": season = 0 else: season = int(season) result = kodiUtilities.kodiJsonRequest({ '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: logger.debug( "'%s - Season %d' is already marked as watched." % (showTitle, season)) return data['season'] = season data['episodes'] = episodes else: logger.debug( "Error getting episodes from '%s' for Season %d" % (showTitle, season)) return elif utilities.isShow(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getShowDetailsFromKodi( dbid, ['year', 'imdbnumber']) if not result: logger.debug("Error getting show details from Kodi.") return showTitle = result['label'] data['id'] = result['imdbnumber'] result = kodiUtilities.kodiJsonRequest({ 'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodes', 'params': { 'tvshowid': dbid, 'properties': ['season', 'episode', 'playcount', 'showtitle'] }, 'id': 0 }) if result and 'episodes' in result: i = 0 s = {} for e in result['episodes']: data['title'] = e['showtitle'] season = str(e['season']) if not season in s: s[season] = [] if e['playcount'] == 0: s[season].append(e['episode']) i += 1 if i == 0: logger.debug("'%s' is already marked as watched." % showTitle) return data['seasons'] = dict( (k, v) for k, v in s.iteritems() if v) else: logger.debug( "Error getting episode details for '%s' from Kodi." % showTitle) return if len(data) > 1: logger.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'] == 'addtowatchlist': media_type = kodiUtilities.getMediaType() if media_type in ['movie', 'show', 'season', 'episode']: data = {'media_type': media_type} if utilities.isMovie(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getMovieDetailsFromKodi( dbid, ['imdbnumber', 'title', 'year', 'playcount']) if result: data['id'] = result['imdbnumber'] else: logger.debug("Error getting movie details from Kodi.") return elif utilities.isEpisode(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getEpisodeDetailsFromKodi( dbid, [ 'showtitle', 'season', 'episode', 'tvshowid', 'playcount' ]) if result: data['id'] = result['imdbnumber'] data['season'] = result['season'] data['number'] = result['episode'] data['title'] = result['showtitle'] else: logger.debug("Error getting episode details from Kodi.") return elif utilities.isSeason(media_type): showID = None showTitle = xbmc.getInfoLabel('ListItem.TVShowTitle') result = kodiUtilities.kodiJsonRequest({ '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'] data['title'] = show['title'] break else: logger.debug("Error getting TV shows from Kodi.") return season = xbmc.getInfoLabel('ListItem.Season') if season == "": season = 0 else: season = int(season) result = kodiUtilities.kodiJsonRequest({ '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']) data['season'] = season data['episodes'] = episodes else: logger.debug( "Error getting episodes from '%s' for Season %d" % (showTitle, season)) return elif utilities.isShow(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getShowDetailsFromKodi( dbid, ['year', 'imdbnumber']) if not result: logger.debug("Error getting show details from Kodi.") return showTitle = result['label'] data['id'] = result['imdbnumber'] result = kodiUtilities.kodiJsonRequest({ 'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodes', 'params': { 'tvshowid': dbid, 'properties': ['season', 'episode', 'playcount', 'showtitle'] }, 'id': 0 }) if result and 'episodes' in result: s = {} for e in result['episodes']: data['title'] = e['showtitle'] season = str(e['season']) if not season in s: s[season] = [] if e['playcount'] == 0: s[season].append(e['episode']) data['seasons'] = dict( (k, v) for k, v in s.iteritems() if v) else: logger.debug( "Error getting episode details for '%s' from Kodi." % showTitle) return if len(data) > 1: logger.debug( "Adding '%s' with the following data '%s' to users watchlist on Trakt.tv" % (media_type, str(data))) data['action'] = 'addtowatchlist' q = sqlitequeue.SqliteQueue() if 'action' in data: logger.debug("Queuing for dispatch: %s" % data) q.append(data)
def Main(): args = __getArguments() data = {} if args['action'] == 'auth_info': data['action'] = 'auth_info' if args['action'] == 'contextmenu': buttons = [] media_type = kodiUtilities.getMediaType() if media_type in ['movie', 'show', 'season', 'episode']: buttons.append("rate") buttons.append("togglewatched") buttons.append("addtowatchlist") buttons.append("sync") contextMenu = traktContextMenu(media_type=media_type, buttons=buttons) contextMenu.doModal() _action = contextMenu.action del contextMenu if _action is None: return logger.debug("'%s' selected from trakt.tv action menu" % _action) args['action'] = _action if args['action'] == 'sync': data = {'action': 'manualSync', 'silent': False} if 'silent' in args: data['silent'] = (args['silent'].lower() == 'true') data['library'] = "all" if 'library' in args and args['library'] in ['episodes', 'movies']: data['library'] = args['library'] elif args['action'] in ['rate', 'unrate']: 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: logger.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'] try: data['season'] = int(args['season']) data['episode'] = int(args['episode']) except ValueError: logger.debug("Error parsing season or episode for manual %s" % args['action']) return except KeyError: pass else: media_type = kodiUtilities.getMediaType() if not utilities.isValidMediaType(media_type): logger.debug("Error, not in video library.") return data['dbid'] = int(xbmc.getInfoLabel('ListItem.DBID')) if media_type is None: logger.debug("Manual %s triggered on an unsupported content container." % args['action']) elif utilities.isValidMediaType(media_type): data['media_type'] = media_type if 'dbid' in data: logger.debug("Manual %s of library '%s' with an ID of '%s'." % (args['action'], media_type, data['dbid'])) if utilities.isMovie(media_type): result = kodiUtilities.getMovieDetailsFromKodi(data['dbid'], ['imdbnumber', 'title', 'year']) if not result: logger.debug("No data was returned from Kodi, aborting manual %s." % args['action']) return elif utilities.isShow(media_type): tvshow_id = data['dbid'] elif utilities.isSeason(media_type): result = kodiUtilities.getSeasonDetailsFromKodi(data['dbid'], ['tvshowid', 'season']) if not result: logger.debug("No data was returned from Kodi, aborting manual %s." % args['action']) return tvshow_id = result['tvshowid'] data['season'] = result['season'] elif utilities.isEpisode(media_type): result = kodiUtilities.getEpisodeDetailsFromKodi(data['dbid'], ['season', 'episode', 'tvshowid']) if not result: logger.debug("No data was returned from Kodi, aborting manual %s." % args['action']) return tvshow_id = result['tvshowid'] data['season'] = result['season'] data['episode'] = result['episode'] if utilities.isShow(media_type) or utilities.isSeason(media_type) or utilities.isEpisode(media_type): result = kodiUtilities.getShowDetailsFromKodi(tvshow_id, ['imdbnumber']) if not result: logger.debug("No data was returned from Kodi, aborting manual %s." % args['action']) return data['video_id'] = result['imdbnumber'] else: data['video_id'] = data['remoteid'] if 'season' in data and 'episode' in data: logger.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'])) elif 'season' in data: logger.debug("Manual %s of non-library '%s' S%02d, with an ID of '%s'." % (args['action'], media_type, data['season'], data['remoteid'])) else: logger.debug("Manual %s of non-library '%s' with an ID of '%s'." % (args['action'], media_type, 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: logger.debug("Manual %s of '%s' is unsupported." % (args['action'], media_type)) elif args['action'] == 'togglewatched': media_type = kodiUtilities.getMediaType() if media_type in ['movie', 'show', 'season', 'episode']: data = {'media_type': media_type} if utilities.isMovie(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getMovieDetailsFromKodi(dbid, ['imdbnumber', 'title', 'year', 'playcount']) if result: if result['playcount'] == 0: data['id'] = result['imdbnumber'] else: logger.debug("Movie alread marked as watched in Kodi.") else: logger.debug("Error getting movie details from Kodi.") return elif utilities.isEpisode(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getEpisodeDetailsFromKodi(dbid, ['showtitle', 'season', 'episode', 'tvshowid', 'playcount']) if result: if result['playcount'] == 0: data['id'] = result['imdbnumber'] data['season'] = result['season'] data['number'] = result['episode'] data['title'] = result['showtitle'] else: logger.debug("Episode already marked as watched in Kodi.") else: logger.debug("Error getting episode details from Kodi.") return elif utilities.isSeason(media_type): showID = None showTitle = xbmc.getInfoLabel('ListItem.TVShowTitle') result = kodiUtilities.kodiJsonRequest({'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'] data['title'] = show['title'] break else: logger.debug("Error getting TV shows from Kodi.") return season = xbmc.getInfoLabel('ListItem.Season') if season == "": season = 0 else: season = int(season) result = kodiUtilities.kodiJsonRequest({'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: logger.debug("'%s - Season %d' is already marked as watched." % (showTitle, season)) return data['season'] = season data['episodes'] = episodes else: logger.debug("Error getting episodes from '%s' for Season %d" % (showTitle, season)) return elif utilities.isShow(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getShowDetailsFromKodi(dbid, ['year', 'imdbnumber']) if not result: logger.debug("Error getting show details from Kodi.") return showTitle = result['label'] data['id'] = result['imdbnumber'] result = kodiUtilities.kodiJsonRequest({'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodes', 'params': {'tvshowid': dbid, 'properties': ['season', 'episode', 'playcount', 'showtitle']}, 'id': 0}) if result and 'episodes' in result: i = 0 s = {} for e in result['episodes']: data['title'] = e['showtitle'] season = str(e['season']) if not season in s: s[season] = [] if e['playcount'] == 0: s[season].append(e['episode']) i += 1 if i == 0: logger.debug("'%s' is already marked as watched." % showTitle) return data['seasons'] = dict((k, v) for k, v in s.iteritems() if v) else: logger.debug("Error getting episode details for '%s' from Kodi." % showTitle) return if len(data) > 1: logger.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'] == 'addtowatchlist': media_type = kodiUtilities.getMediaType() if media_type in ['movie', 'show', 'season', 'episode']: data = {'media_type': media_type} if utilities.isMovie(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getMovieDetailsFromKodi(dbid, ['imdbnumber', 'title', 'year', 'playcount']) if result: data['id'] = result['imdbnumber'] else: logger.debug("Error getting movie details from Kodi.") return elif utilities.isEpisode(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getEpisodeDetailsFromKodi(dbid, ['showtitle', 'season', 'episode', 'tvshowid', 'playcount']) if result: data['id'] = result['imdbnumber'] data['season'] = result['season'] data['number'] = result['episode'] data['title'] = result['showtitle'] else: logger.debug("Error getting episode details from Kodi.") return elif utilities.isSeason(media_type): showID = None showTitle = xbmc.getInfoLabel('ListItem.TVShowTitle') result = kodiUtilities.kodiJsonRequest({'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'] data['title'] = show['title'] break else: logger.debug("Error getting TV shows from Kodi.") return season = xbmc.getInfoLabel('ListItem.Season') if season == "": season = 0 else: season = int(season) result = kodiUtilities.kodiJsonRequest({'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']) data['season'] = season data['episodes'] = episodes else: logger.debug("Error getting episodes from '%s' for Season %d" % (showTitle, season)) return elif utilities.isShow(media_type): dbid = int(xbmc.getInfoLabel('ListItem.DBID')) result = kodiUtilities.getShowDetailsFromKodi(dbid, ['year', 'imdbnumber']) if not result: logger.debug("Error getting show details from Kodi.") return showTitle = result['label'] data['id'] = result['imdbnumber'] result = kodiUtilities.kodiJsonRequest({'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodes', 'params': {'tvshowid': dbid, 'properties': ['season', 'episode', 'playcount', 'showtitle']}, 'id': 0}) if result and 'episodes' in result: s = {} for e in result['episodes']: data['title'] = e['showtitle'] season = str(e['season']) if not season in s: s[season] = [] if e['playcount'] == 0: s[season].append(e['episode']) data['seasons'] = dict((k, v) for k, v in s.iteritems() if v) else: logger.debug("Error getting episode details for '%s' from Kodi." % showTitle) return if len(data) > 1: logger.debug("Adding '%s' with the following data '%s' to users watchlist on Trakt.tv" % (media_type, str(data))) data['action'] = 'addtowatchlist' q = sqlitequeue.SqliteQueue() if 'action' in data: logger.debug("Queuing for dispatch: %s" % data) q.append(data)