lfmxtractplus is a library for extracting last.fm scrobbles along with spotify audio features for use with pandas
Project description
lfmxtractplus
Description
lfmxtractplus is a library for extracting Last.fm scrobbles along with spotify audio features for use with Pandas
Working
The user's scrobbles are retrieved using last.fm's API with the user.getRecentTracks endpoint. As last.fm's API doesn't provide a method to directly retrieve Spotify audio features we use the sp.search() method to search Spotify for the track's spotifyID (trackID) and use the spotifyID to retrieve the audio feature of each track using the sp.audio_features() method.
Installation
If you already have Python on your system you can install the library simply by downloading the distribution, unpack it and install in the usual fashion:
Changelog
-
v1.2
- Encapsulate methods inside a class
- Added token refreshing for get_playlist()
- Optimized imports
-
v1.1
- Added support for outputting logs to a file instead of the console
- Fixed progress bars
- Move timezone out of config.yaml
-
v1.0
- Initial version
python setup.py install
You can also install it using a popular package manager with
pip install lfmxtractplus
or
easy_install lfmxtractplus
Dependencies
Quick Start
To 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:
import lfmxtractplus as lxp
import pandas as pd
lf = lxp.lfmxtractplus('config.yaml') #path to config.yaml
scrobbles_dict = lf.generate_dataset(lfusername='madhan_001', pages=0)
scrobbles_df = scrobbles_dict['complete']
config.yaml
This file must contain the API keys for last.fm and spotify.
#spotify api credentials (visit https://developer.spotify.com)
sp_cid: #spotify client ID
sp_secret: #spotify client secret
#last.fm api key (visit https://www.last.fm/api)
lf_key: #last.fm API key
#filepath for log file
log_path: '\logs\\output.log' #path for output.log
Documentation
initialize(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.yaml
generate_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 scrobbles
get_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 playlist
unmapped_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 trackIDs
Examples
Reporting issues
If you have suggestions, bugs or other issues specific to this library, file an issue on GitHub. Or just send me a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lfmxtractplus-1.2.tar.gz
.
File metadata
- Download URL: lfmxtractplus-1.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d956f398fa6359402f5891089c4b109a281a4b444ab6434380bfa69576d5478 |
|
MD5 | 4353c55f679e2f8a84c1788752c01b38 |
|
BLAKE2b-256 | c0ddbf0b720de4c8a01747849aa725be1f00852b55fc90a72cba54e78804cccd |
File details
Details for the file lfmxtractplus-1.2-py3-none-any.whl
.
File metadata
- Download URL: lfmxtractplus-1.2-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62669deaa23cbdb84e56ad88374677e44e71f30960c5ed4c816a680af716dddd |
|
MD5 | 6c3308babd979333b3cf017bb7ef63a7 |
|
BLAKE2b-256 | 979200031369d97cfcd725a16454bb1ca4a54efcdcdadbec8ff0192b65bbb512 |