def doAddToWatchlist(self, data): media_type = data['media_type'] if utilities.isMovie(media_type): temp_ids, id_type = utilities.parseIdToTraktIds( str(utilities.best_id(data['ids'], media_type)), media_type) best_id = temp_ids[id_type] summaryInfo = globals.traktapi.getMovieSummary( best_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': data['ids'], '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': data['ids'], 'seasons': [{'number': data['season']}]}]} s = utilities.getFormattedItemName(media_type, data) logger.debug("doAddToWatchlist(): '%s - Season %d' trying to add to users watchlist." % (ids, 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': data['ids']}]} 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 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 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 __scrobbleNotification(self, info): if not self.curVideoInfo: return if kodiUtilities.getSettingAsBool("scrobble_notification"): s = utilities.getFormattedItemName(self.curVideo['type'], info[self.curVideo['type']]) kodiUtilities.notification(kodiUtilities.getString(32015), s)
def onInit(self): s = utilities.getFormattedItemName(self.media_type, self.media) self.getControl(10012).setLabel(s) rateID = 11029 + self.default_rating if self.rerate and self.media['user']['ratings'] and int(self.media['user']['ratings']['rating']) > 0: rateID = 11029 + int(self.media['user']['ratings']['rating']) self.setFocus(self.getControl(rateID))
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' # we need to remove this key or trakt will be confused del(params["seasons"]) 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 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 test_getFormattedItemName_Movie(): data = load_params_from_json('tests/fixtures/movie.json') assert utilities.getFormattedItemName('movie', data) == b'TRON: Legacy (2010)'
def test_getFormattedItemName_Season(): data = load_params_from_json('tests/fixtures/season.json') assert utilities.getFormattedItemName('season', data) == b'Winter Is Coming - Season 1'
def test_getFormattedItemName_Season2(): data = load_params_from_json('tests/fixtures/season_no_list.json') assert utilities.getFormattedItemName('season', data) == b'Regular Show - Season 8'
def test_getFormattedItemName_Episode(): data = load_params_from_json('tests/fixtures/episode.json') assert utilities.getFormattedItemName('episode', data) == b'S01E01 - Winter Is Coming'
def test_getFormattedItemName_Show(): data = load_params_from_json('tests/fixtures/show.json') assert utilities.getFormattedItemName('show', data) == b'Game of Thrones'
def test_getFormattedItemName_Season(): data = load_params_from_json('tests/fixtures/season.json') assert utilities.getFormattedItemName( 'season', data) == b'Winter Is Coming - Season 1'
def rateMedia(media_type, itemsToRate, unrate=False, rating=None): """Launches the rating dialog""" for summary_info in itemsToRate: if not utilities.isValidMediaType(media_type): logger.debug("Not a valid media type") return elif 'user' not in summary_info: logger.debug("No user data") return s = utilities.getFormattedItemName(media_type, summary_info) logger.debug("Summary Info %s" % summary_info) if unrate: rating = None if summary_info['user']['ratings']['rating'] > 0: rating = 0 if not rating is None: logger.debug("'%s' is being unrated." % s) __rateOnTrakt(rating, media_type, summary_info, unrate=True) else: logger.debug("'%s' has not been rated, so not unrating." % s) return rerate = kodiUtilities.getSettingAsBool('rate_rerate') if rating is not None: if summary_info['user']['ratings']['rating'] == 0: logger.debug("Rating for '%s' is being set to '%d' manually." % (s, rating)) __rateOnTrakt(rating, media_type, summary_info) else: if rerate: if not summary_info['user']['ratings']['rating'] == rating: logger.debug( "Rating for '%s' is being set to '%d' manually." % (s, rating)) __rateOnTrakt(rating, media_type, summary_info) else: kodiUtilities.notification( kodiUtilities.getString(32043), s) logger.debug("'%s' already has a rating of '%d'." % (s, rating)) else: kodiUtilities.notification(kodiUtilities.getString(32041), s) logger.debug("'%s' is already rated." % s) return if summary_info['user']['ratings'] and summary_info['user']['ratings'][ 'rating']: if not rerate: logger.debug("'%s' has already been rated." % s) kodiUtilities.notification(kodiUtilities.getString(32041), s) return else: logger.debug("'%s' is being re-rated." % s) gui = RatingDialog("script-trakt-RatingDialog.xml", __addon__.getAddonInfo('path'), media_type=media_type, media=summary_info, rerate=rerate) gui.doModal() if gui.rating: rating = gui.rating if rerate: rating = gui.rating if summary_info['user']['ratings'] and summary_info['user'][ 'ratings']['rating'] > 0 and rating == summary_info[ 'user']['ratings']['rating']: rating = 0 if rating == 0 or rating == "unrate": __rateOnTrakt(rating, gui.media_type, gui.media, unrate=True) else: __rateOnTrakt(rating, gui.media_type, gui.media) else: logger.debug("Rating dialog was closed with no rating.") del gui #Reset rating and unrate for multi part episodes unrate = False rating = None
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 rateMedia(media_type, itemsToRate, unrate=False, rating=None): """Launches the rating dialog""" for summary_info in itemsToRate: if not utilities.isValidMediaType(media_type): logger.debug("Not a valid media type") return elif 'user' not in summary_info: logger.debug("No user data") return s = utilities.getFormattedItemName(media_type, summary_info) logger.debug("Summary Info %s" % summary_info) if unrate: rating = None if summary_info['user']['ratings']['rating'] > 0: rating = 0 if not rating is None: logger.debug("'%s' is being unrated." % s) __rateOnTrakt(rating, media_type, summary_info, unrate=True) else: logger.debug("'%s' has not been rated, so not unrating." % s) return rerate = kodiUtilities.getSettingAsBool('rate_rerate') if rating is not None: if summary_info['user']['ratings']['rating'] == 0: logger.debug("Rating for '%s' is being set to '%d' manually." % (s, rating)) __rateOnTrakt(rating, media_type, summary_info) else: if rerate: if not summary_info['user']['ratings']['rating'] == rating: logger.debug("Rating for '%s' is being set to '%d' manually." % (s, rating)) __rateOnTrakt(rating, media_type, summary_info) else: kodiUtilities.notification(kodiUtilities.getString(32043), s) logger.debug("'%s' already has a rating of '%d'." % (s, rating)) else: kodiUtilities.notification(kodiUtilities.getString(32041), s) logger.debug("'%s' is already rated." % s) return if summary_info['user']['ratings'] and summary_info['user']['ratings']['rating']: if not rerate: logger.debug("'%s' has already been rated." % s) kodiUtilities.notification(kodiUtilities.getString(32041), s) return else: logger.debug("'%s' is being re-rated." % s) gui = RatingDialog( "script-trakt-RatingDialog.xml", __addon__.getAddonInfo('path'), media_type=media_type, media=summary_info, rerate=rerate ) gui.doModal() if gui.rating: rating = gui.rating if rerate: rating = gui.rating if summary_info['user']['ratings'] and summary_info['user']['ratings']['rating'] > 0 and rating == summary_info['user']['ratings']['rating']: rating = 0 if rating == 0 or rating == "unrate": __rateOnTrakt(rating, gui.media_type, gui.media, unrate=True) else: __rateOnTrakt(rating, gui.media_type, gui.media) else: logger.debug("Rating dialog was closed with no rating.") del gui #Reset rating and unrate for multi part episodes unrate=False rating=None