kaymmm / rhythmbox-lastfm-sync

GNU General Public License v3.0
1 stars 0 forks source link

Rhythmbox Sync from LastFM

Note: it's easily tweaked for LibreFM etc.

This is project developed for myself to pull external scrobbles to LastFM into the Rhythmbox playcount. If anyone else finds it useful they're welcome to try it out.

It works by connecting to the LastFM api and pulling your recently scrobbled songs. Hopefully those scrobbles came from a music player using the songs from your Rhythmbox library (e.g., on your phone), otherwise it won't be able to find a match. It then edits your Rhythmbox database and updates the playcount accordingly.

Note: Sometimes the matching doesn't work. I've been tweaking the script to try handling cases when they appear, but some may still escape matching.

Installation

  1. This is tested on linux/gnu, based on my own computer setup; not sure if it'll work on other OS, but you can try it by editing sync.py with the appropriate directory structure. All commands assume linux/gnu, edit as appropriate on your own OS.
  2. Requires python3. Not sure what version exactly, but you need a version with configparser built in (or to install it through pip)
  3. git clone the repo; cd to the repo directory.
  4. pip install -r requirements.txt
  5. create rbsync.yaml; you can use sample_config.yaml as a template (e.g., cp sample_config.yaml rbsync.yaml)
  6. locate your rhythmdb.xml database file, probably in ~/.local/share/rhythmbox/rhythmdb.xml
  7. edit rbsync.yaml (or you can use the default values): a. backup: boolean whether to backup the rhythmbox database file before editing it b. limit: maximum number of items to pull from LastFM c. rhythmdb: the path you located in step (4) d. last_update: the epoch time you want to start syncing from
    • you can get the epoch time using something like: > date +%s -d'Jan 1, 2020 03:30:00'
    • by default, the epoch time is 0; feel free to leave this alone and it'll just pull your entire LastFM history (up to limit items)
  8. set up a LastFM developer account (search it on the internet; too lazy to look it up myself)
  9. from ^^ get the api key and api secret; write it down or keep the window open a. the first time you run sync, it'll prompt you for your username, password, and the api key/secret, all of which are required to log in and access your play history
  10. make sure that sync.py is executable: > chmod u+x sync.py
  11. run it! e.g., > ./sync.py; you probably want to quit Rhythmbox before you sync so that your changes register correctly. though it might update automatically?
  12. while it's running, it should output what's going on as it syncs files, along with a check/'x' corresponding to the sync status. 'x' usually means that for whatever reason, the artist/title wasn't found in your library.
  13. after running, it should create a secrets.yaml file adjacent to rbsync.yaml. don't share or git-sync this since it'll store your LastFM api key and password hash (rainbow table attacks?)
  14. if you said yes to backup, it'll create a rhythmdb.xml.backup-(date) file adjacent to your original rhythmdb.xml file. Note: it won't clean old versions, so if you run it often, you'll spam backup files that can get quite large. suggest cleaning out old backups periodically.
  15. if you don't want all the info output, edit sync.py around l40 and change logging.INFO to something else, probably logging.WARNING so you'll still see actual warnings or errors.

Usage

Set up the configuration file rbsync.yaml as described above.

Run sync.py from the command line however you're most comfortable running python scripts.

For example: > ./sync.py (assuming it's been chmodded to execute)

Breaking Change

Converted rbsync.cfg to rbsync.yaml

This was to get rid of a dependency and streamline everything about the configuration file.

To convert:

  1. edit rbsync.cfg
  2. convert every key = val to key: val
  3. get rid of the '[Sync]' at the top
  4. save as rbsync.yaml
  5. that's it.

To-Do/known bugs

Version History

v2.0.0: (breaking changes) Overhaul the configuration file setup and fix album matching

v1.1.1: update dependencies

v1.1.0: (breaking changes) Add configuration file

v0.1.0: Initial commit

LICENSE

see LICENSE (it's GPLv3)