def onPlayBackStarted(self):
		xbmc.sleep(1000)
		self.type = None
		self.id = None
		
		# only do anything if we're playing a video
		if self.isPlayingVideo():
			# get item data from json rpc
			rpccmd = json.dumps({"jsonrpc": "2.0", "method": "Player.GetItem", "params": {"playerid": 1}, "id": 1})
			result = xbmc.executeJSONRPC(rpccmd)
			Debug("[traktPlayer] onPlayBackStarted() - %s" % result)
			result = json.loads(result)
			
			self.type = result["result"]["item"]["type"]
			
			# check for non-library item playback
			if self.type == "unknown":
				Debug("[traktPlayer] onPlayBackStarted() - Started playing a non-library file, skipping.")
				return
			
			# check for exclusion
			_filename = self.getPlayingFile()
			if checkScrobblingExclusion(_filename):
				Debug("[traktPlayer] onPlayBackStarted() - '%s' is in exclusion settings, ignoring." % _filename)
				return
			
			self.id = result["result"]["item"]["id"]
			
			data = {"action": "started", "id": self.id, "type": self.type}
			
			self._playing = True
			
			# send dispatch
			self.action(data)
Esempio n. 2
0
	def onPlayBackStarted(self):
		xbmc.sleep(1000)
		self.type = None
		self.id = None

		# only do anything if we're playing a video
		if self.isPlayingVideo():
			# get item data from json rpc
			result = utilities.xbmcJsonRequest({'jsonrpc': '2.0', 'method': 'Player.GetItem', 'params': {'playerid': 1}, 'id': 1})
			utilities.Debug("[traktPlayer] onPlayBackStarted() - %s" % result)

			# check for exclusion
			_filename = None
			try:
				_filename = self.getPlayingFile()
			except:
				utilities.Debug("[traktPlayer] onPlayBackStarted() - Exception trying to get playing filename, player stopped suddently.")
				return

			if utilities.checkScrobblingExclusion(_filename):
				utilities.Debug("[traktPlayer] onPlayBackStarted() - '%s' is in exclusion settings, ignoring." % _filename)
				return

			self.type = result['item']['type']

			data = {'action': 'started'}

			# check type of item
			if self.type == 'unknown':
				# do a deeper check to see if we have enough data to perform scrobbles
				utilities.Debug("[traktPlayer] onPlayBackStarted() - Started playing a non-library file, checking available data.")
				
				season = xbmc.getInfoLabel('VideoPlayer.Season')
				episode = xbmc.getInfoLabel('VideoPlayer.Episode')
				showtitle = xbmc.getInfoLabel('VideoPlayer.TVShowTitle')
				year = xbmc.getInfoLabel('VideoPlayer.Year')

				if season and episode and showtitle:
					# we have season, episode and show title, can scrobble this as an episode
					self.type = 'episode'
					data['type'] = 'episode'
					data['season'] = int(season)
					data['episode'] = int(episode)
					data['showtitle'] = showtitle
					data['title'] = xbmc.getInfoLabel('VideoPlayer.Title')
					if year.isdigit():
						data['year'] = year
					utilities.Debug("[traktPlayer] onPlayBackStarted() - Playing a non-library 'episode' - %s - S%02dE%02d - %s." % (data['showtitle'], data['season'], data['episode'], data['title']))
				elif year and not season and not showtitle:
					# we have a year and no season/showtitle info, enough for a movie
					self.type = 'movie'
					data['type'] = 'movie'
					data['year'] = int(year)
					data['title'] = xbmc.getInfoLabel('VideoPlayer.Title')
					utilities.Debug("[traktPlayer] onPlayBackStarted() - Playing a non-library 'movie' - %s (%d)." % (data['title'], data['year']))
				else:
					utilities.Debug("[traktPlayer] onPlayBackStarted() - Non-library file, not enough data for scrobbling, skipping.")
					return

			elif self.type == 'episode' or self.type == 'movie':
				# get library id
				self.id = result['item']['id']
				data['id'] = self.id
				data['type'] = self.type

				if self.type == 'episode':
					utilities.Debug("[traktPlayer] onPlayBackStarted() - Doing multi-part episode check.")
					result = utilities.xbmcJsonRequest({'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodeDetails', 'params': {'episodeid': self.id, 'properties': ['tvshowid', 'season', 'episode']}, 'id': 1})
					if result:
						utilities.Debug("[traktPlayer] onPlayBackStarted() - %s" % result)
						tvshowid = int(result['episodedetails']['tvshowid'])
						season = int(result['episodedetails']['season'])
						episode = int(result['episodedetails']['episode'])
						episode_index = episode - 1

						result = utilities.xbmcJsonRequest({'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodes', 'params': {'tvshowid': tvshowid, 'season': season, 'properties': ['episode', 'file'], 'sort': {'method': 'episode'}}, 'id': 1})
						if result:
							utilities.Debug("[traktPlayer] onPlayBackStarted() - %s" % result)
							# make sure episodes array exists in results
							if 'episodes' in result:
								multi = []
								for i in range(episode_index, result['limits']['total']):
									if result['episodes'][i]['file'] == result['episodes'][episode_index]['file']:
										multi.append(result['episodes'][i]['episodeid'])
									else:
										break
								if len(multi) > 1:
									data['multi_episode_data'] = multi
									data['multi_episode_count'] = len(multi)
									utilities.Debug("[traktPlayer] onPlayBackStarted() - This episode is part of a multi-part episode.")
								else:
									utilities.Debug("[traktPlayer] onPlayBackStarted() - This is a single episode.")

			else:
				utilities.Debug("[traktPlayer] onPlayBackStarted() - Video type '%s' unrecognized, skipping." % self.type)
				return

			pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
			plSize = len(pl)
			if plSize > 1:
				pos = pl.getposition()
				if not self.plIndex is None:
					utilities.Debug("[traktPlayer] onPlayBackStarted() - User manually skipped to next (or previous) video, forcing playback ended event.")
					self.onPlayBackEnded()
				self.plIndex = pos
				utilities.Debug("[traktPlayer] onPlayBackStarted() - Playlist contains %d item(s), and is currently on item %d" % (plSize, (pos + 1)))

			self._playing = True

			# send dispatch
			self.action(data)
	def onPlayBackStarted(self):
		xbmc.sleep(1000)
		self.type = None
		self.id = None
		
		# only do anything if we're playing a video
		if self.isPlayingVideo():
			# get item data from json rpc
			result = xbmcJsonRequest({"jsonrpc": "2.0", "method": "Player.GetItem", "params": {"playerid": 1}, "id": 1})
			Debug("[traktPlayer] onPlayBackStarted() - %s" % result)
			
			# check for exclusion
			_filename = self.getPlayingFile()
			if checkScrobblingExclusion(_filename):
				Debug("[traktPlayer] onPlayBackStarted() - '%s' is in exclusion settings, ignoring." % _filename)
				return
			
			self.type = result["item"]["type"]

			data = {"action": "started"}
			
			# check type of item
			if self.type == "unknown":
				# do a deeper check to see if we have enough data to perform scrobbles
				Debug("[traktPlayer] onPlayBackStarted() - Started playing a non-library file, checking available data.")
				
				season = xbmc.getInfoLabel("VideoPlayer.Season")
				episode = xbmc.getInfoLabel("VideoPlayer.Episode")
				showtitle = xbmc.getInfoLabel("VideoPlayer.TVShowTitle")
				year = xbmc.getInfoLabel("VideoPlayer.Year")
				
				if season and episode and showtitle:
					# we have season, episode and show title, can scrobble this as an episode
					self.type = "episode"
					data["type"] = "episode"
					data["season"] = int(season)
					data["episode"] = int(episode)
					data["showtitle"] = showtitle
					data["title"] = xbmc.getInfoLabel("VideoPlayer.Title")
					Debug("[traktPlayer] onPlayBackStarted() - Playing a non-library 'episode' - %s - S%02dE%02d - %s." % (data["title"], data["season"], data["episode"]))
				elif year and not season and not showtitle:
					# we have a year and no season/showtitle info, enough for a movie
					self.type = "movie"
					data["type"] = "movie"
					data["year"] = int(year)
					data["title"] = xbmc.getInfoLabel("VideoPlayer.Title")
					Debug("[traktPlayer] onPlayBackStarted() - Playing a non-library 'movie' - %s (%d)." % (data["title"], data["year"]))
				else:
					Debug("[traktPlayer] onPlayBackStarted() - Non-library file, not enough data for scrobbling, skipping.")
					return
			
			elif self.type == "episode" or self.type == "movie":
				# get library id
				self.id = result["item"]["id"]
				data["id"] = self.id
				data["type"] = self.type
			
				if self.type == "episode":
					Debug("[traktPlayer] onPlayBackStarted() - Doing multi-part episode check.")
					result = xbmcJsonRequest({"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": self.id, "properties": ["tvshowid", "season","episode"]}, "id": 1})
					if result:
						Debug("[traktPlayer] onPlayBackStarted() - %s" % result)
						tvshowid = int(result["episodedetails"]["tvshowid"])
						season = int(result["episodedetails"]["season"])
						episode = int(result["episodedetails"]["episode"])
						episode_index = episode - 1
						
						result = xbmcJsonRequest({"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": tvshowid, "season": season, "properties": ["episode", "file"], "sort": {"method": "episode"}}, "id": 1})
						if result:
							Debug("[traktPlayer] onPlayBackStarted() - %s" % result)
							# make sure episodes array exists in results
							if result.has_key("episodes"):
								multi = []
								for i in range(episode_index, result["limits"]["total"]):
									if result["episodes"][i]["file"] == result["episodes"][episode_index]["file"]:
										multi.append(result["episodes"][i]["episodeid"])
									else:
										break
								if len(multi) > 1:
									data["multi_episode_data"] = multi
									data["multi_episode_count"] = len(multi)
									Debug("[traktPlayer] onPlayBackStarted() - This episode is part of a multi-part episode.")

			else:
				Debug("[traktPlayer] onPlayBackStarted() - Video type '%s' unrecognized, skipping." % self.type)
				return

			self._playing = True
			
			# send dispatch
			self.action(data)
