當前位置: 首頁>>代碼示例>>Python>>正文


Python scrobbler.Scrobbler類代碼示例

本文整理匯總了Python中scrobbler.Scrobbler的典型用法代碼示例。如果您正苦於以下問題:Python Scrobbler類的具體用法?Python Scrobbler怎麽用?Python Scrobbler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Scrobbler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

	def run(self):		  
		#while xbmc is running
		scrobbler = Scrobbler()
		scrobbler.start()
		
		while (not (self.abortRequested or xbmc.abortRequested)):
			time.sleep(1)
			try:
				tn = telnetlib.Telnet('localhost', 9090, 10)
			except IOError as (errno, strerror):
				#connection failed, try again soon
				Debug("[Notification Service] Telnet too soon? ("+str(errno)+") "+strerror)
				time.sleep(1)
				continue
			
			Debug("[Notification Service] Waiting~");
			bCount = 0
			
			while (not (self.abortRequested or xbmc.abortRequested)):
				try:
					if bCount == 0:
						notification = ""
						inString = False
					[index, match, raw] = tn.expect(["(\\\\)|(\\\")|[{\"}]"], 0.2) #note, pre-compiled regex might be faster here
					notification += raw
					if index == -1: # Timeout
						continue
					if index == 0: # Found escaped quote
						match = match.group(0)
						if match == "\"":
							inString = not inString
							continue
						if match == "{":
							bCount += 1
						if match == "}":
							bCount -= 1
					if bCount > 0:
						continue
					if bCount < 0:
						bCount = 0
				except EOFError:
					break #go out to the other loop to restart the connection
				
				Debug("[Notification Service] message: " + str(notification))
				
				# Parse recieved notification
				data = json.loads(notification)
				
				# Forward notification to functions
				if 'method' in data and 'params' in data and 'sender' in data['params'] and data['params']['sender'] == 'xbmc':
					if data['method'] == 'Player.OnStop':
						scrobbler.playbackEnded()
					elif data['method'] == 'Player.OnPlay':
						if 'data' in data['params'] and 'item' in data['params']['data'] and 'type' in data['params']['data']['item']:
							scrobbler.playbackStarted(data['params']['data'])
					elif data['method'] == 'Player.OnPause':
						scrobbler.playbackPaused()
					elif data['method'] == 'System.OnQuit':
						self.abortRequested = True
開發者ID:MaDDoGo,項目名稱:script.trakt,代碼行數:59,代碼來源:notification_service.py

示例2: __init__

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()
開發者ID:Conjuro,項目名稱:script.trakt,代碼行數:53,代碼來源:notification_service.py

示例3: __init__

 def __init__(self):
     self._load_config()
     self.douban = Douban(self.email, self.password, self.user_id, self.expire, self.token, self.user_name)
     self.player = Player()
     self.current_channel = 0
     self.current_song = None
     self.current_play_list = None
     self.get_channels()
     
     self.palette = [('selected', 'bold', 'default'),
                     ('title', 'yellow', 'default')]
     self.selected_button = None
     self.main_loop = None
     self.song_change_alarm = None
     
     if self.scrobbling:
         self.scrobbler = Scrobbler(self.last_fm_username, self.last_fm_password)
         r =  self.scrobbler.handshake()
         if r:
             print("Last.FM logged in.")
         else:
             print("Last.FM login failed")
     if self.douban_account:
         r, err = self.douban.do_login()
         if r:
             print("Douban logged in.")
             self._save_cache()
         else:
             print("Douban login failed: " + err)
開發者ID:beanmoon,項目名稱:pyfm,代碼行數:29,代碼來源:pyfm.py

示例4: run

	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()
開發者ID:darnyte,項目名稱:script.trakt,代碼行數:28,代碼來源:notification_service.py

示例5: run

	def run(self):
		#while xbmc is running
		self._scrobbler = Scrobbler()
		self._scrobbler.start()
		while not (self._abortRequested or xbmc.abortRequested):
			try:
				#try to connect, catch errors and retry every 5 seconds
				telnet = telnetlib.Telnet(self.TELNET_ADDRESS, self.TELNET_PORT)
				
				#if connection succeeds
				while not (self._abortRequested or xbmc.abortRequested):
					try:
						#read notification data
						data = self._readNotification(telnet)
						Debug("[Notification Service] message: " + str(data))
						self._forward(data)
					except EOFError:
						#if we end up here, it means the connection was lost or reset,
						# so we empty out the buffer, and exit this loop, which retries
						# the connection in the outer loop
						self._notificationBuffer = ""
						break
			except:
				time.sleep(5)
				continue


		telnet.close()
		self._scrobbler.abortRequested = True
		Debug("Notification service stopping")
