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

Conversation

happiestbee
Copy link

@happiestbee happiestbee commented Oct 16, 2021

Get popularity tag for tracks from track api in Spotify plugin

Fixes #4094 .

Makes use of the popularity information for tracks

To Do

  • Documentation. (If you've add a new command-line flag, for example, find the appropriate page under docs/ to describe it.)
  • Changelog. (Add an entry to docs/changelog.rst near the top of the document.)
  • Tests. (Encouraged but not strictly required.)

beets/library.py Outdated
@@ -511,6 +511,7 @@ class Item(LibModel):
'releasegroupdisambig': types.STRING,
'disctitle': types.STRING,
'encoder': types.STRING,
'popularity': types.INTEGER,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if we should use spotify_popularity as the label. LastFm also provides popularity values.

Copy link
Author

Choose a reason for hiding this comment

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

No problem, it should be changed now

@sampsyo
Copy link
Member

sampsyo commented Oct 16, 2021

Seems good overall to me! Can you also please add a changelog entry?

@happiestbee
Copy link
Author

Seems good overall to me! Can you also please add a changelog entry?

Ok, that should be done

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Thanks! Giving this a more thorough read a second time through, I see a couple of changes that would be useful. In particular, I think that the plugin should "own" this flexible attribute rather than having it baked into beets core. The plugin can provide the integer type for the field.

Also, to confirm, have you been able to try this feature out? That is, have you imported albums tagged with the spotify plugin and witnessed the field being set correctly? It can be useful to see things working at least once (in the absence of tests).

docs/changelog.rst Outdated Show resolved Hide resolved
beets/library.py Outdated Show resolved Hide resolved
beets/autotag/hooks.py Outdated Show resolved Hide resolved
@sampsyo
Copy link
Member

sampsyo commented Oct 25, 2021

Looking pretty good overall… when you get a chance, can you please confirm that this works for you?

@happiestbee
Copy link
Author

Looking pretty good overall… when you get a chance, can you please confirm that this works for you?

I'm not sure how to test if it works or not

@sampsyo
Copy link
Member

sampsyo commented Oct 25, 2021

I think a good way would be to set up the plugin and try using it to tag some music.

@happiestbee
Copy link
Author

Sorry I am not very familiar with this library. When I try tagging some music, it only provides the title and artist, even though it is marked as a recognized by Spotify. I am also unsure how to change the spotify plugin being used when I import beets to be the one with the relevant changes.

@sampsyo
Copy link
Member

sampsyo commented Oct 26, 2021

Well, you'll want to install the source code you have modified (something like pip install -e . can help with that). You can also try exploring the info plugin, which can dump out all the data for a given track after it's imported. (You might also consider calling on the people who originally requested this feature to help test it out.)

@arsaboo
Copy link
Contributor

arsaboo commented Oct 26, 2021

I am absolutely interested in testing it out, but not sure how to go about doing that :(

@sampsyo
Copy link
Member

sampsyo commented Oct 26, 2021

The FAQ has instructions for installing beets from source, which might be a good place to start.

@arsaboo
Copy link
Contributor

arsaboo commented Oct 26, 2021

Ok...so I tried it and here's the error that I am getting:

PS C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts> .\beet import "C:\Users\Alok\Downloads\Test"
Error: MusicBrainz not reachable in get release by ID with query 'b59f6b6e-b6e0-405f-a80c-a1859942a86e'
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts\beet.exe\__main__.py", line 7, in <module>
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\ui\__init__.py", line 1278, in main
    _raw_main(args)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\ui\__init__.py", line 1265, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\ui\commands.py", line 973, in import_func
    import_files(lib, paths, query)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\ui\commands.py", line 943, in import_files
    session.run()
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\importer.py", line 340, in run
    pl.run_parallel(QUEUE_SIZE)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\util\pipeline.py", line 446, in run_parallel
    raise exc_info[1].with_traceback(exc_info[2])
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\util\pipeline.py", line 311, in run
    out = self.coro.send(msg)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\util\pipeline.py", line 193, in coro
    func(*(args + (task,)))
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\importer.py", line 1376, in lookup_candidates
    task.lookup_candidates()
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\importer.py", line 660, in lookup_candidates
    autotag.tag_album(self.items, search_ids=self.search_ids)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\autotag\match.py", line 461, in tag_album
    for matched_candidate in hooks.album_candidates(items,
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\plugins.py", line 573, in decorated
    for v in generator(*args, **kwargs):
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\autotag\hooks.py", line 629, in album_candidates
    yield from plugins.candidates(items, artist, album, va_likely,
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\plugins.py", line 384, in candidates
    yield from plugin.candidates(items, artist, album, va_likely,
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\plugins.py", line 733, in candidates
    albums = [self.album_for_id(album_id=r['id']) for r in results]
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beets\plugins.py", line 733, in <listcomp>
    albums = [self.album_for_id(album_id=r['id']) for r in results]
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beetsplug\spotify.py", line 200, in album_for_id
    track = self._get_track(track_data)
  File "C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\beetsplug\spotify.py", line 246, in _get_track
    spotify_popularity=track_data['popularity'],
KeyError: 'popularity'

@happiestbee
Copy link
Author

happiestbee commented Oct 26, 2021

Yeah I got that same error when testing but I'm not sure why that is happening.
Taking a look at the track_data argument, the response does not match the response shown in the spotify api get track response which is listed as the parameter type. So, while the response shown in the spotify api documentation has a popularity key for tracks, the actual response that the plugin gets does not. I'm not sure what is causing this difference.
The attached screenshot shows the track_data that the plugin is using, which is notably missing many keys
image

@arsaboo
Copy link
Contributor

arsaboo commented Oct 26, 2021

Ok...I did some more digging and looks like the popularity information may require an extra API call per track.

curl --request GET 'https://api.spotify.com/v1/tracks/6JUQViD0hLXlvWXCV4uUF8' --header "Authorization: Bearer XYZXYZ"
{
  "album" : {
    "album_type" : "album",
    "artists" : [ {
      "external_urls" : {
        "spotify" : "https://open.spotify.com/artist/0LyfQWJT6nXafLPZqxe9Of"
      },
      "href" : "https://api.spotify.com/v1/artists/0LyfQWJT6nXafLPZqxe9Of",
      "id" : "0LyfQWJT6nXafLPZqxe9Of",
      "name" : "Various Artists",
      "type" : "artist",
      "uri" : "spotify:artist:0LyfQWJT6nXafLPZqxe9Of"
    } ],
    "available_markets" : [ "AD", "AE", "AG", "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BN", "BO", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CH", "CI", "CL", "CM", "CO", "CR", "CV", "CW", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FJ", "FM", "FR", "GA", "GB", "GD", "GE", "GH", "GM", "GN", "GQ", "GR", "GT", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MG", "MH", "MK", "ML", "MN", "MO", "MR", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NZ", "OM", "PA", "PE", "PG", "PH", "PK", "PL", "PS", "PT", "PW", "PY", "QA", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SE", "SG", "SI", "SK", "SL", "SM", "SN", "SR", "ST", "SV", "SZ", "TD", "TG", "TH", "TL", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VC", "VN", "VU", "WS", "XK", "ZA", "ZM", "ZW" ],
    "external_urls" : {
      "spotify" : "https://open.spotify.com/album/2ifXB65SLpF97vWZjKGpQ9"
    },
    "href" : "https://api.spotify.com/v1/albums/2ifXB65SLpF97vWZjKGpQ9",
    "id" : "2ifXB65SLpF97vWZjKGpQ9",
    "images" : [ {
      "height" : 640,
      "url" : "https://i.scdn.co/image/ab67616d0000b273e4c77dc1b6c85c754f7f136c",
      "width" : 640
    }, {
      "height" : 300,
      "url" : "https://i.scdn.co/image/ab67616d00001e02e4c77dc1b6c85c754f7f136c",
      "width" : 300
    }, {
      "height" : 64,
      "url" : "https://i.scdn.co/image/ab67616d00004851e4c77dc1b6c85c754f7f136c",
      "width" : 64
    } ],
    "name" : "Shiddat",
    "release_date" : "2021-09-22",
    "release_date_precision" : "day",
    "total_tracks" : 7,
    "type" : "album",
    "uri" : "spotify:album:2ifXB65SLpF97vWZjKGpQ9"
  },
  "artists" : [ {
    "external_urls" : {
      "spotify" : "https://open.spotify.com/artist/3pQ4aA7dkolyjUAMrVScgh"
    },
    "href" : "https://api.spotify.com/v1/artists/3pQ4aA7dkolyjUAMrVScgh",
    "id" : "3pQ4aA7dkolyjUAMrVScgh",
    "name" : "Manan Bhardwaj",
    "type" : "artist",
    "uri" : "spotify:artist:3pQ4aA7dkolyjUAMrVScgh"
  } ],
  "available_markets" : [ "AD", "AE", "AG", "AL", "AM", "AO", "AR", "AT", "AU", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BN", "BO", "BR", "BS", "BT", "BW", "BY", "BZ", "CA", "CH", "CI", "CL", "CM", "CO", "CR", "CV", "CW", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "ES", "FI", "FJ", "FM", "FR", "GA", "GB", "GD", "GE", "GH", "GM", "GN", "GQ", "GR", "GT", "GW", "GY", "HK", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IS", "IT", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MG", "MH", "MK", "ML", "MN", "MO", "MR", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NE", "NG", "NI", "NL", "NO", "NP", "NR", "NZ", "OM", "PA", "PE", "PG", "PH", "PK", "PL", "PS", "PT", "PW", "PY", "QA", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SE", "SG", "SI", "SK", "SL", "SM", "SN", "SR", "ST", "SV", "SZ", "TD", "TG", "TH", "TL", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "US", "UY", "UZ", "VC", "VN", "VU", "WS", "XK", "ZA", "ZM", "ZW" ],
  "disc_number" : 1,
  "duration_ms" : 228189,
  "explicit" : false,
  "external_ids" : {
    "isrc" : "INS182101536"
  },
  "external_urls" : {
    "spotify" : "https://open.spotify.com/track/6JUQViD0hLXlvWXCV4uUF8"
  },
  "href" : "https://api.spotify.com/v1/tracks/6JUQViD0hLXlvWXCV4uUF8",
  "id" : "6JUQViD0hLXlvWXCV4uUF8",
  "is_local" : false,
  "name" : "Chitta",
  "popularity" : 64,
  "preview_url" : "https://p.scdn.co/mp3-preview/07ed17823a4678b9e7877caa85ab5c43952cfe8c?cid=3416be3c054d4a9a9ae55e3ef47ce3f9",
  "track_number" : 5,
  "type" : "track",
  "uri" : "spotify:track:6JUQViD0hLXlvWXCV4uUF8"

That information is not available in the album API call.

@rhlahuja indicated this in one of the closed threads. s/he was the last contributor to the Spotify plugin.

@happiestbee
Copy link
Author

happiestbee commented Oct 27, 2021

Ok I can quickly implement a track api call when iterating through the album response then. This will give access to a lot more information about each track

@sampsyo
Copy link
Member

sampsyo commented Oct 27, 2021

OK! As before, it would be great to hear about a demonstration that this has been tried and actually works.

It also adds an extra request per track, I think. That seems like it could slow things down a lot. Do we know how much? If it is indeed much slower, maybe this should be an option (off by default)?

@arsaboo
Copy link
Contributor

arsaboo commented Oct 27, 2021

Agreed on the track API call being optional (configurable). In addition, we need to be sure that this runs outside the importer with beet spotify

@arsaboo
Copy link
Contributor

arsaboo commented Oct 27, 2021

SO, I was able to run the updated code, but I did not see any new popularity field. See the output below (I have the info before and after the import):

PS C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts> .\beet info "C:\Users\Alok\Downloads\Test\Schedule (2021)\Schedule (2021) - Schedule.mp3"
C:\Users\Alok\Downloads\Test\Schedule (2021)\Schedule (2021) - Schedule.mp3
acoustid_fingerprint: AQADtNGehFKkCGl1fGnxB02P_DNcMYfoZBFc5cjyLUN4MYV-RHyqoJJ2PEmO5ujx-AiTD5qTPLjmIaSPMMuDXNiP_7BWHXGLi0dzBs9hRuzwGnmPA-6OfgGPK0Z-qMo3vAh1oumLfGqh6yPCPOg9nDNTWMtWcNcRMlWQnNiOOnqCpnqkoN9xD-4iXXiSBXKCZnxw9jj1DI2PD_3ROJGDWz--o1ZIHaF8DaqOPA_s49nxx9hz9BOJ_riWHA9znEf8BH8OLbVRSVHQnGD0pUdzPeiWHGdVvMhyHf5k7NHxCNfxpELzWHhx5MxxB33g5bFQ8tBzfIPKHE-OZkxInC_6McYhh8mDXDsmKR9-PBIHOzmqPBHyHZeoQF_WIqd49Dma0JmOjgqa8B2YP2he4kmigDdKDo8ZYuOF0keeIBll-AlatsH_4XKOK9HwzGikI3yM5BG-HU80qzhzGZ6oBF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EqECHOACEwIsQAZhSAAhhhBDAAACIEo4ASgYggQACGEENEAAgEYEoxwgwRBAlkiECAAAcIEgQAQpwCwDDBAFBIAGCIIN4A
         acoustid_id: 23f8959b-5b64-4a1a-b8cb-e60f098112f1
               album: Schedule
         albumartist: Tegi Pannu\\Manni Sandhu
        albumartists:
           albumtype: single
            arranger:
                 art: True
              artist: Tegi Pannu, Manni Sandhu
             artists:
            bitdepth: 0
             bitrate: 320000
                 bpm: 0
            channels: 2
                comp: False
                date: 2021-08-20
                 day: 20
                disc: 1
           disctotal: 1
              format: MP3
               genre: Indi Pop
              genres: Indi Pop
               label: Collab Creations Ltd
              length: 148.4277551020408
              lyrics:
    mb_albumartistid: 78sIlhMniFgXlOrNWnPtIl
   mb_albumartistids: 78sIlhMniFgXlOrNWnPtIl
          mb_albumid: 0XtDEAGgkFrbNNaukE8pEF
         mb_artistid: 78sIlhMniFgXlOrNWnPtIl
        mb_artistids: 78sIlhMniFgXlOrNWnPtIl
          mb_trackid: 5eGsHi6RcL33gb9k89UYaB
               month: 8
       original_date: 2021-01-01
       original_year: 2021
          samplerate: 44100
               title: Schedule
               track: 1
          tracktotal: 1
                year: 2021
PS C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts> .\beet import "C:\Users\Alok\Downloads\Test"
Skipped 3 paths.

C:\Users\Alok\Downloads\Test\Schedule (2021) (1 items)
Finding tags for album "Tegi Pannu\\Manni Sandhu - Schedule".
Candidates:
1. Manni Sandhu - Makhaul (27.2%) (id, album, tracks, ...) (2015, GB, Collab Creations Ltd, CCDD00002)
2. Manni Sandhu - Door Ni Kulne (24.1%) (id, album, tracks, ...) (Digital Media, 2010, Brown Boi Music, GB-3LA-10-01012)
3. Manni Sandhu feat. Manjit Pappu - Friday (24.0%) (id, album, tracks, ...) (Digital Media, 2014, XW, Collab Creations Ltd, CCDD00001)
4. Manni Sandhu - Welcome to the Future (17.5%) (missing tracks, id, album, ...) (Digital Media, 2016, IN)
5. Manni Sandhu - My Time (13.2%) (missing tracks, id, album, ...) (CD, 2012, GB, Brown Boi Music)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort? e
Artist: tegi pannu
Album: schedule
Correcting tags from:
    Tegi Pannu\\Manni Sandhu - Schedule
To:
    Tegi Pannu, Manni Sandhu - Schedule
URL:
    https://open.spotify.com/album/0XtDEAGgkFrbNNaukE8pEF
(Similarity: 93.4%) (source, tracks) (Spotify, 2021, Collab Creations Ltd)
 * Schedule -> Schedule (source)
[A]pply, More candidates, Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort? a
PS C:\Users\Alok\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts> .\beet info "C:\Users\Alok\Downloads\Test\Schedule (2021)\Schedule (2021) - Schedule.mp3"
C:\Users\Alok\Downloads\Test\Schedule (2021)\Schedule (2021) - Schedule.mp3
acoustid_fingerprint: AQADtNGehFKkCGl1fGnxB02P_DNcMYfoZBFc5cjyLUN4MYV-RHyqoJJ2PEmO5ujx-AiTD5qTPLjmIaSPMMuDXNiP_7BWHXGLi0dzBs9hRuzwGnmPA-6OfgGPK0Z-qMo3vAh1oumLfGqh6yPCPOg9nDNTWMtWcNcRMlWQnNiOOnqCpnqkoN9xD-4iXXiSBXKCZnxw9jj1DI2PD_3ROJGDWz--o1ZIHaF8DaqOPA_s49nxx9hz9BOJ_riWHA9znEf8BH8OLbVRSVHQnGD0pUdzPeiWHGdVvMhyHf5k7NHxCNfxpELzWHhx5MxxB33g5bFQ8tBzfIPKHE-OZkxInC_6McYhh8mDXDsmKR9-PBIHOzmqPBHyHZeoQF_WIqd49Dma0JmOjgqa8B2YP2he4kmigDdKDo8ZYuOF0keeIBll-AlatsH_4XKOK9HwzGikI3yM5BG-HU80qzhzGZ6oBF-MLxaS-4hlBdPqhjj2EBt6Fifx5cGRR4nxQs6H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ENEAAgEYEoxwgwRBAlkiECAAAcIEgQAQpwCwDDBAFBIAGCIIN4A
         acoustid_id: 23f8959b-5b64-4a1a-b8cb-e60f098112f1
               album: Schedule
         albumartist: Tegi Pannu, Manni Sandhu
        albumartists:
           albumtype: single
            arranger:
                 art: True
              artist: Tegi Pannu, Manni Sandhu
             artists:
            bitdepth: 0
             bitrate: 320000
                 bpm: 0
            channels: 2
                comp: False
                date: 2021-08-20
                 day: 20
                disc: 1
           disctotal: 1
              format: MP3
               genre: Indi Pop
              genres: Indi Pop
               label: Collab Creations Ltd
              length: 148.4277551020408
              lyrics:
    mb_albumartistid: 78sIlhMniFgXlOrNWnPtIl
   mb_albumartistids: 78sIlhMniFgXlOrNWnPtIl
          mb_albumid: 0XtDEAGgkFrbNNaukE8pEF
         mb_artistid: 78sIlhMniFgXlOrNWnPtIl
        mb_artistids: 78sIlhMniFgXlOrNWnPtIl
          mb_trackid: 5eGsHi6RcL33gb9k89UYaB
               month: 8
       original_date: 2021-01-01
       original_year: 2021
          samplerate: 44100
               title: Schedule
               track: 1
          tracktotal: 1
                year: 2021

@arsaboo
Copy link
Contributor

arsaboo commented Oct 27, 2021

@happiestbee Can you confirm if you getting the popularity information? I can try again once I hear from you.

@happiestbee
Copy link
Author

happiestbee commented Oct 27, 2021

I believe it is working on my end

$ beet ls --format='$spotify_popularity'
73
$spotify_popularity
84
68
61
55
71
50
51
70
58
54
55
74
50
57
51
50
64
55
53
51
52
49
52
63
50
51
50
48
50
46
49

@arsaboo
Copy link
Contributor

arsaboo commented Oct 27, 2021

Indeed, I see those too. Looks like it is working

.\beet ls --format='$spotify_popularity'
0
0
0
0
1
1
0
0
0
0
0
0
0
0
1
0
0
0
71
0

For some reason I am not able to find the musiclibrary.blb file to browse the database on my test machine. Can you also see if you get that info with beet info

@arsaboo
Copy link
Contributor

arsaboo commented Oct 27, 2021

Ok...I see the information even in the database:
image
Wondering if this is the reason why it does not show in beet info as the information is saved in item_attributes table.

@@ -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

Copy link
Author

@happiestbee happiestbee left a comment

Choose a reason for hiding this comment

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

These changes have been made

@arsaboo
Copy link
Contributor

arsaboo commented Oct 28, 2021

These changes have been made

Did you push those changes? I still see spotify_popularity=track_data['popularity'], in the code.

@sampsyo
Copy link
Member

sampsyo commented Oct 28, 2021

FWIW, changing apply_item_metadata should not be necessary. Values are already transferred from the TrackInfo object to the Item object here:

item[field] = value

@happiestbee
Copy link
Author

FWIW, changing apply_item_metadata should not be necessary. Values are already transferred from the TrackInfo object to the Item object here:

item[field] = value

So is this feature fine the way it is right now?

@arsaboo
Copy link
Contributor

arsaboo commented Oct 29, 2021

FWIW, changing apply_item_metadata should not be necessary. Values are already transferred from the TrackInfo object to the Item object here:

item[field] = value

But it is currently being added to the item_attributes table and not items. If item_attributes is the right place, then we are fine I guess.

@sampsyo
Copy link
Member

sampsyo commented Oct 29, 2021

It is indeed; that's where flexible (rather than fixed) attributes live.

@happiestbee
Copy link
Author

FWIW, changing apply_item_metadata should not be necessary. Values are already transferred from the TrackInfo object to the Item object here:

item[field] = value

But it is currently being added to the item_attributes table and not items. If item_attributes is the right place, then we are fine I guess.

So is this able to be merged?

@sampsyo
Copy link
Member

sampsyo commented Oct 29, 2021

Well, I would love to see a little more discussion (or implementation) on this point from above:

It also adds an extra request per track, I think. That seems like it could slow things down a lot. Do we know how much? If it is indeed much slower, maybe this should be an option (off by default)?

@happiestbee
Copy link
Author

Well, I would love to see a little more discussion (or implementation) on this point from above:

It also adds an extra request per track, I think. That seems like it could slow things down a lot. Do we know how much? If it is indeed much slower, maybe this should be an option (off by default)?

I'm not sure where to implement this option since the autotagger is not a subcommand of the plugin

@arsaboo
Copy link
Contributor

arsaboo commented Oct 29, 2021

Well, I would love to see a little more discussion (or implementation) on this point from above:

It doesn't look like it is adding more calls right now. Currently, it is just gathering the information available at the time of import (which was available even earlier but was not stored).

@happiestbee
Copy link
Author

Well, I would love to see a little more discussion (or implementation) on this point from above:

It doesn't look like it is adding more calls right now. Currently, it is just gathering the information available at the time of import (which was available even earlier but was not stored).

I did need to add a new call since the track info being passed was actually the track info contained in an album call, which does not contain all info such as the popularity of the track

@arsaboo
Copy link
Contributor

arsaboo commented Oct 30, 2021

While we are at it...can we also save the track_id (maybe part of items table)? We can then use the track_id to get other audio features (in a subsequent PR).

@arsaboo
Copy link
Contributor

arsaboo commented Nov 2, 2021

So, I tested this a little more and it looks like the track API will not work. I started getting 429 errors (API rate limit exceeded) and I am guessing it is because every track is triggering an API call and that can easily exceed the API rate limit for a large album. Instead of track API call, we should use tracks API call that allows multiple tracks (maximum of 50) to be called.

@stale
Copy link

stale bot commented Mar 6, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 6, 2022
@stale stale bot closed this Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spotify: Get track popularity from Spotify
3 participants