Beispiel #1
0
    def transitionCheck(self, isSeek=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:
                logger.debug("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 isSeek:
                    self.lastMPCheck = time.time()
                    watchedPercent = self.__calculateWatchedPercent()
                    epIndex = self._currentEpisode(watchedPercent, self.curVideo['multi_episode_count'])
                    if self.curMPEpisode != epIndex:
                        response = self.__scrobble('stop')
                        if response is not None:
                            logger.debug("Scrobble response: %s" % str(response))
                            self.videosToRate.append(self.curVideoInfo)
                            # update current information
                            self.curMPEpisode = epIndex
                            self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('episode', utilities.getEpisodeDetailsFromKodi(self.curVideo['multi_episode_data'][self.curMPEpisode], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid', 'file', 'playcount']))

                            logger.debug("Multi episode transition - call start for next episode")
                            response = self.__scrobble('start')
                            self.__preFetchUserRatings(response)
            elif isSeek:
                self.__scrobble('start')
Beispiel #2
0
    def transitionCheck(self, isSeek=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:
                logger.debug("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 isSeek:
                    self.lastMPCheck = time.time()
                    watchedPercent = self.__calculateWatchedPercent()
                    epIndex = self._currentEpisode(watchedPercent, self.curVideo['multi_episode_count'])
                    if self.curMPEpisode != epIndex:
                        response = self.__scrobble('stop')
                        if response is not None:
                            logger.debug("Scrobble response: %s" % str(response))
                            self.videosToRate.append(self.curVideoInfo)
                            # update current information
                            self.curMPEpisode = epIndex
                            self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('episode', utilities.getEpisodeDetailsFromKodi(self.curVideo['multi_episode_data'][self.curMPEpisode], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid', 'file', 'playcount']))

                            logger.debug("Multi episode transition - call start for next episode")
                            response = self.__scrobble('start')
                            self.__preFetchUserRatings(response)
            elif isSeek:
                self.__scrobble('start')
Beispiel #3
0
	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:
				logger.debug("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.__calculateWatchedPercent()
					epIndex = self._currentEpisode(watchedPercent, self.curVideo['multi_episode_count'])
					if self.curMPEpisode != epIndex:
						# current episode in multi-part episode has changed
						logger.debug("Attempting to stop 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'])
						watchedPercent = ((self.watchedTime - (adjustedDuration * self.curMPEpisode)) / adjustedDuration) * 100
						response = self.traktapi.scrobbleEpisode(self.traktShowSummary, self.curVideoInfo, watchedPercent, 'stop')
						if response is not None:
							logger.debug("Scrobble response: %s" % str(response))

						# update current information
						self.curMPEpisode = epIndex
						self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('episode', utilities.getEpisodeDetailsFromKodi(self.curVideo['multi_episode_data'][self.curMPEpisode], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid', 'file', 'playcount']))

						if not forceCheck:
							logger.debug("Attempting to start scrobble episode part %d of %d." % (self.curMPEpisode + 1, self.curVideo['multi_episode_count']))
							response = self.traktapi.scrobbleEpisode(self.traktShowSummary, self.curVideoInfo, 0, 'start')
							if response is not None:
								logger.debug("Scrobble response: %s" % str(response))
    def playbackStarted(self, data):
        logger.debug("playbackStarted(data: %s)" % data)
        if not data:
            return
        self.curVideo = data
        self.curVideoInfo = None
        self.videosToRate = []

        if (
            not utilities.getSettingAsBool("scrobble_fallback")
            and "id" not in self.curVideo
            and "video_ids" not in self.curVideo
        ):
            logger.debug("Aborting scrobble to avoid fallback: %s" % (self.curVideo))
            return

        if "type" in self.curVideo:
            logger.debug("Watching: %s" % self.curVideo["type"])
            if not xbmc.Player().isPlayingVideo():
                logger.debug("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 as e:
                logger.debug("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:
                logger.debug("Warning: Cant find playlist length, assuming that this item is by itself")
                self.playlistLength = 1

            self.isMultiPartEpisode = False
            if utilities.isMovie(self.curVideo["type"]):
                if "id" in self.curVideo:
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject(
                        "movie",
                        utilities.getMovieDetailsFromKodi(
                            self.curVideo["id"], ["imdbnumber", "title", "year", "file", "lastplayed", "playcount"]
                        ),
                    )
                elif "video_ids" in self.curVideo:
                    self.curVideoInfo = {"ids": self.curVideo["video_ids"]}
                elif "title" in self.curVideo and "year" in self.curVideo:
                    self.curVideoInfo = {"title": self.curVideo["title"], "year": self.curVideo["year"]}

            elif utilities.isEpisode(self.curVideo["type"]):
                if "id" in self.curVideo:
                    episodeDetailsKodi = utilities.getEpisodeDetailsFromKodi(
                        self.curVideo["id"],
                        ["showtitle", "season", "episode", "tvshowid", "uniqueid", "file", "playcount"],
                    )
                    tvdb = episodeDetailsKodi["imdbnumber"]
                    title, year = utilities.regex_year(episodeDetailsKodi["showtitle"])
                    if not year:
                        self.traktShowSummary = {
                            "title": episodeDetailsKodi["showtitle"],
                            "year": episodeDetailsKodi["year"],
                        }
                    else:
                        self.traktShowSummary = {"title": title, "year": year}
                    if tvdb:
                        self.traktShowSummary["ids"] = {"tvdb": tvdb}
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject("episode", episodeDetailsKodi)
                    if not self.curVideoInfo:  # getEpisodeDetailsFromKodi was empty
                        logger.debug(
                            "Episode details from Kodi 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
                elif "video_ids" in self.curVideo and "season" in self.curVideo and "episode" in self.curVideo:
                    self.curVideoInfo = {"season": self.curVideo["season"], "number": self.curVideo["episode"]}
                    self.traktShowSummary = {"ids": self.curVideo["video_ids"]}
                elif "title" in self.curVideo and "season" in self.curVideo and "episode" in self.curVideo:
                    self.curVideoInfo = {
                        "title": self.curVideo["title"],
                        "season": self.curVideo["season"],
                        "number": self.curVideo["episode"],
                    }

                    title, year = utilities.regex_year(self.curVideo["showtitle"])
                    if not year:
                        self.traktShowSummary = {"title": self.curVideo["showtitle"]}
                    else:
                        self.traktShowSummary = {"title": title, "year": year}

                    if "year" in self.curVideo:
                        self.traktShowSummary["year"] = self.curVideo["year"]

                if "multi_episode_count" in self.curVideo and self.curVideo["multi_episode_count"] > 1:
                    self.isMultiPartEpisode = True

            self.isPlaying = True
            self.isPaused = False

            result = {}
            if utilities.getSettingAsBool("scrobble_movie") or utilities.getSettingAsBool("scrobble_episode"):
                result = self.__scrobble("start")
            elif (
                utilities.getSettingAsBool("rate_movie")
                and utilities.isMovie(self.curVideo["type"])
                and "ids" in self.curVideoInfo
            ):
                result = {"movie": self.traktapi.getMovieSummary(utilities.best_id(self.curVideoInfo["ids"])).to_dict()}
            elif (
                utilities.getSettingAsBool("rate_episode")
                and utilities.isEpisode(self.curVideo["type"])
                and "ids" in self.traktShowSummary
            ):
                best_id = utilities.best_id(self.traktShowSummary["ids"])
                result = {
                    "show": self.traktapi.getShowSummary(best_id).to_dict(),
                    "episode": self.traktapi.getEpisodeSummary(
                        best_id, self.curVideoInfo["season"], self.curVideoInfo["number"]
                    ).to_dict(),
                }
                result["episode"]["season"] = self.curVideoInfo["season"]

            self.__preFetchUserRatings(result)
Beispiel #5
0
    def playbackStarted(self, data):
        logger.debug("playbackStarted(data: %s)" % data)
        if not data:
            return
        self.curVideo = data
        self.curVideoInfo = None
        self.videosToRate = []

        if not utilities.getSettingAsBool('scrobble_fallback') and 'id' not in self.curVideo and 'video_ids' not in self.curVideo:
            logger.debug('Aborting scrobble to avoid fallback: %s' % (self.curVideo))
            return
             
        if 'type' in self.curVideo:
            logger.debug("Watching: %s" % self.curVideo['type'])
            if not xbmc.Player().isPlayingVideo():
                logger.debug("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 as e:
                logger.debug("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:
                logger.debug("Warning: Cant find playlist length, assuming that this item is by itself")
                self.playlistLength = 1

            self.isMultiPartEpisode = False
            if utilities.isMovie(self.curVideo['type']):
                if 'id' in self.curVideo:
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('movie', utilities.getMovieDetailsFromKodi(self.curVideo['id'], ['imdbnumber', 'title', 'year', 'file', 'lastplayed', 'playcount']))
                elif 'video_ids' in self.curVideo:
                    self.curVideoInfo = {'ids': self.curVideo['video_ids']}
                elif 'title' in self.curVideo and 'year' in self.curVideo:
                    self.curVideoInfo = {'title': self.curVideo['title'], 'year': self.curVideo['year']}

            elif utilities.isEpisode(self.curVideo['type']):
                if 'id' in self.curVideo:
                    episodeDetailsKodi = utilities.getEpisodeDetailsFromKodi(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid', 'file', 'playcount'])
                    tvdb = episodeDetailsKodi['imdbnumber']
                    title, year = utilities.regex_year(episodeDetailsKodi['showtitle'])
                    if not year:
                        self.traktShowSummary = {'title': episodeDetailsKodi['showtitle'], 'year': episodeDetailsKodi['year']}
                    else:
                        self.traktShowSummary = {'title': title, 'year': year}
                    if tvdb:
                        self.traktShowSummary['ids'] = {'tvdb': tvdb}
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('episode', episodeDetailsKodi)
                    if not self.curVideoInfo:  # getEpisodeDetailsFromKodi was empty
                        logger.debug("Episode details from Kodi 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
                elif 'video_ids' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo:
                    self.curVideoInfo = {'season': self.curVideo['season'], 'number': self.curVideo['episode']}
                    self.traktShowSummary = {'ids': self.curVideo['video_ids']}
                elif 'title' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo:
                    self.curVideoInfo = {'title': self.curVideo['title'], 'season': self.curVideo['season'],
                                         'number': self.curVideo['episode']}

                    title, year = utilities.regex_year(self.curVideo['showtitle'])
                    if not year:
                        self.traktShowSummary = {'title': self.curVideo['showtitle']}
                    else:
                        self.traktShowSummary = {'title': title, 'year': year}

                    if 'year' in self.curVideo:
                        self.traktShowSummary['year'] = self.curVideo['year']

                if 'multi_episode_count' in self.curVideo and self.curVideo['multi_episode_count'] > 1:
                    self.isMultiPartEpisode = True

            self.isPlaying = True
            self.isPaused = False

            result = {}
            if utilities.getSettingAsBool('scrobble_movie') or utilities.getSettingAsBool('scrobble_episode'):
                result = self.__scrobble('start')
            elif utilities.getSettingAsBool('rate_movie') and utilities.isMovie(self.curVideo['type']) and 'ids' in self.curVideoInfo:
                best_id = utilities.best_id(self.curVideoInfo['ids'])
                result = {'movie': self.traktapi.getMovieSummary(best_id).to_dict()}
                if 'id' in self.curVideo: result['movie']['movieid'] = self.curVideo['id']
            elif utilities.getSettingAsBool('rate_episode') and utilities.isEpisode(self.curVideo['type']) and 'ids' in self.traktShowSummary:
                best_id = utilities.best_id(self.traktShowSummary['ids'])
                result = {'show': self.traktapi.getShowSummary(best_id).to_dict(),
                          'episode': self.traktapi.getEpisodeSummary(best_id, self.curVideoInfo['season'],
                                                                     self.curVideoInfo['number']).to_dict()}
                result['episode']['season'] = self.curVideoInfo['season']
                if 'id' in self.curVideo: result['episode']['episodeid'] = self.curVideo['id']

            self.__preFetchUserRatings(result)
Beispiel #6
0
	def playbackStarted(self, data):
		logger.debug("playbackStarted(data: %s)" % data)
		if not data:
			return
		self.curVideo = data
		self.curVideoInfo = None

		if 'type' in self.curVideo:
			logger.debug("Watching: %s" % self.curVideo['type'])
			if not xbmc.Player().isPlayingVideo():
				logger.debug("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 as e:
				logger.debug("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:
				logger.debug("Warning: Cant find playlist length, assuming that this item is by itself")
				self.playlistLength = 1

			self.isMultiPartEpisode = False
			if utilities.isMovie(self.curVideo['type']):
				if 'id' in self.curVideo:
					self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('movie', utilities.getMovieDetailsFromKodi(self.curVideo['id'], ['imdbnumber', 'title', 'year', 'file', 'lastplayed', 'playcount']))
				elif 'title' in self.curVideo and 'year' in self.curVideo:
					self.curVideoInfo = {'title': self.curVideo['title'], 'year': self.curVideo['year']}

			elif utilities.isEpisode(self.curVideo['type']):
				if 'id' in self.curVideo:
					episodeDetailsKodi = utilities.getEpisodeDetailsFromKodi(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid', 'file', 'playcount'])
					tvdb = episodeDetailsKodi['imdbnumber']
					title, year = utilities.regex_year(episodeDetailsKodi['showtitle'])
					if not year:
						self.traktShowSummary = {'title': episodeDetailsKodi['showtitle'], 'year': episodeDetailsKodi['year']}
					else:
						self.traktShowSummary = {'title': title, 'year': year}
					if tvdb:
						self.traktShowSummary['ids'] = {'tvdb': tvdb}
					self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('episode', episodeDetailsKodi)
					if not self.curVideoInfo: # getEpisodeDetailsFromKodi was empty
						logger.debug("Episode details from Kodi 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
				elif 'title' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo:
					self.curVideoInfo = {'title': self.curVideo['title'], 'season': self.curVideo['season'],
					                     'number': self.curVideo['episode']}

					title, year = utilities.regex_year(self.curVideo['showtitle'])
					if not year:
						self.traktShowSummary = {'title': self.curVideo['showtitle']}
					else:
						self.traktShowSummary = {'title': title, 'year': year}

					if 'year' in self.curVideo:
						self.traktShowSummary['year'] = self.curVideo['year']

				if 'multi_episode_count' in self.curVideo:
					self.isMultiPartEpisode = True

			self.isPlaying = True
			self.isPaused = False
			result = self.__scrobble('start')
			if result:
				if utilities.isMovie(self.curVideo['type']) and utilities.getSettingAsBool('rate_movie'):
					# pre-get sumamry information, for faster rating dialog.
					logger.debug("Movie rating is enabled, pre-fetching summary information.")
					if result['movie']['ids']['imdb']:
						self.curVideoInfo['user'] = {'ratings': self.traktapi.getMovieRatingForUser(result['movie']['ids']['imdb'])}
						self.curVideoInfo['ids'] = result['movie']['ids']
					else:
						logger.debug("'%s (%d)' has no valid id, can't get rating." % (self.curVideoInfo['title'], self.curVideoInfo['year']))
				elif utilities.isEpisode(self.curVideo['type']) and utilities.getSettingAsBool('rate_episode'):
					# pre-get sumamry information, for faster rating dialog.
					logger.debug("Episode rating is enabled, pre-fetching summary information.")

					if result['show']['ids']['tvdb']:
						self.curVideoInfo['user'] = {'ratings' : self.traktapi.getEpisodeRatingForUser(result['show']['ids']['tvdb'], self.curVideoInfo['season'], self.curVideoInfo['number'])}
						self.curVideoInfo['ids'] = result['episode']['ids']
					else:
						logger.debug("'%s - S%02dE%02d' has no valid id, can't get rating." % (self.curVideoInfo['showtitle'], self.curVideoInfo['season'], self.curVideoInfo['episode']))
Beispiel #7
0
    def playbackStarted(self, data):
        logger.debug("playbackStarted(data: %s)" % data)
        if not data:
            return
        self.curVideo = data
        self.curVideoInfo = None
        self.videosToRate = []

        if not utilities.getSettingAsBool('scrobble_fallback') and 'id' not in self.curVideo and 'video_ids' not in self.curVideo:
            logger.debug('Aborting scrobble to avoid fallback: %s' % (self.curVideo))
            return
             
        if 'type' in self.curVideo:
            logger.debug("Watching: %s" % self.curVideo['type'])
            if not xbmc.Player().isPlayingVideo():
                logger.debug("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 as e:
                logger.debug("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:
                logger.debug("Warning: Cant find playlist length, assuming that this item is by itself")
                self.playlistLength = 1

            self.isMultiPartEpisode = False
            if utilities.isMovie(self.curVideo['type']):
                if 'id' in self.curVideo:
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('movie', utilities.getMovieDetailsFromKodi(self.curVideo['id'], ['imdbnumber', 'title', 'year', 'file', 'lastplayed', 'playcount']))
                elif 'video_ids' in self.curVideo:
                    self.curVideoInfo = {'ids': self.curVideo['video_ids'], 'title': self.curVideo['title'], 'year': self.curVideo['year']}
                elif 'title' in self.curVideo and 'year' in self.curVideo:
                    self.curVideoInfo = {'title': self.curVideo['title'], 'year': self.curVideo['year']}

            elif utilities.isEpisode(self.curVideo['type']):
                if 'id' in self.curVideo:
                    episodeDetailsKodi = utilities.getEpisodeDetailsFromKodi(self.curVideo['id'], ['showtitle', 'season', 'episode', 'tvshowid', 'uniqueid', 'file', 'playcount'])
                    tvdb = episodeDetailsKodi['imdbnumber']
                    title, year = utilities.regex_year(episodeDetailsKodi['showtitle'])
                    if not year:
                        self.traktShowSummary = {'title': episodeDetailsKodi['showtitle'], 'year': episodeDetailsKodi['year']}
                    else:
                        self.traktShowSummary = {'title': title, 'year': year}
                    if tvdb:
                        self.traktShowSummary['ids'] = {'tvdb': tvdb}
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject('episode', episodeDetailsKodi)
                    if not self.curVideoInfo:  # getEpisodeDetailsFromKodi was empty
                        logger.debug("Episode details from Kodi 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
                elif 'video_ids' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo:
                    self.curVideoInfo = {'title': self.curVideo['title'], 'season': self.curVideo['season'], 'number': self.curVideo['episode']}
                    self.traktShowSummary = {'ids': self.curVideo['video_ids']}
                elif 'title' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo:
                    self.curVideoInfo = {'title': self.curVideo['title'], 'season': self.curVideo['season'],
                                         'number': self.curVideo['episode']}

                    title, year = utilities.regex_year(self.curVideo['showtitle'])
                    if not year:
                        self.traktShowSummary = {'title': self.curVideo['showtitle']}
                    else:
                        self.traktShowSummary = {'title': title, 'year': year}

                    if 'year' in self.curVideo:
                        self.traktShowSummary['year'] = self.curVideo['year']

                if 'multi_episode_count' in self.curVideo and self.curVideo['multi_episode_count'] > 1:
                    self.isMultiPartEpisode = True

            self.isPlaying = True
            self.isPaused = False

            result = {}
            if utilities.getSettingAsBool('scrobble_movie') or utilities.getSettingAsBool('scrobble_episode'):
                result = self.__scrobble('start')
            elif utilities.getSettingAsBool('rate_movie') and utilities.isMovie(self.curVideo['type']) and 'ids' in self.curVideoInfo:
                result = {'movie': self.traktapi.getMovieSummary(utilities.best_id(self.curVideoInfo['ids'])).to_dict()}
            elif utilities.getSettingAsBool('rate_episode') and utilities.isEpisode(self.curVideo['type']) and 'ids' in self.traktShowSummary:
                best_id = utilities.best_id(self.traktShowSummary['ids'])
                result = {'show': self.traktapi.getShowSummary(best_id).to_dict(),
                          'episode': self.traktapi.getEpisodeSummary(best_id, self.curVideoInfo['season'], self.curVideoInfo['number']).to_dict()}

            self.__preFetchUserRatings(result)
Beispiel #8
0
    def playbackStarted(self, data):
        Debug("[Scrobbler] playbackStarted(data: %s)" % data)
        if not data:
            return
        self.curVideo = data
        self.curVideoInfo = None

        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 as 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.kodiRpcToTraktMediaObject(
                        'movie',
                        utilities.getMovieDetailsFromKodi(
                            self.curVideo['id'], [
                                'imdbnumber', 'title', 'year', 'file',
                                'lastplayed', 'playcount'
                            ]))
                    Debug("Trakt ticket: %s" % self.curVideo)
                    if utilities.getSettingAsBool('rate_movie'):
                        # pre-get sumamry information, for faster rating dialog.
                        Debug(
                            "[Scrobbler] Movie rating is enabled, pre-fetching summary information."
                        )
                        if self.curVideoInfo['ids']['imdb']:
                            self.traktSummaryInfo = self.traktapi.getMovieSummary(
                                self.curVideoInfo['ids']['imdb'])
                        elif self.curVideoInfo['ids']['tmdb']:
                            self.traktSummaryInfo = self.traktapi.getMovieSummary(
                                self.curVideoInfo['ids']['tmdb'])
                        else:
                            self.curVideoInfo['ids']['imdb'] = 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 = {'ids': {}}
                    self.curVideoInfo['ids']['imdb'] = None
                    self.curVideoInfo['title'] = self.curVideo['title']
                    self.curVideoInfo['year'] = self.curVideo['year']

            elif utilities.isEpisode(self.curVideo['type']):
                if 'id' in self.curVideo:
                    episodeDetailsKodi = utilities.getEpisodeDetailsFromKodi(
                        self.curVideo['id'], [
                            'showtitle', 'season', 'episode', 'tvshowid',
                            'uniqueid', 'file', 'playcount'
                        ])
                    tvdb = episodeDetailsKodi['imdbnumber']
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject(
                        'episode', episodeDetailsKodi)
                    if not self.curVideoInfo:  # getEpisodeDetailsFromKodi was empty
                        Debug(
                            "[Scrobbler] Episode details from Kodi 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."
                        )

                        if tvdb:
                            lookupShow = self.traktapi.getIdLookup(
                                'tvdb', tvdb)
                            self.traktShowSummary = self.traktapi.getShowSummary(
                                lookupShow['ids']['slug'])
                            self.traktSummaryInfo = self.traktapi.getEpisodeSummary(
                                lookupShow['ids'], self.curVideoInfo['season'],
                                self.curVideoInfo['number'])
                        else:
                            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']))
                    else:
                        self.traktShowSummary = {
                            'title': episodeDetailsKodi['showtitle']
                        }
                        self.traktShowSummary['ids'] = {'tvdb': tvdb}
                elif 'title' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo:
                    self.curVideoInfo = {'tvdb_id': None}
                    self.curVideoInfo['title'] = self.curVideo['title']
                    self.curVideoInfo['season'] = self.curVideo['season']
                    self.curVideoInfo['number'] = self.curVideo['episode']

                    self.traktShowSummary = {
                        'title': self.curVideo['showtitle']
                    }
                    if 'year' in self.curVideo:
                        self.traktShowSummary['year'] = self.curVideo['year']

                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')
Beispiel #9
0
    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:
                logger.debug(
                    "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.__calculateWatchedPercent()
                    epIndex = self._currentEpisode(
                        watchedPercent, self.curVideo['multi_episode_count'])
                    if self.curMPEpisode != epIndex:
                        # current episode in multi-part episode has changed
                        logger.debug(
                            "Attempting to stop 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'])
                        watchedPercent = (
                            (self.watchedTime -
                             (adjustedDuration * self.curMPEpisode)) /
                            adjustedDuration) * 100
                        response = self.traktapi.scrobbleEpisode(
                            self.traktShowSummary, self.curVideoInfo,
                            watchedPercent, 'stop')
                        if response is not None:
                            logger.debug("Scrobble response: %s" %
                                         str(response))

                        # update current information
                        self.curMPEpisode = epIndex
                        self.curVideoInfo = utilities.kodiRpcToTraktMediaObject(
                            'episode',
                            utilities.getEpisodeDetailsFromKodi(
                                self.curVideo['multi_episode_data']
                                [self.curMPEpisode], [
                                    'showtitle', 'season', 'episode',
                                    'tvshowid', 'uniqueid', 'file', 'playcount'
                                ]))

                        if not forceCheck:
                            logger.debug(
                                "Attempting to start scrobble episode part %d of %d."
                                % (self.curMPEpisode + 1,
                                   self.curVideo['multi_episode_count']))
                            response = self.traktapi.scrobbleEpisode(
                                self.traktShowSummary, self.curVideoInfo, 0,
                                'start')
                            if response is not None:
                                logger.debug("Scrobble response: %s" %
                                             str(response))
Beispiel #10
0
    def playbackStarted(self, data):
        logger.debug("playbackStarted(data: %s)" % data)
        if not data:
            return
        self.curVideo = data
        self.curVideoInfo = None

        if 'type' in self.curVideo:
            logger.debug("Watching: %s" % self.curVideo['type'])
            if not xbmc.Player().isPlayingVideo():
                logger.debug("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 as e:
                logger.debug("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:
                logger.debug(
                    "Warning: Cant find playlist length, assuming that this item is by itself"
                )
                self.playlistLength = 1

            self.isMultiPartEpisode = False
            if utilities.isMovie(self.curVideo['type']):
                if 'id' in self.curVideo:
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject(
                        'movie',
                        utilities.getMovieDetailsFromKodi(
                            self.curVideo['id'], [
                                'imdbnumber', 'title', 'year', 'file',
                                'lastplayed', 'playcount'
                            ]))
                elif 'title' in self.curVideo and 'year' in self.curVideo:
                    self.curVideoInfo = {
                        'title': self.curVideo['title'],
                        'year': self.curVideo['year']
                    }

            elif utilities.isEpisode(self.curVideo['type']):
                if 'id' in self.curVideo:
                    episodeDetailsKodi = utilities.getEpisodeDetailsFromKodi(
                        self.curVideo['id'], [
                            'showtitle', 'season', 'episode', 'tvshowid',
                            'uniqueid', 'file', 'playcount'
                        ])
                    tvdb = episodeDetailsKodi['imdbnumber']
                    title, year = utilities.regex_year(
                        episodeDetailsKodi['showtitle'])
                    if not year:
                        self.traktShowSummary = {
                            'title': episodeDetailsKodi['showtitle'],
                            'year': episodeDetailsKodi['year']
                        }
                    else:
                        self.traktShowSummary = {'title': title, 'year': year}
                    if tvdb:
                        self.traktShowSummary['ids'] = {'tvdb': tvdb}
                    self.curVideoInfo = utilities.kodiRpcToTraktMediaObject(
                        'episode', episodeDetailsKodi)
                    if not self.curVideoInfo:  # getEpisodeDetailsFromKodi was empty
                        logger.debug(
                            "Episode details from Kodi 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
                elif 'title' in self.curVideo and 'season' in self.curVideo and 'episode' in self.curVideo:
                    self.curVideoInfo = {
                        'title': self.curVideo['title'],
                        'season': self.curVideo['season'],
                        'number': self.curVideo['episode']
                    }

                    title, year = utilities.regex_year(
                        self.curVideo['showtitle'])
                    if not year:
                        self.traktShowSummary = {
                            'title': self.curVideo['showtitle']
                        }
                    else:
                        self.traktShowSummary = {'title': title, 'year': year}

                    if 'year' in self.curVideo:
                        self.traktShowSummary['year'] = self.curVideo['year']

                if 'multi_episode_count' in self.curVideo:
                    self.isMultiPartEpisode = True

            self.isPlaying = True
            self.isPaused = False
            result = self.__scrobble('start')
            if result:
                if utilities.isMovie(
                        self.curVideo['type']) and utilities.getSettingAsBool(
                            'rate_movie'):
                    # pre-get sumamry information, for faster rating dialog.
                    logger.debug(
                        "Movie rating is enabled, pre-fetching summary information."
                    )
                    if result['movie']['ids']['imdb']:
                        self.curVideoInfo['user'] = {
                            'ratings':
                            self.traktapi.getMovieRatingForUser(
                                result['movie']['ids']['imdb'])
                        }
                        self.curVideoInfo['ids'] = result['movie']['ids']
                    else:
                        logger.debug(
                            "'%s (%d)' has no valid id, can't get rating." %
                            (self.curVideoInfo['title'],
                             self.curVideoInfo['year']))
                elif utilities.isEpisode(
                        self.curVideo['type']) and utilities.getSettingAsBool(
                            'rate_episode'):
                    # pre-get sumamry information, for faster rating dialog.
                    logger.debug(
                        "Episode rating is enabled, pre-fetching summary information."
                    )

                    if result['show']['ids']['tvdb']:
                        self.curVideoInfo['user'] = {
                            'ratings':
                            self.traktapi.getEpisodeRatingForUser(
                                result['show']['ids']['tvdb'],
                                self.curVideoInfo['season'],
                                self.curVideoInfo['number'])
                        }
                        self.curVideoInfo['ids'] = result['episode']['ids']
                    else:
                        logger.debug(
                            "'%s - S%02dE%02d' has no valid id, can't get rating."
                            % (self.curVideoInfo['showtitle'],
                               self.curVideoInfo['season'],
                               self.curVideoInfo['episode']))