開發者ID:koying,項目名稱:script.trakt,代碼行數:30,代碼來源:notification_service.py

示例6: main

class main():
    ## The Constructor
    # @param self Object pointer
    # @param pyjama Reference to the pyjama object
    def __init__(self, pyjama):
        self.pyjama = pyjama
        self.Events = self.pyjama.Events

        self.Events.connect_event("nowplaying", self.ev_nowplaying)
        self.Events.connect_event('player-status', self.ev_player_status)

        self.pyjama.preferences.register_plugin("LastFM", self.create_preferences, self.save_preferences)

        # login to last.fm
        self.scrobbler = None

        if self.get_session():
            logging.debug('last.fm plugin loaded')
        else:
            logging.debug('last.fm plugin loaded but scrobbling isn\'t available')
        
            #raise

        self.last_scrobbled = None

#    def get_session(self):
#        thr = Thread(target = self.get_session_do, args = ())
#        thr.start()
    @threaded
    def get_session(self):
        if self.pyjama.settings.get_value('LASTFM','SCROBBLING'):

            login=str(self.pyjama.settings.get_value('LASTFM','LOGIN'))
            password=str(self.pyjama.settings.get_value('LASTFM','PASS'))

            try:
                # pyjama has own last.fm clien id 'pyj'
                self.scrobbler=Scrobbler(client=('pyj',VERSION))
                self.scrobbler.login(login, password)
            except Exception, e:
                logging.error(e)
                self.scrobbler=None
                return False
            else:
                #self.logged=True
                return True
        else:
開發者ID:hsbp,項目名稱:burnstation2,代碼行數:47,代碼來源:__init__.py

示例7: __init__

    def __init__(self):
        self.email = None
        self.password = None
        self.user_name = None
        self.user_id = None
        self.expire = None
        self.token = None
        self.cookies = None
        
        self.last_fm_username = None
        self.last_fm_password = None
        self.scrobbling = True
        self.douban_account = True
        self.channels = None
        
        # Set up config
        try:
            arg = sys.argv[1]
            self._do_config()
        except IndexError:
            self._load_config()
        
        # Init API tools
        self.douban = Douban(
            self.email, self.password, self.user_id, self.expire, self.token, self.user_name, self.cookies)
        self.player = Player()
        self.current_channel = 0
        self.current_song = None
        self.current_play_list = None

        # Init terminal ui
        self.palette = [('selected', 'bold', 'default'),
                        ('title', 'yellow', 'default')]
        self.selected_button = None
        self.main_loop = None
        self.song_change_alarm = None
        
        # Try to login
        if self.last_fm_username is None or self.last_fm_username == "":
            self.scrobbling = False
        if (self.email is None or self.email == "") and self.cookies == None:
            self.douban_account = False
            
        if self.scrobbling:
            self.scrobbler = Scrobbler(
                self.last_fm_username, self.last_fm_password)
            r, err = self.scrobbler.handshake()
            if r:
                print("Last.FM 已登陸")
            else:
                print("Last.FM 登錄失敗: " + err)
        if self.douban_account:
            r, err = self.douban.do_login()
            if r:
                print("Douban 已登陸")
            else:
                print("Douban 登錄失敗: " + err)
        self.get_channels()
        self._save_cache()
開發者ID:JamesTing,項目名稱:pyfm,代碼行數:59,代碼來源:pyfm.py

示例8: run

	def run(self):
		startup_delay = utilities.getSettingAsInt('startup_delay')
		if startup_delay:
			utilities.Debug("Delaying startup by %d seconds." % startup_delay)
			xbmc.sleep(startup_delay * 1000)

		utilities.Debug("Service thread starting.")
		
		# setup event driven classes
		self.Player = traktPlayer(action = self._dispatchQueue)
		self.Monitor = traktMonitor(action = self._dispatchQueue)

		# init traktapi class
		globals.traktapi = traktAPI()

		# init sync thread
		self.syncThread = syncThread()

		# init scrobbler class
		self.scrobbler = Scrobbler(globals.traktapi)

		# start loop for events
		while (not xbmc.abortRequested):
			while not self.dispatchQueue.empty() and (not xbmc.abortRequested):
				data = self.dispatchQueue.get()
				utilities.Debug("Queued dispatch: %s" % data)
				self._dispatch(data)

			# check if we were tasked to do a manual sync
			if utilities.getPropertyAsBool('traktManualSync'):
				if not self.syncThread.isAlive():
					utilities.Debug("Performing a manual sync.")
					self.doSync(manual=True)
				else:
					utilities.Debug("There already is a sync in progress.")

				utilities.clearProperty('traktManualSync')

			if xbmc.Player().isPlayingVideo():
				self.scrobbler.update()

			xbmc.sleep(500)

		# we are shutting down
		utilities.Debug("Beginning shut down.")

		# check if watcher is set and active, if so, cancel it.
		if self.watcher:
			if self.watcher.isAlive():
				self.watcher.cancel()

		# delete player/monitor
		del self.Player
		del self.Monitor

		# check if sync thread is running, if so, join it.
		if self.syncThread.isAlive():
			self.syncThread.join()
