sigma67 / ytmusicapi

Unofficial API for YouTube Music
https://ytmusicapi.readthedocs.io
MIT License
1.71k stars 194 forks source link

[Question] How to add/remove library content #68

Closed tadly closed 3 years ago

tadly commented 4 years ago

The README stats add/remove library content but from reading the tests and the source I can't figure out how to do this. Is this not yet implemented or is the library a "playlist" with a special id or something?

Thanks for the help

sigma67 commented 4 years ago

The library refers to anything that's personalized to the user, such as playlists, songs/artists/albums in the personal library, account history, etc. See here:

tadly commented 4 years ago

Oooooh YTMusic.rate_playlist is what I want I think. Google always implements the weirdest backends :/

Sorry for the noise and thanks for the quick reply :)

apastel commented 4 years ago

So, I have the same question as OP. But it seems like OP decided he/she didn't want to add library content after all...

I don't see a function for adding particular songs/albums to your library. Is that currently possible with the API?

sigma67 commented 4 years ago

For songs, use rate_song to like them. For albums, use rate_playlist. Either will add the item to your library.

apastel commented 4 years ago

Ah, ok now I understand why OP said that. It's weird that rating and adding/removing are coupled like that (what if I want to add a song and not have it be 'liked'?) but I imagine that wasn't an implementation decision you made, but more of a backend limitation like OP said. Or maybe just something to get a quick, double-whammie solution.

I know it's been said already but thanks for implementing this. I'm using it to delete all uploads since there's no button for that yet: https://github.com/apastel/ytmusic-deleter

sigma67 commented 4 years ago

It's entirely the YT backend. All this API does is emulate requests that happen on the web interface. Essentially I look at what happens when you press a button there and emulate that call in Python.

Regarding the rating = adding to library, I suppose it has to do with the way they do recommendations. You can also dislike albums and playlists with the API, one of the few things that isn't possible in the web interface (that I know of). This affects your recommendations.

phirestalker commented 3 years ago

Either something is wrong on my end or I don't understand something. I have used the API to like songs. When I go into the web interface it is in liked songs, but not all of them end up in the library. By this, I mean that the right-click menu still has the option "add to library." Does this mean what I understand as add to library in the context of this API and thread question is different? Did they recently change how they do things? Also, I looked at the request in Firefox after I press "add to library" on a song, and instead of making a call to /youtubei/v1/like/like? (like it does for a thumbs up), it makes a call to /youtubei/v1/feedback. So, there seems to be something separate going on in the background.

sigma67 commented 3 years ago

I believe they should still be added to your library if you like them. I just tried and after liking, it didn't show up in "Recently added" library, but when sorting by A-Z it showed up.

And I don't think you are able to add individual songs to the library without liking them? At least there's no option in the context menu.

phirestalker commented 3 years ago

Could it be different for me because I have a subscription? I'm not sure but it definitely has an add to library option on most songs in the context menu. It doesn't show up on some songs though.

On Mon, Dec 14, 2020, 1:31 PM sigmatics notifications@github.com wrote:

I believe they should still be added to your library if you like them. I just tried and after liking, it didn't show up in "Recently added" library, but when sorting by A-Z it showed up.

And I don't think you are able to add individual songs to the library? At least there's no option in the context menu.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/sigma67/ytmusicapi/issues/68#issuecomment-744692552, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZBOZ2W2BRVXDNUFWUHTULSUZY2DANCNFSM4QN7RDSA .

sigma67 commented 3 years ago

No, I also have a subscription. On second thought the song I mentioned above was probably already in my library since I added its album sometime ago.

Checking other songs I also saw that there is an "Add to library" button on the ones not already in the library. It only seems to apply to actual songs, not YouTube videos of songs. Might need an additional function for the case of adding a song to the library via the feedback endpoint.

sigma67 commented 3 years ago

Thanks again for the heads up @phirestalker , I hope it is implemented properly now.

phirestalker commented 3 years ago

No problem, it confused me at first because liking something really SHOULD add it to the library. This is another example of Google's haphazard programming and planning. I will be testing it out today or tomorrow as I am trying to perfect my script that scans my music files and matches them to their twin in Youtube music and uploads them if they are not found.

phirestalker commented 3 years ago

Yes, it works great. Thanks.

phirestalker commented 3 years ago

It seems that feedbackTokens is missing from tracks returned from get_liked_songs.

phirestalker commented 3 years ago

Sorry forgot the info.

{'videoId': '7ysFgElQtjI', 'title': 'Old Town Road (feat. Billy Ray Cyrus)', 'artists': [{'name': 'Lil Nas X', 'id': 'UCCF_6PwrZf1u70yghKms3Mw'}], 'album': None, 'likeStatus': 'LIKE', 'thumbnails': [{'url': 'https://i.ytimg.com/vi/7ysFgElQtjI/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3mgzzB0Z27bC1TD426pgGsigXeJCA', 'width': 400, 'height': 225}], 'isAvailable': True, 'duration': '2:38'}
Adding song "Old Town Road (feat. Billy Ray Cyrus)" by Lil Nas X: 2:38
Traceback (most recent call last):
  File "ytmusic-sync/./sync.py", line 211, in <module>
    ytmusic.edit_song_library_status(song['feedbackTokens']['add'])
KeyError: 'feedbackTokens'
sigma67 commented 3 years ago

It will not appear on YouTube videos. Only songs that are "proper" songs within YouTube Music. Usually you can tell the difference by looking at the artist name or if they have an album.

phirestalker commented 3 years ago

Oh, I see. I will just skip those then. Thanks.