Package: lfmxtractplus
lfmxtractplusDescriptionlfmxtractplus is a library for extractingLast.fmscrobbles along with spotifyaudio featuresfor use withPandasWorkingThe user's scrobbles are retrieved using last.fm's API with theuser.getRecentTracksendpoint.
As last.fm's API doesn't provide a method to directly retrieve Spotifyaudio featureswe use thesp.search()method to search Spotify for the track's spotifyID (trackID) and use the spotifyID to retrieve the audio feature of each track using thesp.audio_features()method.InstallationIf you already havePythonon your system you can install the library simply by downloading the distribution, unpack it and install in the usual fashion:Changelogv1.2Encapsulate methods inside a classAdded token refreshing for get_playlist()Optimized importsv1.1Added support for outputting logs to a file instead of the consoleFixed progress barsMove timezone out of config.yamlv1.0Initial versionpythonsetup.pyinstallYou can also install it using a popular package manager withpipinstalllfmxtractplusoreasy_installlfmxtractplusDependenciesspotipy>= 2.4.4pandas>= 0.22.0PyYAML>= 5.1.1numpy>= 1.14.0requests>= 2.22.0tqdm>= 4.31.1Quick StartTo get started,simply install lfmxtractplus, initialize with config.yaml, visit the link displayed and login with your Spotify account, copy and paste the redirect url back into the Python prompt
and call methods:importlfmxtractplusaslxpimportpandasaspdlf=lxp.lfmxtractplus('config.yaml')#path to config.yamlscrobbles_dict=lf.generate_dataset(lfusername='madhan_001',pages=0)scrobbles_df=scrobbles_dict['complete']config.yamlThis file must contain the API keys for last.fm and spotify.#spotify api credentials (visit https://developer.spotify.com)sp_cid:#spotify client IDsp_secret:#spotify client secret#last.fm api key (visit https://www.last.fm/api)lf_key:#last.fm API key#filepath for log filelog_path:'\logs\\output.log'#path for output.logDocumentationinitialize(cfgPath)Calls functions needed for initialization, handles loading config file,
initializing logger object, initializing Spotipy object.Visit the link displayed and login with your Spotify account, copy and paste the redirect url back into the Python prompt.To be called before calling other functions.:param cfgPath: filepath for config.yamlgenerate_dataset(lfusername, timezone='Asia/Kolkata', pages=0)Gets user's listening history and enriches it with Spotify audio features.:param lfusername: last.fm username
:param timezone: timezone of the user (must correspond with the timezone in user's settings)
:param pages: number of pages to retrieve, use pages = 0 to retrieve full listening history

:return scrobblesDFdict: dictionary with two dataframes ('complete' with timestamps and 'library' with library contents)Warning : Does not support multiple timezones for scrobblesget_playlist(user='billboard.com', playlist_id='6UeSakyzhiEt4NB3UAd6NQ')Retrieves audio features of a playlist (Billboard Hot 100 is the default playlist):param user: username of the playlist owner
:param playlist_id: playlist id (found at the end of a playlist url)

:return: a dataframe with audio features of a playlistunmapped_tracks(scrobblesDF)Returns a dataframe tracks that couldn't be mapped to spotify.:param scrobblesDF: dataframe with scrobbled tracks and trackIDs

:return scrobblesDF: dataframe containing tracks with no trackIDsExamplesMusic Listening History AnalysisReporting issuesIf you have suggestions, bugs or other issues specific to this library, file an issue on GitHub. Or just send me a pull request.