開發者ID:chx0003,項目名稱:script.trakt,代碼行數:58,代碼來源:service.py

示例9: run

	def run(self):
		startup_delay = utilities.getSettingAsInt('startup_delay')
		if startup_delay:
			utilities.Debug("Delaying startup by %d seconds." % startup_delay)
			xbmc.sleep(startup_delay * 1000)

		utilities.Debug("Service thread starting.")

		# setup event driven classes
		self.Player = traktPlayer(action = self._dispatchQueue)
		self.Monitor = traktMonitor(action = self._dispatchQueue)

		# init traktapi class
		globals.traktapi = traktAPI()

		# init sync thread
		self.syncThread = syncThread()

		# init scrobbler class
		self.scrobbler = Scrobbler(globals.traktapi)

		# init tagging class
		self.tagger = Tagger(globals.traktapi)
		
		# purge queue
		self.dispatchQueue.purge()

		# start loop for events
		while (not xbmc.abortRequested):
			while len(self.dispatchQueue) and (not xbmc.abortRequested):
				data = self.dispatchQueue.get()
				utilities.Debug("Queued dispatch: %s" % data)
				self._dispatch(data)

			if xbmc.Player().isPlayingVideo():
				self.scrobbler.update()

			xbmc.sleep(500)

		# we are shutting down
		utilities.Debug("Beginning shut down.")

		# check if watcher is set and active, if so, cancel it.
		if self.watcher:
			if self.watcher.isAlive():
				self.watcher.cancel()

		# delete player/monitor
		del self.Player
		del self.Monitor

		# check update tags thread.
		if self.updateTagsThread and self.updateTagsThread.isAlive():
			self.updateTagsThread.join()

		# check if sync thread is running, if so, join it.
		if self.syncThread.isAlive():
			self.syncThread.join()
開發者ID:foXaCe,項目名稱:script.trakt,代碼行數:58,代碼來源:service.py

示例10: run

    def run(self):
        startup_delay = kodiUtilities.getSettingAsInt('startup_delay')
        if startup_delay:
            logger.debug("Delaying startup by %d seconds." % startup_delay)
            xbmc.sleep(startup_delay * 1000)

        logger.debug("Service thread starting.")

        # purge queue before doing anything
        self.dispatchQueue.purge()

        # setup event driven classes
        self.Player = traktPlayer(action=self._dispatchQueue)
        self.Monitor = traktMonitor(action=self._dispatchQueue)

        # init traktapi class
        globals.traktapi = traktAPI()

        # init sync thread
        self.syncThread = syncThread()

        # init scrobbler class
        self.scrobbler = Scrobbler(globals.traktapi)

        AddonSignals.registerSlot('service.nextup.notification', 'NEXTUPWATCHEDSIGNAL', self.callback)

        # start loop for events
        while not self.Monitor.abortRequested():
            if not kodiUtilities.getSetting('authorization'):
                last_reminder = kodiUtilities.getSettingAsInt('last_reminder')
                now = int(time.time())
                if last_reminder >= 0 and last_reminder < now - (24 * 60 * 60):
                    gui_utils.get_pin()
                
            while len(self.dispatchQueue) and (not self.Monitor.abortRequested()):
                data = self.dispatchQueue.get()
                logger.debug("Queued dispatch: %s" % data)
                self._dispatch(data)

            if xbmc.Player().isPlayingVideo():
                self.scrobbler.transitionCheck()

            if self.Monitor.waitForAbort(1):
                # Abort was requested while waiting. We should exit
                break

        # we are shutting down
        logger.debug("Beginning shut down.")

        # delete player/monitor
        del self.Player
        del self.Monitor

        # check if sync thread is running, if so, join it.
        if self.syncThread.isAlive():
            self.syncThread.join()
開發者ID:ScriptUp,項目名稱:script.trakt,代碼行數:56,代碼來源:service.py

