コード例 #1
0
class NotificationService:

	_scrobbler = None
	
	def __init__(self):
		self.run()

	def _dispatch(self, data):
		Debug("[Notification] Dispatch: %s" % data)
		xbmc.sleep(500)
		action = data["action"]
		if action == "started":
			p = {"item": {"type": data["type"], "id": data["id"]}}
			self._scrobbler.playbackStarted(p)
		elif action == "ended" or action == "stopped":
			self._scrobbler.playbackEnded()
		elif action == "paused":
			self._scrobbler.playbackPaused()
		elif action == "resumed":
			self._scrobbler.playbackResumed()
		elif action == "databaseUpdated":
			if do_sync('movies'):
				movies = SyncMovies(show_progress=False)
				movies.Run()
			if do_sync('episodes'):
				episodes = SyncEpisodes(show_progress=False)
				episodes.Run()
		elif action == "scanStarted":
			Debug("[Notification] Dispatch: scanStarted")
		else:
			Debug("[Notification] '%s' unknown dispatch action!" % action)

	def run(self):
		Debug("[Notification] Starting")
		
		# setup event driven classes
		self.Player = traktPlayer(action = self._dispatch)
		self.Monitor = traktMonitor(action = self._dispatch)
		
		# initalize scrobbler class
		self._scrobbler = Scrobbler()
		self._scrobbler.start()
		
		# start loop for events
		while (not xbmc.abortRequested):
			xbmc.sleep(500)
			
		# we aborted
		if xbmc.abortRequested:
			Debug("[Notification] abortRequested received, shutting down.")
			# join scrobbler, to wait for termination
			Debug("[Notification] Joining scrobbler thread to wait for exit.")
			self._scrobbler.join()
コード例 #2
0
class NotificationService:

	_scrobbler = None
	
	def __init__(self):
		self.run()

	def _dispatch(self, data):
		Debug("[Notification] Dispatch: %s" % data)
		xbmc.sleep(500)
		
		# check if scrobbler thread is still alive
		if not self._scrobbler.isAlive():

			if self.Player._playing and not self._scrobbler.pinging:
				# make sure pinging is set
				self._scrobbler.pinging = True

			Debug("[Notification] Scrobler thread died, restarting.")
			self._scrobbler.start()
		
		action = data["action"]
		if action == "started":
			del data["action"]
			p = {"item": data}
			self._scrobbler.playbackStarted(p)
		elif action == "ended" or action == "stopped":
			self._scrobbler.playbackEnded()
		elif action == "paused":
			self._scrobbler.playbackPaused()
		elif action == "resumed":
			self._scrobbler.playbackResumed()
		elif action == "seek" or action == "seekchapter":
			self._scrobbler.playbackSeek()
		elif action == "databaseUpdated":
			if do_sync('movies'):
				movies = SyncMovies(show_progress=False, api=globals.traktapi)
				movies.Run()
			if do_sync('episodes'):
				episodes = SyncEpisodes(show_progress=False, api=globals.traktapi)
				episodes.Run()
		elif action == "scanStarted":
			pass
		elif action == "settingsChanged":
			Debug("[Notification] Settings changed, reloading.")
			globals.traktapi.updateSettings()
		else:
			Debug("[Notification] '%s' unknown dispatch action!" % action)

	def run(self):
		Debug("[Notification] Starting")
		
		# setup event driven classes
		self.Player = traktPlayer(action = self._dispatch)
		self.Monitor = traktMonitor(action = self._dispatch)
		
		# init traktapi class
		globals.traktapi = traktAPI()

		# initalize scrobbler class
		self._scrobbler = Scrobbler(globals.traktapi)

		# start loop for events
		while (not xbmc.abortRequested):
			xbmc.sleep(500)
			
		# we aborted
		if xbmc.abortRequested:
			Debug("[Notification] abortRequested received, shutting down.")
			
			# delete player/monitor
			del self.Player
			del self.Monitor
			
			# join scrobbler, to wait for termination
			Debug("[Notification] Joining scrobbler thread to wait for exit.")
			self._scrobbler.join()