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

Playlist 'trackCount' returning unexpected value #365

Closed
JohnHKoh opened this issue Mar 24, 2023 · 6 comments
Closed

Playlist 'trackCount' returning unexpected value #365

JohnHKoh opened this issue Mar 24, 2023 · 6 comments
Labels
bug Something isn't working yt-update A server-side change caused this issue

Comments

@JohnHKoh
Copy link
Contributor

JohnHKoh commented Mar 24, 2023

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?

@mtbrandao
Copy link

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

@mtbrandao
Copy link

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.

@sigma67
Copy link
Owner

sigma67 commented 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.

@JohnHKoh
Copy link
Contributor Author

JohnHKoh commented 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.

song_count = to_int(
unicodedata.normalize("NFKD", header['secondSubtitle']['runs'][0]['text']))

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?

@JohnHKoh
Copy link
Contributor Author

JohnHKoh commented Mar 24, 2023

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

if len(header['secondSubtitle']['runs']) > 1:
playlist['duration'] = header['secondSubtitle']['runs'][2]['text']

@sigma67
Copy link
Owner

sigma67 commented Mar 25, 2023

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

@sigma67 sigma67 added bug Something isn't working yt-update A server-side change caused this issue labels Mar 25, 2023
@sigma67 sigma67 closed this as completed Mar 25, 2023
lubo added a commit to lubo/useful-scripts that referenced this issue Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working yt-update A server-side change caused this issue
Projects
None yet
Development

No branches or pull requests

3 participants