Spotify: store the Spotify track ID within the Beets DB also for tracks that were matched against Musicbrainz on import
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 31
Description
Currently the Spotify track ID is persisted within the Beets DB only for songs that have been matched against Spotify on import. Others don't have a Spotify ID.
However, it should be possible to associate each song within the Beets library with a Spotify track and persist that information within the Beets DB, ideally including the [audio features](https://github.com/beetbox/beets/blob/6077b7a3a1037abbf046a00fbbc05db0401982a1/beetsplug/spotify.py#L76-L89).
Background / use-cases that rely on this feature:
* I'd like to use the Spotify [audio features](https://github.com/beetbox/beets/blob/6077b7a3a1037abbf046a00fbbc05db0401982a1/beetsplug/spotify.py#L76-L89) for playlist generation within Beets. (Alternatively this information could be retrieved from the audio data using the [xtractor plugin](https://github.com/adamjakab/BeetsPluginXtractor).)
* I'd like to aggregate the Spotify [audio features](https://github.com/beetbox/beets/blob/6077b7a3a1037abbf046a00fbbc05db0401982a1/beetsplug/spotify.py#L76-L89) within my personal playlists in order to discover related song using Spotify's [recommendations API endpoint](https://developer.spotify.com/documentation/web-api/reference/get-recommendations), providing the aggregated features of a playlist as parameters.
* I'd like to be able to export and sync my personal playlists from my Beets library into Spotify (using the persisted Spotify track ID) and share them with other Spotify users.
### Proposed solution
There should be a Beets CLI command to associate each song within the Beets library with a Spotify track by storing the Spotify track ID within a Beets database field, e.g. `spotify_id`. It could as well be implemented within the existing `beet spotify` command that the Beets Spotify plugin implements.
Also, allow incremental matching of Spotify songs so that Spotify is queried only for Beets songs that are not yet associated with Spotify.
Correspondingly, the Spotify track should be associated with each song on import, also in case the song was matched against Musicbrainz. In that case the Spotify [audio features](https://github.com/beetbox/beets/blob/6077b7a3a1037abbf046a00fbbc05db0401982a1/beetsplug/spotify.py#L76-L89) should also be copied into the Beets DB.
### Objective
Associate as many songs within the Beets library as possible with Spotify and persist that information.
#### Goals
Associate as many songs within the Beets library as possible with Spotify and persist that information.
#### Non-goals
More prompts, less automation.
#### Anti-goals
Don't sacrifice/destroy Musicbrainz track associations.
Contributor guide
Research direction
Start with beetsplug/spotify.py, especially the linked audio-feature handling, and inspect the existing beet spotify command. Trace how imported MusicBrainz matches are persisted in the Beets database before deciding where incremental Spotify matching belongs. Done means library songs can be associated with Spotify IDs and relevant audio features without destroying MusicBrainz associations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100