Skip to content

Commit

Permalink
feat(Playlists): Implement addToLibrary and removeFromLibrary (#844)
Browse files Browse the repository at this point in the history
* chore: add possibility to add playlists to user library

* chore: fix playlist dislike endpoint

* chore: adapt to new structure

* refactor: renamed method names
  • Loading branch information
Duell10111 authored Dec 31, 2024
1 parent 6536801 commit 48460e4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/core/managers/PlaylistManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,46 @@ export default class PlaylistManager {
data: response.data
};
}

/**
* Adds a given playlist to the library of a user.
* @param playlist_id - The playlist ID.
*/
async addToLibrary(playlist_id: string){
throwIfMissing({ playlist_id });

if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');

const like_playlist_endpoint = new NavigationEndpoint({
likeEndpoint: {
status: 'LIKE',
target: playlist_id
}
});

return await like_playlist_endpoint.call(this.#actions);
}

/**
* Remove a given playlist to the library of a user.
* @param playlist_id - The playlist ID.
*/
async removeFromLibrary(playlist_id: string){
throwIfMissing({ playlist_id });

if (!this.#actions.session.logged_in)
throw new InnertubeError('You must be signed in to perform this operation.');

const remove_like_playlist_endpoint = new NavigationEndpoint({
likeEndpoint: {
status: 'INDIFFERENT',
target: playlist_id
}
});

return await remove_like_playlist_endpoint.call(this.#actions);
}

/**
* Adds videos to a given playlist.
Expand Down

0 comments on commit 48460e4

Please sign in to comment.