本文整理汇总了Python中pylast.LastFMNetwork方法的典型用法代码示例。如果您正苦于以下问题:Python pylast.LastFMNetwork方法的具体用法?Python pylast.LastFMNetwork怎么用?Python pylast.LastFMNetwork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylast
的用法示例。
在下文中一共展示了pylast.LastFMNetwork方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: song
# 需要导入模块: import pylast [as 别名]
# 或者: from pylast import LastFMNetwork [as 别名]
def song(self, bot, **rest):
try:
import pylast
except ImportError:
log.error("Missing required library for the LastFM Module: pylast")
return False
API_KEY = self.settings["api_key"]
lastfmname = self.settings["username"]
if len(API_KEY) < 10 or len(lastfmname) < 2:
log.warning("You need to set up the Last FM API stuff in the Module settings.")
return False
try:
network = pylast.LastFMNetwork(api_key=API_KEY, api_secret="", username=lastfmname, password_hash="")
user = network.get_user(lastfmname)
currentTrack = user.get_now_playing()
if currentTrack is None:
bot.me(f"{bot.streamer} isn't playing music right now.. FeelsBadMan")
else:
bot.me(f"Current Song is \u2669\u266a\u266b {currentTrack} \u266c\u266b\u2669")
except pylast.WSError:
log.error("LastFm username not found")
except IndexError:
bot.me("I have trouble fetching the song name.. Please try again FeelsBadMan")
示例2: Client
# 需要导入模块: import pylast [as 别名]
# 或者: from pylast import LastFMNetwork [as 别名]
def Client():
global _network
if not _network:
_network = LastFMNetwork(api_key=api_k, api_secret=api_s)
_network.enable_rate_limit()
return _network
示例3: setup_network
# 需要导入模块: import pylast [as 别名]
# 或者: from pylast import LastFMNetwork [as 别名]
def setup_network(self):
api_key = self.settings.get('APIKEY')
api_secret = self.settings.get('APISECRET')
username = self.settings.get('USERNAME')
password = pylast.md5(self.settings.get('PASSWORD'))
net = pylast.LastFMNetwork(api_key=api_key, api_secret=api_secret,
username=username, password_hash=password)
return net
示例4: __init__
# 需要导入模块: import pylast [as 别名]
# 或者: from pylast import LastFMNetwork [as 别名]
def __init__(self, config, cast_name, available_devices=None):
self.cast_name = cast_name
self.cast_config = config.get('chromecast', {})
self.app_whitelist = self.cast_config.get('app_whitelist', APP_WHITELIST)
self.last_scrobbled = {}
self.current_track = {}
self.current_time = 0
self.last_poll = time.time()
self._connect_chromecast(available_devices)
if not self.cast:
raise ChromecastNotFoundException()
self.scrobblers = []
if 'lastfm' in config:
self.scrobblers.append(pylast.LastFMNetwork(
api_key=config['lastfm']['api_key'],
api_secret=config['lastfm']['api_secret'],
username=config['lastfm']['user_name'],
password_hash=pylast.md5(config['lastfm']['password'])))
if 'librefm' in config:
self.scrobblers.append(pylast.LibreFMNetwork(
session_key=config['librefm']['session_key'],
username=config['librefm']['user_name'],
password_hash=pylast.md5(config['librefm']['password'])
))
self.estimate_spotify_timestamp = self.cast_config.get(
'estimate_spotify_timestamp', True)
示例5: __init__
# 需要导入模块: import pylast [as 别名]
# 或者: from pylast import LastFMNetwork [as 别名]
def __init__(self, api_key, api_secret, username, password):
"""
:param api_key: Last.FM API key, see https://www.last.fm/api
:type api_key: str
:param api_secret: Last.FM API secret, see https://www.last.fm/api
:type api_key: str
:param username: Last.FM username
:type api_key: str
:param password: Last.FM password, used to sign the requests
:type api_key: str
"""
import pylast
super().__init__()
self.api_key = api_key
self.api_secret = api_secret
self.username = username
self.password = password
self.lastfm = pylast.LastFMNetwork(
api_key = self.api_key,
api_secret = self.api_secret,
username = self.username,
password_hash = pylast.md5(self.password))
示例6: retry_queue
# 需要导入模块: import pylast [as 别名]
# 或者: from pylast import LastFMNetwork [as 别名]
def retry_queue(self):
self.logger.info('Retrying scrobble cache.')
for key in self.cache:
# do submissions retry
try:
self.cache[key][2] += 1
lastfm = pylast.LastFMNetwork(
api_key=self.api_key,
api_secret=self.api_secret,
username=self.user_name,
password_hash=pylast.md5(self.password))
lastfm.scrobble(self.cache[key][0],
self.cache[key][1],
timestamp=int(time.time()),
album=self.cache[key][3])
except:
self.logger.warning('Failed to resubmit artist={artist}, title={title}, album={album}, age={age}'.format(
artist=self.cache[key][0],
title=self.cache[key][1],
album=self.cache[key][3],
age=self.cache[key][2]))
if self.cache[key][2] >= ScrobbleCache.MAX_CACHE_AGE:
self.logger.info('MAX_CACHE_AGE for {key} : {artist} - {title}'.format(key=key, artist=self.cache[key][0], title=self.cache[key][1]))
self.remove(key)
continue
# successful send to last.fm, remove from cache
self.logger.info('cache resubmit of artist={artist}, title={title}, album={album} age={age}. Removing.'.format(
artist=self.cache[key][0],
title=self.cache[key][1],
album=self.cache[key][3],
age=self.cache[key][2]))
self.remove(key)
self.sync()
示例7: __init__
# 需要导入模块: import pylast [as 别名]
# 或者: from pylast import LastFMNetwork [as 别名]
def __init__(self):
self.credentials = dict({
'username': None,
'password': None,
'api_key': None,
'api_secret': None
})
if args.lastfm_credentials:
with open(args.lastfm_credentials) as f:
self.credentials.update(
{k: v.encode('utf-8') if isinstance(v, unicode) else v
for (k, v)
in json.loads(f.read()).iteritems()})
if args.lastfm_username:
self.credentials['username'] = args.lastfm_username
if args.lastfm_password:
self.credentials['password'] = args.lastfm_password
if args.lastfm_api_key:
self.credentials['api_key'] = args.lastfm_api_key
if args.lastfm_api_secret:
self.credentials['api_secret'] = args.lastfm_api_secret
if not (self.credentials['username'] and
self.credentials['password'] and
self.credentials['api_key'] and
self.credentials['api_secret']):
self.on = False
print 'Last.fm: incomplete credentials, not launched'
return
self.on = True
self.lastfm_network = pylast.LastFMNetwork(
api_key=self.credentials['api_key'],
api_secret=self.credentials['api_secret'],
username=self.credentials['username'],
password_hash=pylast.md5(self.credentials['password'])
)
self.metadata = None
self.timestamp = None
self.playing = bool(lib.SpPlaybackIsPlaying())
self.play_cumul = 0
self.play_beg = time.time()
# This two functions are used to count the playing time of each song