示例11: setup_scrobbler

    def setup_scrobbler(api_key, shared_secret, username, password,
                        max_retries, max_retry_delay):
        """Returns Last.fm scrobbler.

        Keyword argument(s):
        api_key -- Last.fm API key
        shared_secret -- Last.fm API shared secret
        username -- Last.fm username
        password -- Last.fm password
        max_retries -- Maximum number of retries
        max_delay -- Maximum delay between retries
        """
        scrobbler = Scrobbler(api_key, shared_secret, max_retries,
                              max_retry_delay)
        result = scrobbler.authenticate(username, password)
        if not result:
            log.error("Last.fm authentication failed")
            sys.exit(errno.EACCES)
        return scrobbler
開發者ID:sral,項目名稱:patsy,代碼行數:19,代碼來源:patsy.py

示例12: run

    def run(self):
        startup_delay = utilities.getSettingAsInt('startup_delay')
        if startup_delay:
            logger.debug("Delaying startup by %d seconds." % startup_delay)
            xbmc.sleep(startup_delay * 1000)

        logger.debug("Service thread starting.")

        # purge queue before doing anything
        self.dispatchQueue.purge()

        # setup event driven classes
        self.Player = traktPlayer(action=self._dispatchQueue)
        self.Monitor = traktMonitor(action=self._dispatchQueue)

        # init traktapi class
        globals.traktapi = traktAPI()

        # init sync thread
        self.syncThread = syncThread()

        # init scrobbler class
        self.scrobbler = Scrobbler(globals.traktapi)

        # start loop for events
        while not xbmc.abortRequested:
            if not utilities.getSetting('authorization'):
                last_reminder = utilities.getSettingAsInt('last_reminder')
                now = int(time.time())
                if last_reminder >= 0 and last_reminder < now - (24 * 60 * 60):
                    gui_utils.get_pin()
                
            while len(self.dispatchQueue) and (not xbmc.abortRequested):
                data = self.dispatchQueue.get()
                logger.debug("Queued dispatch: %s" % data)
                self._dispatch(data)

            if xbmc.Player().isPlayingVideo():
                self.scrobbler.transitionCheck()

            xbmc.sleep(500)

        # we are shutting down
        logger.debug("Beginning shut down.")

        # delete player/monitor
        del self.Player
        del self.Monitor

        # check if sync thread is running, if so, join it.
        if self.syncThread.isAlive():
            self.syncThread.join()
開發者ID:beljim,項目名稱:tknorris-beta-repo,代碼行數:52,代碼來源:service.py

示例13: login_lastfm

 def login_lastfm(self):
     '''Last.fm登陸'''
     if self.lastfm and self.last_fm_username and self.last_fm_password:
         self.scrobbler = Scrobbler(
             self.last_fm_username, self.last_fm_password)
         r, err = self.scrobbler.handshake()
         if r:
             logger.info("Last.fm login succeeds!")
             print '\033[31m♥\033[0m Last.fm logged in: %s' % self.last_fm_username
         else:
             logger.error("Last.fm login fails: " + err)
             self.lastfm = False
     else:
         self.lastfm = False
開發者ID:jamesblunt,項目名稱:douban.fm,代碼行數:14,代碼來源:douban_token.py

示例14: get_session

    def get_session(self):
        if self.pyjama.settings.get_value('LASTFM','SCROBBLING'):

            login=str(self.pyjama.settings.get_value('LASTFM','LOGIN'))
            password=str(self.pyjama.settings.get_value('LASTFM','PASS'))

            try:
                # pyjama has own last.fm clien id 'pyj'
                self.scrobbler=Scrobbler(client=('pyj',VERSION))
                self.scrobbler.login(login, password)
            except Exception, e:
                logging.error(e)
                self.scrobbler=None
                return False
            else:
                #self.logged=True
                return True
開發者ID:hsbp,項目名稱:burnstation2,代碼行數:17,代碼來源:__init__.py

示例15: get_session

    def get_session(self):
        if self.pyjama.settings.get_value("LIBREFM", "SCROBBLING"):

            login = str(self.pyjama.settings.get_value("LIBREFM", "LOGIN"))
            password = str(self.pyjama.settings.get_value("LIBREFM", "PASS"))

            try:
                # pyjama has own libre.fm clien id 'pyj'
                self.scrobbler = Scrobbler(client=("pyj", VERSION))
                self.scrobbler.login(login, password)
            except Exception, e:
                logging.error(e)
                self.scrobbler = None
                return False
            else:
                # self.logged=True
                return True
開發者ID:potato,項目名稱:burnstation2,代碼行數:17,代碼來源:__init__.py


注:本文中的scrobbler.Scrobbler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。