Skip to content

Commit

Permalink
Merge pull request #10 from suzuki3jp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
suzuki3jp authored Jan 22, 2025
2 parents 28852e7 + 8bc6700 commit d010207
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ main();
## Supported endpoints
We are striving to support more endpoints, but currently, there are many unsupported endpoints. If the endpoint you want to use is not supported, please open an [issue](https://github.com/suzuki3jp/youtubes.js/issues/new) to request it. We plan to prioritize adding support for the most requested endpoints.

-: Not available in YouTube Data API
×: Not supported
⚠️: Partially supported
✅: Fully supported
Expand All @@ -73,7 +74,7 @@ We are striving to support more endpoints, but currently, there are many unsuppo
| [Members](https://developers.google.com/youtube/v3/docs/members) | × | - | - | - |
| [MembershipsLevels](https://developers.google.com/youtube/v3/docs/membershipsLevels) | × | - | - | - |
| [PlaylistImages](https://developers.google.com/youtube/v3/docs/playlistImages) | × | × | × | × |
| [PlaylistItems](https://developers.google.com/youtube/v3/docs/playlistItems) | ⚠️ || × | × |
| [PlaylistItems](https://developers.google.com/youtube/v3/docs/playlistItems) | ⚠️ || × | |
| [Playlists](https://developers.google.com/youtube/v3/docs/playlists) |||||
| [Search](https://developers.google.com/youtube/v3/docs/search) | × | - | - | - |
| [Subscriptions](https://developers.google.com/youtube/v3/docs/subscriptions) | × | × | - | × |
Expand Down
14 changes: 10 additions & 4 deletions src/Pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Pagination<T> {

/**
* The total number of results in the result set.
* **NOTE**: This number may be larger than the number of actual retrievable results. The YouTube Data API may not return some playlists (for example, the "Liked videos" playlist). However, the totalResults count may include them.
* @remarks This number may be larger than the number of actual retrievable results. The YouTube Data API may not return some playlists (for example, the "Liked videos" playlist). However, the totalResults count may include them.
*/
public totalResults: number;

Expand Down Expand Up @@ -75,7 +75,9 @@ export class Pagination<T> {

/**
* Fetches the previous page.
* - **NOTE**: This method will use the same quotas as the original request.
*
* @remarks
* - This method will use the same quotas as the original request.
* - Normally, GET requests use a quota of 1 unit, while other methods use 50 units.
* - However, some heavy methods use more than 50 units.
* - See more details on the {@link https://developers.google.com/youtube/v3/determine_quota_cost | YouTube Data API reference}
Expand Down Expand Up @@ -108,7 +110,9 @@ export class Pagination<T> {

/**
* Fetches the next page.
* - **NOTE**: This method will use the same quotas as the original request.
*
* @remarks
* - This method will use the same quotas as the original request.
* - Normally, GET requests use a quota of 1 unit, while other methods use 50 units.
* - However, some heavy methods use more than 50 units.
* - See more details on the {@link https://developers.google.com/youtube/v3/determine_quota_cost | YouTube Data API reference}
Expand Down Expand Up @@ -141,7 +145,9 @@ export class Pagination<T> {

/**
* Fetches all pages data.
* - **NOTE**: This method may consume unnecessary quotas, so be careful when using it in actual applications.
*
* @remarks
* - This method may consume unnecessary quotas, so be careful when using it in actual applications.
* - We strongly recommend fetching the next page based on user actions (e.g., scrolling).
* @returns All pages data in an array. If several items are in a page, this method will return a 2D array. Use `flat()` to convert it to a 1D array.
* @example
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type YouTubesJsErrors = LikelyBugError | YouTubeApiError;
/**
* Represents an error that is likely a bug in the library.
*
* If you encounter this error, please report the issue on [GitHub Issue](https://github.com/suzuki3jp/youtubes.js/issues/new).
* If you encounter this error, please report the issue on {@link https://github.com/suzuki3jp/youtubes.js/issues/new | GitHub Issue}.
*/
export class LikelyBugError implements BaseError {
public type = "LIKELY_BUG";
Expand Down
26 changes: 20 additions & 6 deletions src/managers/PlaylistItemManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export class PlaylistItemManager {

/**
* Retrieves a list of playlist items by a playlist ID.
*
* - The operation uses 1 quota unit.
* @remarks The operation uses 1 quota unit.
*
* {@link https://developers.google.com/youtube/v3/docs/playlistItems/list | YouTube Data API Reference}
* @param playlistId - The ID of the playlist to retrieve items from.
Expand Down Expand Up @@ -77,9 +76,7 @@ export class PlaylistItemManager {

/**
* Adds a item to a playlist.
*
* - The operation uses 50 quota units.
*
* @remarks The operation uses 50 quota units.
* @param options - The options to create a playlist item.
* @returns - The created playlist item.
*/
Expand Down Expand Up @@ -109,6 +106,23 @@ export class PlaylistItemManager {

return Ok(item.data);
}

/**
* Deletes a playlist item by its ID.
* @param id - The ID of the playlist item to delete.
*/
public async deleteById(
id: string,
): Promise<Result<undefined, YouTubesJsErrors>> {
const rawData = await wrapGaxios(
this.client.playlistItems.delete({
id,
}),
);
if (rawData.isErr()) return Err(rawData.data);

return Ok(undefined);
}
}

interface PlaylistItemManagerOptions {
Expand All @@ -129,7 +143,7 @@ export interface CreatePlaylistItemOptions {

/**
* The position of the item in the playlist.
* It must be `0 <= position <= N`, where N is the number of items in the playlist. Otherwise, the YouTube API will return an error.
* @remarks It must be `0 <= position <= N`, where N is the number of items in the playlist. Otherwise, the YouTube API will return an error.
*/
position?: number;
}
8 changes: 6 additions & 2 deletions src/managers/PlaylistManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PlaylistManager {
/**
* Fetches the playlists owned by the authenticated user.
*
* - This operation uses 1 quota unit.
* @remarks This operation uses 1 quota unit.
*
* {@link https://developers.google.com/youtube/v3/docs/playlists/list | YouTube Data API Reference}
* @param pageToken - The token for pagination.
Expand Down Expand Up @@ -83,6 +83,7 @@ export class PlaylistManager {
/**
* Fetches a playlist by its ID.
*
* @remarks
* - This operation uses 1 quota unit.
* - Note: The YouTube API returns empty data instead of an error when a playlist with the specified ID is not found.
*
Expand Down Expand Up @@ -136,6 +137,7 @@ export class PlaylistManager {
/**
* Fetches the playlists of a channel by its ID.
*
* @remarks
* - This operation uses 1 quota unit.
* - Retrieves all playlists when given an authenticated user's channel ID. Otherwise, only public playlists are accessible.
*
Expand Down Expand Up @@ -189,6 +191,7 @@ export class PlaylistManager {
/**
* Creates a playlist.
*
* @remarks
* - This operation uses 50 quota units.
* - There is a limit of approximately 10 playlists per day for creation.
* - For more details, see the issue: https://issuetracker.google.com/issues/255216949
Expand Down Expand Up @@ -227,6 +230,7 @@ export class PlaylistManager {
/**
* Updates a playlist by its ID.
*
* @remarks
* - This operation uses 50 quota units.
* - [If you are submitting an update request, and your request does not specify a value for a property that already has a value, the property's existing value will be deleted.](https://developers.google.com/youtube/v3/docs/playlists/update#request-body)
* - For example, when updating a playlist that has a description set, if you don't specify the `description`, it will be set to an empty string.
Expand Down Expand Up @@ -274,7 +278,7 @@ export class PlaylistManager {
/**
* Deletes a playlist by its ID.
*
* - This operation uses 50 quota units.
* @remarks This operation uses 50 quota units.
*
* {@link https://developers.google.com/youtube/v3/docs/playlists/delete | YouTube Data API Reference}
* @param playlistId - The ID of the playlist.
Expand Down

0 comments on commit d010207

Please sign in to comment.