[GH-ISSUE #453] Can't remove tracks from Liked Music playlist #339

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

Originally created by @adamhl8 on GitHub (Oct 9, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/453

I'm trying to remove all the tracks from my Liked Music playlist. Nothing in that playlist is liked (i.e. I set all tracks to INDIFFERENT), but for some reason some tracks have been manually added.

I tried this:

from ytmusicapi import YTMusic

yt = YTMusic("oauth.json")
liked_music = yt.get_playlist("LM", 500)
tracks = liked_music.get("tracks")
yt.remove_playlist_items("LM", tracks)
Exception: Cannot remove songs, because setVideoId is missing. Do you own this playlist?

Which makes sense, because for some reason when you get the LM playlist it never returns setVideoId. (Also, if I use browser auth the response is exactly the same.)

So as a workaround, I copied all tracks from LM to another playlist and tried this (the track dicts now include setVideoId):

yt = YTMusic("oauth.json")
liked_music = yt.get_playlist("VLPLqdQZy1CRWrVB9w0CbMW5nR2dxIgWD9Mu", 500)
tracks = liked_music.get("tracks")
yt.remove_playlist_items("LM", tracks)
Traceback (most recent call last):
  File "/Users/adam/tools/ytmusic/src/ytmusic/__init__.py", line 9, in <module>
    yt.remove_playlist_items("LM", tracks)
  File "/Users/adam/tools/ytmusic/.venv/lib/python3.11/site-packages/ytmusicapi/mixins/playlists.py", line 376, in remove_playlist_items
    response = self._send_request(endpoint, body)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adam/tools/ytmusic/.venv/lib/python3.11/site-packages/ytmusicapi/ytmusic.py", line 156, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 400: Bad Request.
Request contains an invalid argument.

Seems like YouTube might have some weird rules around modifying LM but I also might be doing something wrong.

Originally created by @adamhl8 on GitHub (Oct 9, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/453 I'm trying to remove all the tracks from my Liked Music playlist. Nothing in that playlist is liked (i.e. I set all tracks to `INDIFFERENT`), but for some reason some tracks have been manually added. I tried this: ```python from ytmusicapi import YTMusic yt = YTMusic("oauth.json") liked_music = yt.get_playlist("LM", 500) tracks = liked_music.get("tracks") yt.remove_playlist_items("LM", tracks) ``` ``` Exception: Cannot remove songs, because setVideoId is missing. Do you own this playlist? ``` Which makes sense, because for some reason when you get the `LM` playlist it never returns `setVideoId`. (Also, if I use browser auth the response is exactly the same.) So as a workaround, I copied all tracks from `LM` to another playlist and tried this (the track dicts now include `setVideoId`): ```python yt = YTMusic("oauth.json") liked_music = yt.get_playlist("VLPLqdQZy1CRWrVB9w0CbMW5nR2dxIgWD9Mu", 500) tracks = liked_music.get("tracks") yt.remove_playlist_items("LM", tracks) ``` ``` Traceback (most recent call last): File "/Users/adam/tools/ytmusic/src/ytmusic/__init__.py", line 9, in <module> yt.remove_playlist_items("LM", tracks) File "/Users/adam/tools/ytmusic/.venv/lib/python3.11/site-packages/ytmusicapi/mixins/playlists.py", line 376, in remove_playlist_items response = self._send_request(endpoint, body) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/adam/tools/ytmusic/.venv/lib/python3.11/site-packages/ytmusicapi/ytmusic.py", line 156, in _send_request raise Exception(message + error) Exception: Server returned HTTP 400: Bad Request. Request contains an invalid argument. ``` Seems like YouTube might have some weird rules around modifying `LM` but I also might be doing something wrong.
kerem 2026-02-27 23:00:16 +03:00
  • closed this issue
  • added the
    invalid
    label
Author
Owner

@sigma67 commented on GitHub (Oct 9, 2023):

That's not how it works, you can't do it that way on the Web UI either (well I guess you can, but under the hood it just does an "unlike").

You have to remote the the track's like using rate_song.

<!-- gh-comment-id:1753370436 --> @sigma67 commented on GitHub (Oct 9, 2023): That's not how it works, you can't do it that way on the Web UI either (well I guess you can, but under the hood it just does an "unlike"). You have to remote the the track's like using `rate_song`.
Author
Owner

@adamhl8 commented on GitHub (Oct 9, 2023):

I did set all tracks to INDIFFERENT using rate_song. However there were still tracks leftover in LM despite none of them being liked. I can manually remove them by clicking the three dots and clicking "Remove from playlist". However, I opened this issue because it doesn't seem possible to remove these tracks using this library.

<!-- gh-comment-id:1753376453 --> @adamhl8 commented on GitHub (Oct 9, 2023): I did set all tracks to `INDIFFERENT` using `rate_song`. However there were still tracks leftover in `LM` despite none of them being liked. I can manually remove them by clicking the three dots and clicking "Remove from playlist". However, I opened this issue because it doesn't seem possible to remove these tracks using this library.
Author
Owner

@sigma67 commented on GitHub (Oct 9, 2023):

Ok that sounds like a bit of an edge case.

  • Did you refresh the playlist after removing the tracks and still seeing them?
  • Can you reproduce the issue?
  • Are you facing the same issue when you manually unlike all the tracks in your Web interface?
<!-- gh-comment-id:1753382539 --> @sigma67 commented on GitHub (Oct 9, 2023): Ok that sounds like a bit of an edge case. - Did you refresh the playlist after removing the tracks and still seeing them? - Can you reproduce the issue? - Are you facing the same issue when you manually unlike all the tracks in your Web interface?
Author
Owner

@adamhl8 commented on GitHub (Oct 9, 2023):

Did you refresh the playlist after removing the tracks and still seeing them?

Yes

Can you reproduce the issue?

I'm not really sure how I ended up with unliked tracks in my liked music playlist in the first place, but no I'm not able to reproduce that.

Are you facing the same issue when you manually unlike all the tracks in your Web interface?

Yes, if I unlike them (or rather, like and then unlike them), they still remain in LM.

I'd imagine this is some weird holdover from an older version of YTM. Probably not worth fixing but hopefully what I posted helps someone if they run into the same thing.

<!-- gh-comment-id:1753387706 --> @adamhl8 commented on GitHub (Oct 9, 2023): > Did you refresh the playlist after removing the tracks and still seeing them? Yes > Can you reproduce the issue? I'm not really sure how I ended up with unliked tracks in my liked music playlist in the first place, but no I'm not able to reproduce that. > Are you facing the same issue when you manually unlike all the tracks in your Web interface? Yes, if I unlike them (or rather, like and then unlike them), they still remain in `LM`. I'd imagine this is some weird holdover from an older version of YTM. Probably not worth fixing but hopefully what I posted helps someone if they run into the same thing.
Author
Owner

@sigma67 commented on GitHub (Oct 9, 2023):

Yes, if I unlike them (or rather, like and then unlike them), they still remain in LM.

But does that remain if you refresh? I would doubt it.

This is mostly a web frontend issue I think, the tracks are not removed immediately after unliking.

And the older tracks may indeed be a holdover, but it's still strange behavior. Let me know if you do find a way to reproduce.

<!-- gh-comment-id:1753393346 --> @sigma67 commented on GitHub (Oct 9, 2023): > Yes, if I unlike them (or rather, like and then unlike them), they still remain in LM. But does that remain if you refresh? I would doubt it. This is mostly a web frontend issue I think, the tracks are not removed immediately after unliking. And the older tracks may indeed be a holdover, but it's still strange behavior. Let me know if you do find a way to reproduce.
Author
Owner

@beanallergy commented on GitHub (Jun 30, 2024):

I also saw similar issues when using rate_song, my code:

yt_pl = yt.get_playlist(playlistId="LM", limit=5000)
liked_tracks_initial: set = yt_pl['tracks']

tracks_rated_count = 0
error_count = 0

for track in liked_tracks_initial:
    print(f"Youtube video to unlike:   {track['title']} (videoId {track['videoId']})")
    try:
        res = yt.rate_song(track["videoId"], "INDIFFERENT")
        # Print response text that would have popped up in web app UI
        print(f"Response: {res['actions'][0]['addToToastAction']['item']['notificationTextRenderer']['successResponseText']['runs']}")
        tracks_rated_count += 1
    except Exception as e:
        print(f"ERROR: (Unliking track {track['videoId']}): {e}")
        error_count += 1        

time.sleep(2)
liked_tracks_final = yt.get_liked_songs(5000)
print(f"Unliked {tracks_rated_count}/{len(liked_tracks_initial)} tracks, encountered {error_count} errors")
print(f"BUT!! Real number of liked tracks left: {len(liked_tracks_final['tracks'])}")

Then I would get this result:

Unliked 37/37 tracks, encountered 0 errors
BUT!! Real number of liked tracks left: 28

I go to the web app and remove some of the problematic tracks manually (3 dots -> "Remove from playlist") and check Developer Tools - Network - Request. Turns out the request payload from web client to /like/removelike API would actually have a different target.videoId from the one I got from get_playlist! This is probably related to the "weird holdover" @adamhl8 mentioned above.

Anyway I don't think this can be fixed in the scope of this repo, but good to know somebody else has experienced the same thing.

Thanks @sigma67 for this API, very useful and easy to get started!

<!-- gh-comment-id:2198633069 --> @beanallergy commented on GitHub (Jun 30, 2024): I also saw similar issues when using `rate_song`, my code: ``` yt_pl = yt.get_playlist(playlistId="LM", limit=5000) liked_tracks_initial: set = yt_pl['tracks'] tracks_rated_count = 0 error_count = 0 for track in liked_tracks_initial: print(f"Youtube video to unlike: {track['title']} (videoId {track['videoId']})") try: res = yt.rate_song(track["videoId"], "INDIFFERENT") # Print response text that would have popped up in web app UI print(f"Response: {res['actions'][0]['addToToastAction']['item']['notificationTextRenderer']['successResponseText']['runs']}") tracks_rated_count += 1 except Exception as e: print(f"ERROR: (Unliking track {track['videoId']}): {e}") error_count += 1 time.sleep(2) liked_tracks_final = yt.get_liked_songs(5000) print(f"Unliked {tracks_rated_count}/{len(liked_tracks_initial)} tracks, encountered {error_count} errors") print(f"BUT!! Real number of liked tracks left: {len(liked_tracks_final['tracks'])}") ``` Then I would get this result: ``` Unliked 37/37 tracks, encountered 0 errors BUT!! Real number of liked tracks left: 28 ``` I go to the web app and remove some of the problematic tracks manually (3 dots -> "Remove from playlist") and check Developer Tools - Network - Request. Turns out the request payload from web client to `/like/removelike` API would actually have a different **`target.videoId`** from the one I got from get_playlist! This is probably related to the "weird holdover" @adamhl8 mentioned above. Anyway I don't think this can be fixed in the scope of this repo, but good to know somebody else has experienced the same thing. Thanks @sigma67 for this API, very useful and easy to get started!
Author
Owner

@apastel commented on GitHub (Jul 22, 2024):

I also noticed the issue with tracks in the "Liked Music" playlist appearing there even though they don't have a Thumbs Up or Down rating. They are songs that I've liked on YouTube. To make them go away, go to your settings within YouTube Music and disable "Show your liked music from YouTube"

image

<!-- gh-comment-id:2243534810 --> @apastel commented on GitHub (Jul 22, 2024): I also noticed the issue with tracks in the "Liked Music" playlist appearing there even though they don't have a Thumbs Up or Down rating. They are songs that I've liked on YouTube. To make them go away, go to your settings within YouTube Music and disable "Show your liked music from YouTube" ![image](https://github.com/user-attachments/assets/afd0568f-791c-407e-99bd-bee50b41cbc6)
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#339
No description provided.