Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add popularity tag #4102

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions beets/autotag/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def __init__(self, title=None, track_id=None, release_track_id=None,
data_source=None, data_url=None, media=None, lyricist=None,
composer=None, composer_sort=None, arranger=None,
track_alt=None, work=None, mb_workid=None,
work_disambig=None, bpm=None, initial_key=None, genre=None,
**kwargs):
work_disambig=None, bpm=None, initial_key=None,
genre=None, **kwargs):
self.title = title
self.track_id = track_id
self.release_track_id = release_track_id
Expand Down
4 changes: 4 additions & 0 deletions beetsplug/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ def album_for_id(self, album_id):
tracks = []
medium_totals = collections.defaultdict(int)
for i, track_data in enumerate(album_data['tracks']['items'], start=1):
track_data = self._handle_response(
requests.get, track_data["href"]
)
track = self._get_track(track_data)
track.index = i
medium_totals[track.medium] += 1
Expand Down Expand Up @@ -243,6 +246,7 @@ def _get_track(self, track_data):
medium_index=track_data['track_number'],
data_source=self.data_source,
data_url=track_data['external_urls']['spotify'],
spotify_popularity=track_data['popularity'],
Copy link
Contributor

@arsaboo arsaboo Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be item.spotify_popularity so that the information is available in the items table. I also think it may be a good idea to save id while we are at it (similar to how MusicBrainz does it).

Maybe @sampsyo can confirm this before you make any changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, I will go ahead and make the changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, is this what you mean?

def apply_item_metadata(item, track_info):
    """Set an item's metadata from its matched TrackInfo object.
    """
    item.artist = track_info.artist
    item.artist_sort = track_info.artist_sort
    item.artist_credit = track_info.artist_credit
    item.title = track_info.title
    item.mb_trackid = track_info.track_id
    item.mb_releasetrackid = track_info.release_track_id
    item.spotify_popularity = track_info.spotify_popularity

)

def track_for_id(self, track_id=None, track_data=None):
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Other new things:
* Permissions plugin now sets cover art permissions to the file permissions.
* :doc:`/plugins/unimported`: Support excluding specific
subdirectories in library.
* :doc:`/plugins/spotify`: We now fetch a ``spotify_popularity`` field.

Bug fixes:

Expand Down