Esempio n. 4
0
    def onPlayBackStarted(self):
        xbmc.sleep(1000)
        self.type = None
        self.id = None

        # only do anything if we're playing a video
        if self.isPlayingVideo():
            # get item data from json rpc
            result = utilities.xbmcJsonRequest({
                'jsonrpc': '2.0',
                'method': 'Player.GetItem',
                'params': {
                    'playerid': 1
                },
                'id': 1
            })
            utilities.Debug("[traktPlayer] onPlayBackStarted() - %s" % result)

            # check for exclusion
            _filename = None
            try:
                _filename = self.getPlayingFile()
            except:
                utilities.Debug(
                    "[traktPlayer] onPlayBackStarted() - Exception trying to get playing filename, player stopped suddently."
                )
                return

            if utilities.checkScrobblingExclusion(_filename):
                utilities.Debug(
                    "[traktPlayer] onPlayBackStarted() - '%s' is in exclusion settings, ignoring."
                    % _filename)
                return

            self.type = result['item']['type']

            data = {'action': 'started'}

            # check type of item
            if self.type == 'unknown':
                # do a deeper check to see if we have enough data to perform scrobbles
                utilities.Debug(
                    "[traktPlayer] onPlayBackStarted() - Started playing a non-library file, checking available data."
                )

                season = xbmc.getInfoLabel('VideoPlayer.Season')
                episode = xbmc.getInfoLabel('VideoPlayer.Episode')
                showtitle = xbmc.getInfoLabel('VideoPlayer.TVShowTitle')
                year = xbmc.getInfoLabel('VideoPlayer.Year')

                if season and episode and showtitle:
                    # we have season, episode and show title, can scrobble this as an episode
                    self.type = 'episode'
                    data['type'] = 'episode'
                    data['season'] = int(season)
                    data['episode'] = int(episode)
                    data['showtitle'] = showtitle
                    data['title'] = xbmc.getInfoLabel('VideoPlayer.Title')
                    if year.isdigit():
                        data['year'] = year
                    utilities.Debug(
                        "[traktPlayer] onPlayBackStarted() - Playing a non-library 'episode' - %s - S%02dE%02d - %s."
                        % (data['showtitle'], data['season'], data['episode'],
                           data['title']))
                elif year and not season and not showtitle:
                    # we have a year and no season/showtitle info, enough for a movie
                    self.type = 'movie'
                    data['type'] = 'movie'
                    data['year'] = int(year)
                    data['title'] = xbmc.getInfoLabel('VideoPlayer.Title')
                    utilities.Debug(
                        "[traktPlayer] onPlayBackStarted() - Playing a non-library 'movie' - %s (%d)."
                        % (data['title'], data['year']))
                else:
                    utilities.Debug(
                        "[traktPlayer] onPlayBackStarted() - Non-library file, not enough data for scrobbling, skipping."
                    )
                    return

            elif self.type == 'episode' or self.type == 'movie':
                # get library id
                self.id = result['item']['id']
                data['id'] = self.id
                data['type'] = self.type

                if self.type == 'episode':
                    utilities.Debug(
                        "[traktPlayer] onPlayBackStarted() - Doing multi-part episode check."
                    )
                    result = utilities.xbmcJsonRequest({
                        'jsonrpc': '2.0',
                        'method': 'VideoLibrary.GetEpisodeDetails',
                        'params': {
                            'episodeid': self.id,
                            'properties': ['tvshowid', 'season', 'episode']
                        },
                        'id': 1
                    })
                    if result:
                        utilities.Debug(
                            "[traktPlayer] onPlayBackStarted() - %s" % result)
                        tvshowid = int(result['episodedetails']['tvshowid'])
                        season = int(result['episodedetails']['season'])
                        episode = int(result['episodedetails']['episode'])
                        episode_index = episode - 1

                        result = utilities.xbmcJsonRequest({
                            'jsonrpc': '2.0',
                            'method': 'VideoLibrary.GetEpisodes',
                            'params': {
                                'tvshowid': tvshowid,
                                'season': season,
                                'properties': ['episode', 'file'],
                                'sort': {
                                    'method': 'episode'
                                }
                            },
                            'id': 1
                        })
                        if result:
                            utilities.Debug(
                                "[traktPlayer] onPlayBackStarted() - %s" %
                                result)
                            # make sure episodes array exists in results
                            if 'episodes' in result:
                                multi = []
                                for i in range(episode_index,
                                               result['limits']['total']):
                                    if result['episodes'][i]['file'] == result[
                                            'episodes'][episode_index]['file']:
                                        multi.append(
                                            result['episodes'][i]['episodeid'])
                                    else:
                                        break
                                if len(multi) > 1:
                                    data['multi_episode_data'] = multi
                                    data['multi_episode_count'] = len(multi)
                                    utilities.Debug(
                                        "[traktPlayer] onPlayBackStarted() - This episode is part of a multi-part episode."
                                    )
                                else:
                                    utilities.Debug(
                                        "[traktPlayer] onPlayBackStarted() - This is a single episode."
                                    )

            else:
                utilities.Debug(
                    "[traktPlayer] onPlayBackStarted() - Video type '%s' unrecognized, skipping."
                    % self.type)
                return

            pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
            plSize = len(pl)
            if plSize > 1:
                pos = pl.getposition()
                if not self.plIndex is None:
                    utilities.Debug(
                        "[traktPlayer] onPlayBackStarted() - User manually skipped to next (or previous) video, forcing playback ended event."
                    )
                    self.onPlayBackEnded()
                self.plIndex = pos
                utilities.Debug(
                    "[traktPlayer] onPlayBackStarted() - Playlist contains %d item(s), and is currently on item %d"
                    % (plSize, (pos + 1)))

            self._playing = True

            # send dispatch
            self.action(data)
    def onPlayBackStarted(self):
        #xbmc.sleep(2000)
        self.type = None
        self.id = None
        
        # only do anything if we're playing a video
        if self.isPlayingVideo():
            # get item data from json rpc
            result = xbmcJsonRequest({"jsonrpc": "2.0", "method": "Player.GetItem", "params": {"playerid": 1}, "id": 1})
            Debug("[myshowsPlayer] onPlayBackStarted() - %s" % result)
            
            # check for exclusion
            _filename = self.getPlayingFile()
            if checkScrobblingExclusion(_filename):
                Debug("[myshowsPlayer] onPlayBackStarted() - '%s' is in exclusion settings, ignoring." % _filename)
                return

            try:
                if result['item']['label']=='': result['item']['label']=_filename.replace('\\','/').split('/')[-1]
            except: pass

            self.type = result["item"]["type"]

            data = {"action": "started"}
            
            # check type of item
            if self.type == "unknown":
                # do a deeper check to see if we have enough data to perform scrobbles
                Debug("[myshowsPlayer] onPlayBackStarted() - Started playing a non-library file, checking available data.")
                
                season = xbmc.getInfoLabel("VideoPlayer.Season")
                episode = xbmc.getInfoLabel("VideoPlayer.Episode")
                showtitle = xbmc.getInfoLabel("VideoPlayer.TVShowTitle")
                year = xbmc.getInfoLabel("VideoPlayer.Year")
                
                if season and episode and showtitle:
                    # we have season, episode and show title, can scrobble this as an episode
                    self.type = "episode"
                    data["type"] = "episode"
                    data["season"] = int(season)
                    data["episode"] = int(episode)
                    data["showtitle"] = showtitle
                    data["title"] = xbmc.getInfoLabel("VideoPlayer.Title")
                    Debug("[myshowsPlayer] onPlayBackStarted() - Playing a non-library 'episode' - %s - S%02dE%02d - %s." % (data["title"], data["season"], data["episode"]))
                elif year and not season and not showtitle:
                    # we have a year and no season/showtitle info, enough for a movie
                    self.type = "movie"
                    data["type"] = "movie"
                    data["year"] = int(year)
                    data["title"] = xbmc.getInfoLabel("VideoPlayer.Title")
                    data["titleAlt"]= xbmc.getInfoLabel("VideoPlayer.OriginalTitle")
                    Debug("[myshowsPlayer] onPlayBackStarted() - Playing a non-library 'movie' - %s (%d)." % (data["title"], data["year"]))
                else:
                    Debug("[myshowsPlayer] onPlayBackStarted() - Non-library file, not enough data for scrobbling, try use lable.")
                    try:data["label"]=result["item"]["label"]
                    except: return
                    urls=['(.+)s(\d+)e(\d+)','(.+)s(\d+)\.e(\d+)', '(.+) [\[|\(](\d+)[x|-](\d+)[\]|\)]', '(.+) (\d+)[x|-](\d+)',
                          '(.+)(\d{4})\.(\d{2,4})\.(\d{2,4})','(.+)(\d{4}) (\d{2}) (\d{2})']
                    for file in urls:
                        match=re.compile(file, re.I | re.IGNORECASE).findall(data["label"])
                        if match:
                            self.type = "episode"
                            data["type"] = "episode"
                            break
                    if self.type!="episode":
                        file=data["label"]
                        file=file.replace('.',' ').replace('_',' ').replace('[',' ').replace(']',' ').replace('(',' ').replace(')',' ').strip()
                        match=re.compile('(.+) (\d{4})( |$)', re.I | re.IGNORECASE).findall(file)
                        if match:
                            data["title"], data["year"] = match[0][0],match[0][1]
                            self.type = "movie"
                            data["type"] = "movie"
                            data["year"]=int(data["year"])
                            data["title"]=data["title"].strip()

                    if self.type == "unknown":
                        Debug("[myshowsPlayer] onPlayBackStarted() - Non-library unknown file, stopped scrobble.")

            elif self.type == "episode" or self.type == "movie":
                # get library id
                self.id = result["item"]["id"]
                data["id"] = self.id
                data["type"] = self.type

                if self.type == "movie":
                    data["year"] = xbmc.getInfoLabel("VideoPlayer.Year")
                    data["title"] = xbmc.getInfoLabel("VideoPlayer.Title")
                    data["titleAlt"]= xbmc.getInfoLabel("VideoPlayer.OriginalTitle")
                    if len(data["title"])<1:
                        result = xbmcJsonRequest({"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"movieid": self.id, "properties": ["title", "year","originaltitle"]}, "id": 1})
                        if result:
                            Debug("[myshowsPlayer] onPlayBackStarted() TitleLen0 Event - %s" % result)
                            data["title"] = result["moviedetails"]["title"]
                            data["year"] = int(result["moviedetails"]["year"])
                            data["titleAlt"] = result["moviedetails"]["originaltitle"]

                if self.type == "episode":
                    Debug("[myshowsPlayer] onPlayBackStarted() - Doing multi-part episode check.")
                    result = xbmcJsonRequest({"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"episodeid": self.id, "properties": ["tvshowid", "season","episode"]}, "id": 1})
                    if result:
                        Debug("[myshowsPlayer] onPlayBackStarted() - %s" % result)
                        tvshowid = int(result["episodedetails"]["tvshowid"])
                        season = int(result["episodedetails"]["season"])
                        episode = int(result["episodedetails"]["episode"])
                        episode_index = episode - 1
                        
                        result = xbmcJsonRequest({"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"tvshowid": tvshowid, "season": season, "properties": ["episode", "file"], "sort": {"method": "episode"}}, "id": 1})
                        if result:
                            Debug("[myshowsPlayer] onPlayBackStarted() - %s" % result)
                            # make sure episodes array exists in results
                            if result.has_key("episodes"):
                                multi = []
                                for i in range(episode_index, result["limits"]["total"]):
                                    if result["episodes"][i]["file"] == result["episodes"][episode_index]["file"]:
                                        multi.append(result["episodes"][i]["episodeid"])
                                    else:
                                        break
                                if len(multi) > 1:
                                    data["multi_episode_data"] = multi
                                    data["multi_episode_count"] = len(multi)
                                    Debug("[myshowsPlayer] onPlayBackStarted() - This episode is part of a multi-part episode.")
            else:
                Debug("[myshowsPlayer] onPlayBackStarted() - Video type '%s' unrecognized, skipping." % self.type)
                return

            self._playing = True
            
            # send dispatch
            Debug("[myshowsPlayer] onPlayBackStarted() - Data '%s'." % data)
            self.action(data)