Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def scrobble(info, lastfm_user):
"""Scrobble a song to a given user.
`info` song info dict as represented in Media
`lastfm_user` dict: {'username': xxx, 'password': xxx}
Other methods take care of getting:
- info from songid
- lastfm_user from request.username
"""
for x in ['artist', 'title']:
assert info.get(x), "Missing required field: %s" % x
network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=
API_SECRET, username=lastfm_user.get('username'), password_hash=pylast.md5(lastfm_user.get('password')))
ret = network.scrobble(
info.get('artist'),
info.get('title'),
int(time.time()),
album=info.get('album')
)
print (ret)
cache_location = config['plex-scrobble']['cache_location']
try:
f = io.open(config['plex-scrobble']['mediaserver_log_location'], 'r', encoding='utf-8')
except IOError:
logger.error('Unable to read log-file {0}. Shutting down.'.format(config[
'plex-scrobble']['mediaserver_log_location']))
return
f.seek(0, 2)
try:
lastfm = pylast.LastFMNetwork(
api_key=api_key,
api_secret=api_secret,
username=user_name,
password_hash=pylast.md5(password))
except Exception as e:
logger.error('FATAL {0}. Aborting execution'.format(e))
os._exit(1)
while True:
time.sleep(.03)
# reset our file handle in the event the log file was not written to
# within the last 60 seconds. This is a very crude attempt to support
# the log file i/o rotation detection cross-platform.
if int(time.time()) - int(os.fstat(f.fileno()).st_mtime) >= 60:
if int(os.fstat(f.fileno()).st_mtime) == st_mtime:
continue
`info_l` songs: a list of info dict as represented in Media
`lastfm_user` dict: {'username': xxx, 'password': xxx}
Other methods take care of getting:
- info from songid
- lastfm_user from request.username
"""
for info in info_l:
for x in ['artist', 'title']:
assert info.get(x), "Missing required field: %s" % x
network = ScrobbleNetwork(api_key=API_KEY,
api_secret=API_SECRET,
username=lastfm_user.get('username'),
password_hash=pylast.md5(lastfm_user.get('password'))
)
ret = network.scrobble_many(info_l)
return ret
def init_thread(self):
username = FCBase().lfm_login
password = FCBase().lfm_password
if not username or username == "l_user_" or not password:
logging.debug("No last.fm account provided")
return None
if not self.controls.net_wrapper.is_internet():
# try again...
time.sleep(5)
if not self.controls.net_wrapper.is_internet():
return None
logging.debug("RUN INIT LAST.FM")
password_hash = pylast.md5(password)
self.cache = None
try:
self.network = pylast.get_lastfm_network(api_key=API_KEY,
api_secret=API_SECRET,
username=username,
password_hash=password_hash)
self.cache = Cache(self.network)
"""scrobbler"""
scrobbler_network = pylast.get_lastfm_network(username=username, password_hash=password_hash)
self.scrobbler = scrobbler_network.get_scrobbler("fbx", "1.0")
except:
self.network = None
self.scrobbler = None
self.controls.statusbar.set_text("Error last.fm connection with %s/%s" % (username, FCBase().lfm_password))
logging.error("Either invalid last.fm login or password or network problems")
def check_lastfm_password(password):
if not has_pylast:
msg = "pylast not installed"
return dict(valid=False, message=msg)
password_hash = pylast.md5(password)
return dict(valid=True, value=password_hash)
def on_start(self):
try:
username = settings.LASTFM_USERNAME
password_hash = pylast.md5(settings.LASTFM_PASSWORD)
self.lastfm = pylast.LastFMNetwork(
api_key=API_KEY, api_secret=API_SECRET,
username=username, password_hash=password_hash)
logger.info('Connected to Last.fm')
except exceptions.SettingsError as e:
logger.info('Last.fm scrobbler not started')
logger.debug('Last.fm settings error: %s', e)
self.stop()
except (pylast.NetworkError, pylast.MalformedResponseError,
pylast.WSError) as e:
logger.error('Error during Last.fm setup: %s', e)
self.stop()
def authenticate(self):
'''
authenticate using this linkedopendata account
'''
username = "linkedopendata"
md5_pwd = pylast.md5("nopassword")
self.session_key = pylast.SessionKeyGenerator(API_KEY, API_SECRET).get_session_key(username, md5_pwd)
def __init__(self, username, password, use):
self.__api_key = "3b918147d7533ddb46cbf8c90c7c4b63"
self.__api_secret = "feb61d4de652b7223ab2341a4e436668"
self.__session = None
if use:
import pylast
password_hash = pylast.md5(password)
self.__session = pylast.LastFMNetwork(
api_key = self.__api_key, api_secret = self.__api_secret,
username = username, password_hash = password_hash)
self.enabled = use
self.scrobbles_enabled = use