[GH-ISSUE #787] fix/rework get_charts #501

Closed
opened 2026-02-27 23:01:08 +03:00 by kerem · 7 comments
Owner

Originally created by @MarshallARoss on GitHub (Jul 14, 2025).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/787

Originally assigned to: @sgvictorino on GitHub.

Describe the bug

'get_charts()' function crashes

ytmusicapi version

v1.10.3

To Reproduce

Steps to reproduce the behavior:

  1. Call the 'get_charts()' function
  2. Observe a crash
return ytmusic.get_charts()
           ^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/mixins/explore.py", line 247, in get_charts
    charts["videos"]["items"] = parse_chart(1, parse_video, MTRIR)
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/mixins/explore.py", line 236, in <lambda>
    parse_chart = lambda i, parse_func, key: parse_content_list(
                                             ^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/parsers/browsing.py", line 52, in parse_content_list
    contents.append(parse_func(result[key]))
                    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/parsers/browsing.py", line 119, in parse_video
    videoId = next(
              ^^^^^
StopIteration

I've seen this happen in the past when there is a '/' on a trending song on the charts.

Originally created by @MarshallARoss on GitHub (Jul 14, 2025). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/787 Originally assigned to: @sgvictorino on GitHub. **Describe the bug** 'get_charts()' function crashes **ytmusicapi version** v1.10.3 **To Reproduce** Steps to reproduce the behavior: 1. Call the 'get_charts()' function 3. Observe a crash ``` return ytmusic.get_charts() ^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/mixins/explore.py", line 247, in get_charts charts["videos"]["items"] = parse_chart(1, parse_video, MTRIR) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/mixins/explore.py", line 236, in <lambda> parse_chart = lambda i, parse_func, key: parse_content_list( ^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/parsers/browsing.py", line 52, in parse_content_list contents.append(parse_func(result[key])) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/ytmusicapi/parsers/browsing.py", line 119, in parse_video videoId = next( ^^^^^ StopIteration ``` I've seen this happen in the past when there is a '/' on a trending song on the charts.
kerem 2026-02-27 23:01:08 +03:00
Author
Owner

@sgvictorino commented on GitHub (Jul 24, 2025):

Among other things, they've removed trending videos from the charts page. @sigma67 would a PR that reflects the changes and adds a separate get_trends function to fetch the data from FEmusic_explore be alright?

<!-- gh-comment-id:3114519237 --> @sgvictorino commented on GitHub (Jul 24, 2025): Among other things, they've removed trending videos from the charts page. @sigma67 would a PR that reflects the changes and adds a separate `get_trends` function to fetch the data from [`FEmusic_explore`](https://music.youtube.com/explore#:~:text=Trending,-More) be alright?
Author
Owner

@sigma67 commented on GitHub (Jul 24, 2025):

Yeah I was just checking this. They've shuffled things around quite a bit.

For sure, feel free to send a PR.


I think get_explore as function/API title would match what's shown in the UI. For me it shows

Logged out: as below, but "Top songs" missing.

Logged in:

Ideally that function would return the data being shown.

Not sure if the moods one is worth it since you can get it via get_mood_categories. But might as well return what you get.


get_charts also needs to be adapted to the new data being shown:

Logged out:

  • Video charts
  • Top artists

Logged in/Premium:

  • Daily charts
  • Weekly charts
  • Top artists

Some of the old logic in get_charts might be worth keeping for get_explore, since top songs is still only present when logged in.

<!-- gh-comment-id:3114561440 --> @sigma67 commented on GitHub (Jul 24, 2025): Yeah I was just checking this. They've shuffled things around quite a bit. For sure, feel free to send a PR. -------------- I think `get_explore` as function/API title would match what's shown in the UI. For me it shows **Logged out**: as below, but "Top songs" missing. **Logged in**: - [New albums & singles](https://music.youtube.com/new_releases/albums) - [Top songs](https://music.youtube.com/playlist?list=PL4fGSI1pDJn6KpOXlp0MH8qA9tngXaUJ-) - [Moods & genres](https://music.youtube.com/moods_and_genres) - [Trending](https://music.youtube.com/playlist?list=OLAK5uy_nPQBmQpOIYYxuvYW4gIHsjgDqX9kc--Dg) - [New music videos](https://music.youtube.com/new_releases/videos) Ideally that function would return the data being shown. Not sure if the moods one is worth it since you can get it via `get_mood_categories`. But might as well return what you get. -------------- `get_charts` also needs to be adapted to the new data being shown: **Logged out**: - Video charts - Top artists **Logged in/Premium**: - Daily charts - Weekly charts - Top artists Some of the old logic in `get_charts` might be worth keeping for `get_explore`, since top songs is still only present when logged in.
Author
Owner

@sigma67 commented on GitHub (Jul 26, 2025):

We can also split this into two packages for get_explore and get_charts, since it's quite a bit to change.

<!-- gh-comment-id:3121609705 --> @sigma67 commented on GitHub (Jul 26, 2025): We can also split this into two packages for `get_explore` and `get_charts`, since it's quite a bit to change.
Author
Owner

@sigma67 commented on GitHub (Jul 29, 2025):

This issue is now about returning the contents on: https://music.youtube.com/charts

<!-- gh-comment-id:3134013974 --> @sigma67 commented on GitHub (Jul 29, 2025): This issue is now about returning the contents on: https://music.youtube.com/charts
Author
Owner

@sigma67 commented on GitHub (Jul 30, 2025):

@sgvictorino did you want to tackle either one? sorry if I assigned prematurely

<!-- gh-comment-id:3135346474 --> @sigma67 commented on GitHub (Jul 30, 2025): @sgvictorino did you want to tackle either one? sorry if I assigned prematurely
Author
Owner

@sgvictorino commented on GitHub (Jul 30, 2025):

Yes, I've been working on a PR for both and will hopefully finish it soon. No worries about the assignment!

<!-- gh-comment-id:3136868624 --> @sgvictorino commented on GitHub (Jul 30, 2025): Yes, I've been working on a PR for both and will hopefully finish it soon. No worries about the assignment!
Author
Owner

@sigma67 commented on GitHub (Jul 30, 2025):

Good to know, take the time you need

<!-- gh-comment-id:3137091227 --> @sigma67 commented on GitHub (Jul 30, 2025): Good to know, take the time you need
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ytmusicapi#501
No description provided.