[GH-ISSUE #365] Playlist 'trackCount' returning unexpected value #291

Closed
opened 2026-02-27 22:09:01 +03:00 by kerem · 6 comments
Owner

Originally created by @JohnHKoh on GitHub (Mar 24, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/365

When using the YTMusic.get_playlist method (documentation), getting the trackCount value from the returned playlist object seems to return an unexpected value. This has only recently started happening.

For example, the playlist ID "PLnlxKMP5GzKCXJ3Cw99qSWgC01cuhTFxG" has 100 songs. However, playlist['trackCount'] returns 13, while len(playlist['tracks']) returns the correct value of 100. This issue first started appearing on March 22, 2023. Before then, trackCount would return the same value as the length of tracks, as expected. I've tried multiple playlist, and none of the trackCount values match up with the number of songs in the playlist. Did YouTube update what trackCount means?

Originally created by @JohnHKoh on GitHub (Mar 24, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/365 When using the `YTMusic.get_playlist` method ([documentation](https://ytmusicapi.readthedocs.io/en/latest/reference.html#ytmusicapi.YTMusic.get_playlist)), getting the `trackCount` value from the returned playlist object seems to return an unexpected value. This has only recently started happening. For example, the playlist ID "PLnlxKMP5GzKCXJ3Cw99qSWgC01cuhTFxG" has 100 songs. However, `playlist['trackCount']` returns 13, while `len(playlist['tracks'])` returns the correct value of 100. This issue first started appearing on March 22, 2023. Before then, `trackCount` would return the same value as the length of `tracks`, as expected. I've tried multiple playlist, and none of the `trackCount` values match up with the number of songs in the playlist. Did YouTube update what `trackCount` means?
kerem 2026-02-27 22:09:01 +03:00
Author
Owner

@mtbrandao commented on GitHub (Mar 24, 2023):

Looking at the web interface, looks like the playlists have a new field called "views".
Example: "7.1K views"

For me, the "trackCount" value matches the "view" value on the web interface

<!-- gh-comment-id:1483245556 --> @mtbrandao commented on GitHub (Mar 24, 2023): Looking at the web interface, looks like the playlists have a new field called "views". Example: "7.1K views" For me, the "trackCount" value matches the "view" value on the web interface
Author
Owner

@mtbrandao commented on GitHub (Mar 24, 2023):

The "get_playlist" function also uses the "trackCount" value to orient itself.
As currently, the track count is wrong, the "get_playlist" function is only returning 100 song maximum.

<!-- gh-comment-id:1483274768 --> @mtbrandao commented on GitHub (Mar 24, 2023): The "get_playlist" function also uses the "trackCount" value to orient itself. As currently, the track count is wrong, the "get_playlist" function is only returning 100 song maximum.
Author
Owner

@sigma67 commented on GitHub (Mar 24, 2023):

I'm not able to reproduce. For me the playlist you provided has a trackCount of 100 and 100 returned playlist items. It's a top 100 playlist, so that's exactly what's expected.

<!-- gh-comment-id:1483291152 --> @sigma67 commented on GitHub (Mar 24, 2023): I'm not able to reproduce. For me the playlist you provided has a `trackCount` of 100 and 100 returned playlist items. It's a top 100 playlist, so that's exactly what's expected.
Author
Owner

@JohnHKoh commented on GitHub (Mar 24, 2023):

Looking at the web interface, looks like the playlists have a new field called "views". Example: "7.1K views"

For me, the "trackCount" value matches the "view" value on the web interface

This is exactly it. I've tried multiple playlists. If it says "8.5K views", trackCount will return 85. If it says "22 views", trackCount will return 22. It seems to be the numeric part of the view count without the decimal.

I'm not able to reproduce. For me the playlist you provided has a trackCount of 100 and 100 returned playlist items. It's a top 100 playlist, so that's exactly what's expected.

I've figured it out. This bug seems to only happen on playlists that you have created. If you use someone else's playlist, trackCount will use the right value. This is because the view count is only shown when viewing your own playlist. Look at the difference when viewing the same playlist in different scenarios:

Logged in:
image

Logged out (incognito):
image

This is the code that needs to be updated.

github.com/sigma67/ytmusicapi@19ad424e0e/ytmusicapi/mixins/playlists.py (L136-L137)

The ['secondSubtitle']['runs'] array looks different based on whether you own a playlist or not.

Here it is when it is someone else's playlist:

[
    {
        "text": "노래 100곡"
    },
    {
        "text": " • "
    },
    {
        "text": "6시간 2분"
    }
]

And here it is when it is your own:

[
    {
        "text": "조회수 13만회"
    },
    {
        "text": " • "
    },
    {
        "text": "노래 100곡"
    },
    {
        "text": " • "
    },
    {
        "text": "6시간 2분"
    }
]

Using the [0] index will return the wrong value for your own playlist. Maybe the length of the runs array could be checked? Or maybe we could use the locale translation for "song", in this case, the Korean "노래", to see which object to extract the number from?

<!-- gh-comment-id:1483416319 --> @JohnHKoh commented on GitHub (Mar 24, 2023): > Looking at the web interface, looks like the playlists have a new field called "views". Example: "7.1K views" > > For me, the "trackCount" value matches the "view" value on the web interface This is exactly it. I've tried multiple playlists. If it says "8.5K views", `trackCount` will return 85. If it says "22 views", `trackCount` will return 22. It seems to be the numeric part of the view count without the decimal. > I'm not able to reproduce. For me the playlist you provided has a `trackCount` of 100 and 100 returned playlist items. It's a top 100 playlist, so that's exactly what's expected. I've figured it out. This bug seems to only happen on playlists that you have created. If you use someone else's playlist, `trackCount` will use the right value. This is because the view count is only shown when viewing your own playlist. Look at the difference when viewing the same playlist in different scenarios: Logged in: ![image](https://user-images.githubusercontent.com/6465531/227643198-31065dd1-3dfb-47fa-acea-8a78de6c677d.png) Logged out (incognito): ![image](https://user-images.githubusercontent.com/6465531/227643264-ef4ae745-8d24-4c76-906d-6e0446d2f352.png) This is the code that needs to be updated. https://github.com/sigma67/ytmusicapi/blob/19ad424e0e59b1908fcb767f8b85a83ecf5ecde2/ytmusicapi/mixins/playlists.py#L136-L137 The `['secondSubtitle']['runs']` array looks different based on whether you own a playlist or not. Here it is when it is someone else's playlist: ``` [ { "text": "노래 100곡" }, { "text": " • " }, { "text": "6시간 2분" } ] ``` And here it is when it is your own: ``` [ { "text": "조회수 13만회" }, { "text": " • " }, { "text": "노래 100곡" }, { "text": " • " }, { "text": "6시간 2분" } ] ``` Using the [0] index will return the wrong value for your own playlist. Maybe the length of the `runs` array could be checked? Or maybe we could use the locale translation for "song", in this case, the Korean ["노래"](https://github.com/sigma67/ytmusicapi/blob/19ad424e0e59b1908fcb767f8b85a83ecf5ecde2/ytmusicapi/locales/ko/LC_MESSAGES/base.po#L30), to see which object to extract the number from?
Author
Owner

@JohnHKoh commented on GitHub (Mar 24, 2023):

This also means that the following lines need to be fixed as well:

github.com/sigma67/ytmusicapi@19ad424e0e/ytmusicapi/mixins/playlists.py (L138-L139)

<!-- gh-comment-id:1483445417 --> @JohnHKoh commented on GitHub (Mar 24, 2023): This also means that the following lines need to be fixed as well: https://github.com/sigma67/ytmusicapi/blob/19ad424e0e59b1908fcb767f8b85a83ecf5ecde2/ytmusicapi/mixins/playlists.py#L138-L139
Author
Owner

@sigma67 commented on GitHub (Mar 25, 2023):

I see, they've added view counts to playlists. Will adjust accordingly.

<!-- gh-comment-id:1483767813 --> @sigma67 commented on GitHub (Mar 25, 2023): I see, they've added view counts to playlists. Will adjust accordingly.
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#291
No description provided.