def watching(self): Debug("[Scrobbler] watching()") scrobbleMovieOption = __settings__.getSetting("scrobble_movie") scrobbleEpisodeOption = __settings__.getSetting("scrobble_episode") if self.curVideo['type'] == 'movie' and scrobbleMovieOption == 'true': match = None if 'id' in self.curVideo: match = utilities.getMovieDetailsFromXbmc(self.curVideo['id'], ['imdbnumber', 'title', 'year']) elif 'title' in self.curVideo and 'year' in self.curVideo: match = {} match['imdbnumber'] = '' match['title'] = self.curVideo['title'] match['year'] = self.curVideo['year'] if match == None: return duration = self.totalTime / 60 watchedPercent = int((self.watchedTime / self.totalTime) * 100) response = self.traktapi.watchingMovie(match['imdbnumber'], match['title'], match['year'], duration, watchedPercent) if response != None: Debug("[Scrobbler] Watch response: "+str(response)) elif self.curVideo['type'] == 'episode' and scrobbleEpisodeOption == 'true': match = None if 'id' in self.curVideo: if self.curVideo.has_key("multi_episode_count"): cur_episode = self._currentEpisode((self.watchedTime / self.totalTime) * 100, self.curVideo['multi_episode_count']) if cur_episode > 0: if not self.markedAsWatched[cur_episode - 1]: Debug("[Scrobbler] Attempting to scrobble episode part %d of %d." % (cur_episode, self.curVideo['multi_episode_count'])) episode_data = utilities.getEpisodeDetailsFromXbmc(self.curVideo["multi_episode_data"][cur_episode - 1], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) response = self.traktapi.scrobbleEpisode(episode_data['tvdb_id'], episode_data['showtitle'], episode_data['year'], episode_data['season'], episode_data['episode'], episode_data['uniqueid']['unknown'], self.totalTime/60, 100) if response != None: Debug("[Scrobbler] Scrobble response: %s" % str(response)) self.markedAsWatched[cur_episode - 1] = True Debug("[Scrobbler] Multi-part episode, watching part %d of %d." % (cur_episode + 1, self.curVideo['multi_episode_count'])) match = utilities.getEpisodeDetailsFromXbmc(self.curVideo["multi_episode_data"][cur_episode], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) else: match = utilities.getEpisodeDetailsFromXbmc(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) elif 'showtitle' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo: match = {} match['tvdb_id'] = None match['year'] = None match['showtitle'] = self.curVideo['showtitle'] match['season'] = self.curVideo['season'] match['episode'] = self.curVideo['episode'] match['uniqueid'] = None if match == None: return duration = self.totalTime / 60 watchedPercent = int((self.watchedTime / self.totalTime) * 100) response = self.traktapi.watchingEpisode(match['tvdb_id'], match['showtitle'], match['year'], match['season'], match['episode'], match['uniqueid']['unknown'], duration, watchedPercent) if response != None: Debug("[Scrobbler] Watch response: "+str(response))
def watching(self): if not self.isPlaying: return if not self.curVideoInfo: return Debug("[Scrobbler] watching()") self.update(True) duration = self.videoDuration / 60 watchedPercent = (self.watchedTime / self.videoDuration) * 100 if self.isMultiPartEpisode: Debug("[Scrobbler] Multi-part episode, watching part %d of %d." % ( self.curMPEpisode + 1, self.curVideo['multi_episode_count'])) # recalculate watchedPercent and duration for multi-part adjustedDuration = int(self.videoDuration / self.curVideo['multi_episode_count']) duration = adjustedDuration / 60 watchedPercent = ((self.watchedTime - (adjustedDuration * self.curMPEpisode)) / adjustedDuration) * 100 response = 'yep' if response != None: if self.curVideoInfo['tvdb_id'] is None: if 'status' in response and response['status'] == "success": if 'show' in response and 'tvdb_id' in response['show']: self.curVideoInfo['tvdb_id'] = response['show']['tvdb_id'] if 'id' in self.curVideo and utilities.getSettingAsBool('update_tvdb_id'): req = {"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetTVShowDetails", "params": {"tvshowid": self.curVideoInfo['tvshowid'], "imdbnumber": self.curVideoInfo['tvdb_id']}} utilities.xbmcJsonRequest(req) # get summary data now if we are rating this episode if utilities.getSettingAsBool('rate_episode') and self.traktSummaryInfo is None: self.traktSummaryInfo = self.traktapi.getEpisodeSummary(self.curVideoInfo['tvdb_id'], self.curVideoInfo['season'], self.curVideoInfo['episode']) Debug("[Scrobbler] Watch response: %s" % str(response)) match = utilities.getEpisodeDetailsFromXbmc(self.curMPEpisode, ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) else: match = utilities.getEpisodeDetailsFromXbmc(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) elif 'showtitle' in self.curVideoData and 'season' in self.curVideoData and 'episode' in self.curVideoData: match = {} match['tvdb_id'] = None match['year'] = None match['showtitle'] = self.curVideoData['showtitle'] match['season'] = self.curVideoData['season'] match['episode'] = self.curVideoData['episode'] match['uniqueid'] = None if match == None: return
def startedWatching(self): scrobbleMovieOption = __settings__.getSetting("scrobble_movie") scrobbleEpisodeOption = __settings__.getSetting("scrobble_episode") if self.curVideo['type'] == 'movie' and scrobbleMovieOption == 'true': match = None if 'id' in self.curVideo: match = utilities.getMovieDetailsFromXbmc(self.curVideo['id'], ['imdbnumber', 'title', 'year']) elif 'title' in self.curVideoData and 'year' in self.curVideoData: match = {} match['imdbnumber'] = '' match['title'] = self.curVideoData['title'] match['year'] = self.curVideoData['year'] if match == None: return response = utilities.watchingMovieOnTrakt(match['imdbnumber'], match['title'], match['year'], self.totalTime/60, int(100*self.watchedTime/self.totalTime)) if response != None: Debug("[Scrobbler] Watch response: "+str(response)) elif self.curVideo['type'] == 'episode' and scrobbleEpisodeOption == 'true': match = None if 'id' in self.curVideo: match = utilities.getEpisodeDetailsFromXbmc(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) elif 'showtitle' in self.curVideoData and 'season' in self.curVideoData and 'episode' in self.curVideoData: match = {} match['tvdb_id'] = None match['year'] = None match['showtitle'] = self.curVideoData['showtitle'] match['season'] = self.curVideoData['season'] match['episode'] = self.curVideoData['episode'] match['uniqueid'] = self.curVideoData['uniqueid']['unknown'] if match == None: return response = utilities.watchingEpisodeOnTrakt(match['tvdb_id'], match['showtitle'], match['year'], match['season'], match['episode'], match['uniqueid']['unknown'], self.totalTime/60, int(100*self.watchedTime/self.totalTime)) if response != None: Debug("[Scrobbler] Watch response: "+str(response))
def update(self, forceCheck = False): if not xbmc.Player().isPlayingVideo(): return if self.isPlaying: t = xbmc.Player().getTime() l = xbmc.PlayList(xbmc.PLAYLIST_VIDEO).getposition() if self.playlistIndex == l: self.watchedTime = t else: Debug("[Scrobbler] Current playlist item changed! Not updating time! (%d -> %d)" % (self.playlistIndex, l)) if 'id' in self.curVideo and self.isMultiPartEpisode: # do transition check every minute if (time.time() > (self.lastMPCheck + 60)) or forceCheck: self.lastMPCheck = time.time() watchedPercent = (self.watchedTime / self.videoDuration) * 100 epIndex = self._currentEpisode(watchedPercent, self.curVideo['multi_episode_count']) if self.curMPEpisode != epIndex: # current episode in multi-part episode has changed Debug("[Scrobbler] Attempting to scrobble episode part %d of %d." % (self.curMPEpisode + 1, self.curVideo['multi_episode_count'])) # recalculate watchedPercent and duration for multi-part, and scrobble adjustedDuration = int(self.videoDuration / self.curVideo['multi_episode_count']) duration = adjustedDuration / 60 watchedPercent = ((self.watchedTime - (adjustedDuration * self.curMPEpisode)) / adjustedDuration) * 100 response = self.traktapi.scrobbleEpisode(self.traktShowSummary, self.traktSummaryInfo, watchedPercent) if response != None: Debug("[Scrobbler] Scrobble response: %s" % str(response)) # update current information self.curMPEpisode = epIndex self.curVideoInfo = utilities.getEpisodeDetailsFromXbmc(self.curVideo['multi_episode_data'][self.curMPEpisode], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid'])
def update(self, forceCheck=False): if not xbmc.Player().isPlayingVideo(): return if self.isPlaying: t = xbmc.Player().getTime() l = xbmc.PlayList(xbmc.PLAYLIST_VIDEO).getposition() if self.playlistIndex == l: self.watchedTime = t else: Debug( "[Scrobbler] Current playlist item changed! Not updating time! (%d -> %d)" % (self.playlistIndex, l) ) if "id" in self.curVideo and self.isMultiPartEpisode: # do transition check every minute if (time.time() > (self.lastMPCheck + 60)) or forceCheck: self.lastMPCheck = time.time() watchedPercent = (self.watchedTime / self.videoDuration) * 100 epIndex = self._currentEpisode(watchedPercent, self.curVideo["multi_episode_count"]) if self.curMPEpisode != epIndex: # current episode in multi-part episode has changed Debug( "[Scrobbler] Attempting to scrobble episode part %d of %d." % (self.curMPEpisode + 1, self.curVideo["multi_episode_count"]) ) # recalculate watchedPercent and duration for multi-part, and scrobble adjustedDuration = int(self.videoDuration / self.curVideo["multi_episode_count"]) duration = adjustedDuration / 60 watchedPercent = ( (self.watchedTime - (adjustedDuration * self.curMPEpisode)) / adjustedDuration ) * 100 response = self.traktapi.scrobbleEpisode(self.curVideoInfo, duration, watchedPercent) if response != None: Debug("[Scrobbler] Scrobble response: %s" % str(response)) # update current information self.curMPEpisode = epIndex self.curVideoInfo = utilities.getEpisodeDetailsFromXbmc( self.curVideo["multi_episode_data"][self.curMPEpisode], ["showtitle", "season", "episode", "tvshowid", "uniqueid"], ) if not forceCheck: self.watching()
def scrobble(self): scrobbleMovieOption = __settings__.getSetting("scrobble_movie") scrobbleEpisodeOption = __settings__.getSetting("scrobble_episode") if self.curVideo['type'] == 'movie' and scrobbleMovieOption == 'true': match = None if 'id' in self.curVideo: match = utilities.getMovieDetailsFromXbmc( self.curVideo['id'], ['imdbnumber', 'title', 'year']) elif 'title' in self.curVideoData and 'year' in self.curVideoData: match = {} match['imdbnumber'] = '' match['title'] = self.curVideoData['title'] match['year'] = self.curVideoData['year'] if match == None: return response = utilities.scrobbleMovieOnTrakt( match['imdbnumber'], match['title'], match['year'], self.totalTime / 60, int(100 * self.watchedTime / self.totalTime)) if response != None: Debug("[Scrobbler] Scrobble response: " + str(response)) elif self.curVideo[ 'type'] == 'episode' and scrobbleEpisodeOption == 'true': match = None if 'id' in self.curVideo: match = utilities.getEpisodeDetailsFromXbmc( self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) elif 'showtitle' in self.curVideoData and 'season' in self.curVideoData and 'episode' in self.curVideoData: match = {} match['tvdb_id'] = None match['year'] = None match['showtitle'] = self.curVideoData['showtitle'] match['season'] = self.curVideoData['season'] match['episode'] = self.curVideoData['episode'] match['uniqueid'] = self.curVideoData['uniqueid']['unknown'] if match == None: return response = utilities.scrobbleEpisodeOnTrakt( match['tvdb_id'], match['showtitle'], match['year'], match['season'], match['episode'], match['uniqueid']['unknown'], self.totalTime / 60, int(100 * self.watchedTime / self.totalTime)) if response != None: Debug("[Scrobbler] Scrobble response: " + str(response))
def _scrobble(self): scrobble_movies = __settings__.getSetting("scrobble_movie") scrobble_episodes = __settings__.getSetting("scrobble_episode") if self._current_video['type'] == 'movie' and scrobble_movies == 'true': match = utilities.getMovieDetailsFromXbmc(self._current_video['id'], ['imdbnumber', 'title', 'year']) if match == None: return response = utilities.scrobbleMovieOnTrakt(match['imdbnumber'], match['title'], match['year'], self._total_time/60, int(100*self._watched_time/self._total_time)) if response != None: Debug("[Scrobbler] Scrobble responce: "+str(response)) elif self._current_video['type'] == 'episode' and scrobble_episodes == 'true': match = utilities.getEpisodeDetailsFromXbmc(self._current_video['id'], ['showtitle', 'season', 'episode']) if match == None: return response = utilities.scrobbleEpisodeOnTrakt(None, match['showtitle'], None, match['season'], match['episode'], self._total_time/60, int(100*self._watched_time/self._total_time)) if response != None: Debug("[Scrobbler] Scrobble responce: "+str(response))
def rate_episode(episode_id): """Launches the episode rating dialogue""" match = utilities.getEpisodeDetailsFromXbmc(episode_id, ['showtitle', 'season', 'episode']) if not match: #add error message here return tvdbid = None #match['tvdbnumber'] title = match['showtitle'] year = None #match['year'] season = match['season'] episode = match['episode'] if utilities.getTraktRatingType() == "advanced": gui = windows.RateEpisodeDialog("rate_advanced.xml", __settings__.getAddonInfo('path')) else: gui = windows.RateEpisodeDialog("rate.xml", __settings__.getAddonInfo('path')) gui.initDialog(tvdbid, title, year, season, episode, utilities.getEpisodeRatingFromTrakt(tvdbid, title, year, season, episode)) gui.doModal() del gui
def _started_watching(self): scrobble_movies = __settings__.getSetting("scrobble_movie") scrobble_episodes = __settings__.getSetting("scrobble_episode") Debug('[Scrobbler] Started watching') if self._current_video['type'] == 'movie' and scrobble_movies == 'true': match = utilities.getMovieDetailsFromXbmc(self._current_video['id'], ['imdbnumber', 'title', 'year']) if match == None: return response = utilities.watchingMovieOnTrakt(match['imdbnumber'], match['title'], match['year'], self._total_time/60, int(100*self._watched_time/self._total_time)) if response != None: Debug("[Scrobbler] Watch response: "+str(response)) elif self._current_video['type'] == 'episode' and scrobble_episodes == 'true': match = utilities.getEpisodeDetailsFromXbmc(self._current_video['id'], ['tvshowid', 'showtitle', 'season', 'episode']) if match == None: return tvshowdetails = utilities.getTVShowDetailsFromXBMC(match['tvshowid'], ['title', 'year', 'imdbnumber']) Debug("[Scrobbler] TVShowDetails in _started_watching: "+str(tvshowdetails)) response = utilities.watchingEpisodeOnTrakt(tvshowdetails['imdbnumber'], match['showtitle'], None, match['season'], match['episode'], self._total_time/60, int(100*self._watched_time/self._total_time)) if response != None: Debug("[Scrobbler] Watch responce: "+str(response))
def playbackStarted(self, data): Debug("[Scrobbler] playbackStarted(data: %s)" % data) if not data: return self.curVideo = data self.curVideoInfo = None # {"jsonrpc":"2.0","method":"Player.OnPlay","params":{"data":{"item":{"type":"movie"},"player":{"playerid":1,"speed":1},"title":"Shooter","year":2007},"sender":"xbmc"}} # {"jsonrpc":"2.0","method":"Player.OnPlay","params":{"data":{"episode":3,"item":{"type":"episode"},"player":{"playerid":1,"speed":1},"season":4,"showtitle":"24","title":"9:00 A.M. - 10:00 A.M."},"sender":"xbmc"}} if 'type' in self.curVideo: Debug("[Scrobbler] Watching: %s" % self.curVideo['type']) if not xbmc.Player().isPlayingVideo(): Debug("[Scrobbler] Suddenly stopped watching item") return xbmc.sleep( 1000) # Wait for possible silent seek (caused by resuming) try: self.watchedTime = xbmc.Player().getTime() self.videoDuration = xbmc.Player().getTotalTime() except Exception, e: Debug("[Scrobbler] Suddenly stopped watching item: %s" % e.message) self.curVideo = None return if self.videoDuration == 0: if utilities.isMovie(self.curVideo['type']): self.videoDuration = 90 elif utilities.isEpisode(self.curVideo['type']): self.videoDuration = 30 else: self.videoDuration = 1 self.playlistLength = len(xbmc.PlayList(xbmc.PLAYLIST_VIDEO)) self.playlistIndex = xbmc.PlayList( xbmc.PLAYLIST_VIDEO).getposition() if (self.playlistLength == 0): Debug( "[Scrobbler] Warning: Cant find playlist length, assuming that this item is by itself" ) self.playlistLength = 1 self.traktSummaryInfo = None self.isMultiPartEpisode = False if utilities.isMovie(self.curVideo['type']): if 'id' in self.curVideo: self.curVideoInfo = utilities.getMovieDetailsFromXbmc( self.curVideo['id'], ['imdbnumber', 'title', 'year']) if utilities.getSettingAsBool('rate_movie'): # pre-get sumamry information, for faster rating dialog. Debug( "[Scrobbler] Movie rating is enabled, pre-fetching summary information." ) imdb_id = self.curVideoInfo['imdbnumber'] if imdb_id.startswith("tt") or imdb_id.isdigit(): self.traktSummaryInfo = self.traktapi.getMovieSummary( self.curVideoInfo['imdbnumber']) self.traktSummaryInfo['xbmc_id'] = self.curVideo[ 'id'] else: self.curVideoInfo['imdbnumber'] = None Debug( "[Scrobbler] Can not get summary information for '%s (%d)' as is has no valid id, will retry during a watching call." % (self.curVideoInfo['title'], self.curVideoInfo['year'])) elif 'title' in self.curVideo and 'year' in self.curVideo: self.curVideoInfo = {} self.curVideoInfo['imdbnumber'] = None self.curVideoInfo['title'] = self.curVideo['title'] self.curVideoInfo['year'] = self.curVideo['year'] elif utilities.isEpisode(self.curVideo['type']): if 'id' in self.curVideo: self.curVideoInfo = utilities.getEpisodeDetailsFromXbmc( self.curVideo['id'], [ 'showtitle', 'season', 'episode', 'tvshowid', 'uniqueid' ]) if not self.curVideoInfo: # getEpisodeDetailsFromXbmc was empty Debug( "[Scrobbler] Episode details from XBMC was empty, ID (%d) seems invalid, aborting further scrobbling of this episode." % self.curVideo['id']) self.curVideo = None self.isPlaying = False self.watchedTime = 0 return if utilities.getSettingAsBool('rate_episode'): # pre-get sumamry information, for faster rating dialog. Debug( "[Scrobbler] Episode rating is enabled, pre-fetching summary information." ) tvdb_id = self.curVideoInfo['tvdb_id'] if tvdb_id.isdigit() or tvdb_id.startswith("tt"): self.traktSummaryInfo = self.traktapi.getEpisodeSummary( tvdb_id, self.curVideoInfo['season'], self.curVideoInfo['episode']) else: self.curVideoInfo['tvdb_id'] = None Debug( "[Scrobbler] Can not get summary information for '%s - S%02dE%02d' as it has no valid id, will retry during a watching call." % (self.curVideoInfo['showtitle'], self.curVideoInfo['season'], self.curVideoInfo['episode'])) elif 'showtitle' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo: self.curVideoInfo = {} self.curVideoInfo['tvdb_id'] = None self.curVideoInfo['year'] = None if 'year' in self.curVideo: self.curVideoInfo['year'] = self.curVideo['year'] self.curVideoInfo['showtitle'] = self.curVideo['showtitle'] self.curVideoInfo['season'] = self.curVideo['season'] self.curVideoInfo['episode'] = self.curVideo['episode'] if 'multi_episode_count' in self.curVideo: self.isMultiPartEpisode = True self.markedAsWatched = [] episode_count = self.curVideo['multi_episode_count'] for i in range(episode_count): self.markedAsWatched.append(False) self.isPlaying = True self.isPaused = False self.scrobble('start')
def playbackStarted(self, data): Debug("[Scrobbler] playbackStarted(data: %s)" % data) if not data: return self.curVideo = data self.curVideoInfo = None # {"jsonrpc":"2.0","method":"Player.OnPlay","params":{"data":{"item":{"type":"movie"},"player":{"playerid":1,"speed":1},"title":"Shooter","year":2007},"sender":"xbmc"}} # {"jsonrpc":"2.0","method":"Player.OnPlay","params":{"data":{"episode":3,"item":{"type":"episode"},"player":{"playerid":1,"speed":1},"season":4,"showtitle":"24","title":"9:00 A.M. - 10:00 A.M."},"sender":"xbmc"}} if 'type' in self.curVideo: Debug("[Scrobbler] Watching: %s" % self.curVideo['type']) if not xbmc.Player().isPlayingVideo(): Debug("[Scrobbler] Suddenly stopped watching item") return xbmc.sleep(1000) # Wait for possible silent seek (caused by resuming) try: self.watchedTime = xbmc.Player().getTime() self.videoDuration = xbmc.Player().getTotalTime() except Exception, e: Debug("[Scrobbler] Suddenly stopped watching item: %s" % e.message) self.curVideo = None return if self.videoDuration == 0: if utilities.isMovie(self.curVideo['type']): self.videoDuration = 90 elif utilities.isEpisode(self.curVideo['type']): self.videoDuration = 30 else: self.videoDuration = 1 self.playlistLength = len(xbmc.PlayList(xbmc.PLAYLIST_VIDEO)) self.playlistIndex = xbmc.PlayList(xbmc.PLAYLIST_VIDEO).getposition() if (self.playlistLength == 0): Debug("[Scrobbler] Warning: Cant find playlist length, assuming that this item is by itself") self.playlistLength = 1 self.traktSummaryInfo = None self.isMultiPartEpisode = False if utilities.isMovie(self.curVideo['type']): if 'id' in self.curVideo: self.curVideoInfo = utilities.getMovieDetailsFromXbmc(self.curVideo['id'], ['imdbnumber', 'title', 'year']) if utilities.getSettingAsBool('rate_movie'): # pre-get sumamry information, for faster rating dialog. Debug("[Scrobbler] Movie rating is enabled, pre-fetching summary information.") imdb_id = self.curVideoInfo['imdbnumber'] if imdb_id.startswith("tt") or imdb_id.isdigit(): self.traktSummaryInfo = self.traktapi.getMovieSummary(self.curVideoInfo['imdbnumber']) self.traktSummaryInfo['xbmc_id'] = self.curVideo['id'] else: self.curVideoInfo['imdbnumber'] = None Debug("[Scrobbler] Can not get summary information for '%s (%d)' as is has no valid id, will retry during a watching call." % (self.curVideoInfo['title'], self.curVideoInfo['year'])) elif 'title' in self.curVideo and 'year' in self.curVideo: self.curVideoInfo = {} self.curVideoInfo['imdbnumber'] = None self.curVideoInfo['title'] = self.curVideo['title'] self.curVideoInfo['year'] = self.curVideo['year'] elif utilities.isEpisode(self.curVideo['type']): if 'id' in self.curVideo: self.curVideoInfo = utilities.getEpisodeDetailsFromXbmc(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) if utilities.getSettingAsBool('rate_episode'): # pre-get sumamry information, for faster rating dialog. Debug("[Scrobbler] Episode rating is enabled, pre-fetching summary information.") tvdb_id = self.curVideoInfo['tvdb_id'] if tvdb_id.isdigit() or tvdb_id.startswith("tt"): self.traktSummaryInfo = self.traktapi.getEpisodeSummary(tvdb_id, self.curVideoInfo['season'], self.curVideoInfo['episode']) else: self.curVideoInfo['tvdb_id'] = None Debug("[Scrobbler] Can not get summary information for '%s - S%02dE%02d' as it has no valid id, will retry during a watching call." % (self.curVideoInfo['showtitle'], self.curVideoInfo['season'], self.curVideoInfo['episode'])) elif 'showtitle' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo: self.curVideoInfo = {} self.curVideoInfo['tvdb_id'] = None self.curVideoInfo['year'] = None if 'year' in self.curVideo: self.curVideoInfo['year'] = self.curVideo['year'] self.curVideoInfo['showtitle'] = self.curVideo['showtitle'] self.curVideoInfo['season'] = self.curVideo['season'] self.curVideoInfo['episode'] = self.curVideo['episode'] if 'multi_episode_count' in self.curVideo: self.isMultiPartEpisode = True self.markedAsWatched = [] episode_count = self.curVideo['multi_episode_count'] for i in range(episode_count): self.markedAsWatched.append(False) self.isPlaying = True self.isPaused = False self.watching()
def startedWatching(self): scrobbleMovieOption = __settings__.getSetting("scrobble_movie") scrobbleEpisodeOption = __settings__.getSetting("scrobble_episode") ExcludeLiveTV = __settings__.getSetting("ExcludeLiveTV") ExcludeHTTP = __settings__.getSetting("ExcludeHTTP") ExcludePathOption = __settings__.getSetting("ExcludePathOption") ExcludePathOption2 = __settings__.getSetting("ExcludePathOption2") ExcludePathOption3 = __settings__.getSetting("ExcludePathOption3") ExcludePath = __settings__.getSetting("ExcludePath") ExcludePath2 = __settings__.getSetting("ExcludePath2") ExcludePath3 = __settings__.getSetting("ExcludePath3") LiveTVExcluded = False HTTPExcluded = False PathExcluded = False currentPath = xbmc.Player().getPlayingFile() if (currentPath.find("pvr://") > -1) and ExcludeLiveTV == 'true': Debug("Video is playing via Live TV, which is currently set as excluded location.", False) LiveTVExcluded = True if (currentPath.find("http://") > -1) and ExcludeHTTP == 'true': Debug("Video is playing via HTTP source, which is currently set as excluded location.", False) HTTPExcluded = True if ExcludePath != "" and ExcludePathOption == 'true': if (currentPath.find(ExcludePath) > -1): Debug('Video is playing from location, which is currently set as excluded path 1.', False) PathExcluded = True if ExcludePath2 != "" and ExcludePathOption2 == 'true': currentPath = xbmc.Player().getPlayingFile() if (currentPath.find(ExcludePath2) > -1): Debug('Video is playing from location, which is currently set as excluded path 2.', False) PathExcluded = True if ExcludePath3 != "" and ExcludePathOption3 == 'true': currentPath = xbmc.Player().getPlayingFile() if (currentPath.find(ExcludePath3) > -1): Debug('Video is playing from location, which is currently set as excluded path 3.', False) PathExcluded = True if (LiveTVExcluded or HTTPExcluded or PathExcluded): self.VideoExcluded = True Debug("Video from excluded location was detected. No scrobbling!", False) if self.curVideo['type'] == 'movie' and scrobbleMovieOption == 'true' and not self.VideoExcluded: match = None if 'id' in self.curVideo: match = utilities.getMovieDetailsFromXbmc(self.curVideo['id'], ['imdbnumber', 'title', 'year']) elif 'title' in self.curVideoData and 'year' in self.curVideoData: match = {} match['imdbnumber'] = '' match['title'] = self.curVideoData['title'] match['year'] = self.curVideoData['year'] if match == None: return response = utilities.watchingMovieOnTrakt(match['imdbnumber'], match['title'], match['year'], self.totalTime/60, int(100*self.watchedTime/self.totalTime)) if response != None: Debug("[Scrobbler] Watch response: "+str(response)) elif self.curVideo['type'] == 'episode' and scrobbleEpisodeOption == 'true' and not self.VideoExcluded: match = None if 'id' in self.curVideo: match = utilities.getEpisodeDetailsFromXbmc(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) elif 'showtitle' in self.curVideoData and 'season' in self.curVideoData and 'episode' in self.curVideoData: match = {} match['tvdb_id'] = None match['year'] = None match['showtitle'] = self.curVideoData['showtitle'] match['season'] = self.curVideoData['season'] match['episode'] = self.curVideoData['episode'] match['uniqueid'] = self.curVideoData['uniqueid']['unknown'] if match == None: return response = utilities.watchingEpisodeOnTrakt(match['tvdb_id'], match['showtitle'], match['year'], match['season'], match['episode'], match['uniqueid']['unknown'], self.totalTime/60, int(100*self.watchedTime/self.totalTime)) if response != None: Debug("[Scrobbler] Watch response: "+str(response))
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"] == "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 scrobble(self): Debug("[Scrobbler] self.curVideo:" + unicode(self.curVideo)) Debug("[Scrobbler] self.curVideoData" + unicode(self.curVideoData)) if self.curVideo['type']=="episode": match = None if 'id' in self.curVideo: #if self.curVideo.has_key("multi_episode_count"): #cur_episode = self._currentEpisode((self.watchedTime / self.totalTime) * 100, self.curVideo['multi_episode_count']) # cur_episode = self.curVideo['multi_episode_count'] - 1 # Debug("[Scrobbler] Multi-part episode, scrobbling part %d of %d." % (cur_episode + 1, self.curVideo['multi_episode_count'])) # match = utilities.getEpisodeDetailsFromXbmc(self.curVideo["multi_episode_data"][cur_episode], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid']) #else: match = utilities.getEpisodeDetailsFromXbmc(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid', 'file']) elif 'showtitle' in self.curVideoData and 'season' in self.curVideoData and 'episode' in self.curVideoData: match = {} match['tvdb_id'] = None match['year'] = None match['showtitle'] = self.curVideoData['showtitle'] match['season'] = self.curVideoData['season'] match['episode'] = self.curVideoData['episode'] match['uniqueid'] = self.curVideoData['uniqueid']['unknown'] elif 'label' in self.curVideo and len(self.curVideo['label']) > 0: match = {} match['label'] = self.curVideo['label'] if match == None: return duration = self.totalTime / 60 watchedPercent = int((self.watchedTime / self.totalTime) * 100) Debug("[Scrobbler] Match for MyShows.ru Plugin: " + str(match)) xbmc.executebuiltin( 'xbmc.RunPlugin("plugin://plugin.video.myshows/?mode=70&action=check&title=' + urllib.quote_plus( json.dumps(match)) + '")') #response = self.myshowsapi.scrobbleEpisode(match['tvdb_id'], match['showtitle'], match['year'], match['season'], match['episode'], match['uniqueid']['unknown'], duration, watchedPercent) #if response != None: #Debug("[Scrobbler] Scrobble response: "+str(response)) elif self.curVideo['type']=="movie": if len(self.curVideo['title'])<1: Debug("[Scrobbler] No title, stop scrobbing.") else: import kp from rating import rateMedia login=get_string_setting('login') password=get_string_setting('password') cookie=get_string_setting('cookie') if cookie=='': cookie=None if login!='' and password!='': kpLogin=kp.Login(login,password,cookie) else: Debug("No login or password!") if not cookie or not kpLogin.testAcc(): try: set_string_setting('cookie', kpLogin.get_cookie()) except: rateMedia(self.curVideo['type'], self.curVideo, offline=True) return if get_string_setting('cookie'): rateMedia(self.curVideo['type'], self.curVideo) self.curVideo = None
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'] == '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)