youtubei 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/cjs/music/MusicClient/MusicClient.js +13 -13
  2. package/dist/cjs/music/MusicClient/index.js +0 -1
  3. package/dist/cjs/music/MusicContinuable/MusicContinuable.js +43 -0
  4. package/dist/cjs/music/MusicContinuable/index.js +13 -0
  5. package/dist/cjs/music/{MusicClient/MusicSearchResultParser.js → MusicSearchResult/MusicAllSearchResultParser.js} +29 -22
  6. package/dist/cjs/music/MusicSearchResult/MusicSearchResult.js +92 -0
  7. package/dist/cjs/music/MusicSearchResult/MusicSearchResultParser.js +34 -0
  8. package/dist/cjs/music/MusicSearchResult/index.js +15 -0
  9. package/dist/cjs/music/MusicSearchResult/proto/MusicSearchProto.js +2 -0
  10. package/dist/cjs/music/MusicSearchResult/proto/index.js +35 -0
  11. package/dist/cjs/youtube/BaseChannel/ChannelLive.js +3 -3
  12. package/dist/cjs/youtube/BaseChannel/ChannelShorts.js +7 -7
  13. package/dist/cjs/youtube/BaseChannel/index.js +2 -0
  14. package/dist/cjs/youtube/BaseVideo/BaseVideoParser.js +1 -1
  15. package/dist/cjs/youtube/Client/Client.js +1 -1
  16. package/dist/cjs/youtube/Playlist/PlaylistParser.js +2 -1
  17. package/dist/cjs/youtube/SearchResult/SearchResult.js +1 -1
  18. package/dist/cjs/youtube/SearchResult/proto/index.js +5 -5
  19. package/dist/cjs/youtube/Transcript/proto/TranscriptParamsProto.js +3 -3
  20. package/dist/esm/music/MusicClient/MusicClient.js +15 -14
  21. package/dist/esm/music/MusicClient/index.js +0 -1
  22. package/dist/esm/music/MusicContinuable/MusicContinuable.js +125 -0
  23. package/dist/esm/music/MusicContinuable/index.js +1 -0
  24. package/dist/esm/music/{MusicClient/MusicSearchResultParser.js → MusicSearchResult/MusicAllSearchResultParser.js} +27 -24
  25. package/dist/esm/music/MusicSearchResult/MusicSearchResult.js +169 -0
  26. package/dist/esm/music/MusicSearchResult/MusicSearchResultParser.js +56 -0
  27. package/dist/esm/music/MusicSearchResult/index.js +3 -0
  28. package/dist/esm/music/MusicSearchResult/proto/MusicSearchProto.js +1 -0
  29. package/dist/esm/music/MusicSearchResult/proto/index.js +15 -0
  30. package/dist/esm/youtube/BaseChannel/ChannelLive.js +3 -3
  31. package/dist/esm/youtube/BaseChannel/ChannelShorts.js +7 -7
  32. package/dist/esm/youtube/BaseChannel/index.js +2 -0
  33. package/dist/esm/youtube/BaseVideo/BaseVideoParser.js +1 -1
  34. package/dist/esm/youtube/Client/Client.js +1 -1
  35. package/dist/esm/youtube/Playlist/PlaylistParser.js +3 -2
  36. package/dist/esm/youtube/SearchResult/SearchResult.js +1 -1
  37. package/dist/esm/youtube/SearchResult/proto/index.js +2 -2
  38. package/dist/esm/youtube/Transcript/proto/TranscriptParamsProto.js +2 -2
  39. package/dist/typings/music/MusicBaseArtist/MusicBaseArtist.d.ts +1 -1
  40. package/dist/typings/music/MusicClient/MusicClient.d.ts +2 -0
  41. package/dist/typings/music/MusicClient/index.d.ts +0 -1
  42. package/dist/typings/music/MusicContinuable/MusicContinuable.d.ts +24 -0
  43. package/dist/typings/music/MusicContinuable/index.d.ts +1 -0
  44. package/dist/typings/music/{MusicClient/MusicSearchResultParser.d.ts → MusicSearchResult/MusicAllSearchResultParser.d.ts} +4 -3
  45. package/dist/typings/music/MusicSearchResult/MusicSearchResult.d.ts +46 -0
  46. package/dist/typings/music/MusicSearchResult/MusicSearchResultParser.d.ts +13 -0
  47. package/dist/typings/music/MusicSearchResult/index.d.ts +3 -0
  48. package/dist/typings/music/MusicSearchResult/proto/MusicSearchProto.d.ts +14 -0
  49. package/dist/typings/music/MusicSearchResult/proto/index.d.ts +5 -0
  50. package/dist/typings/youtube/BaseChannel/ChannelLive.d.ts +4 -4
  51. package/dist/typings/youtube/BaseChannel/ChannelShorts.d.ts +8 -8
  52. package/dist/typings/youtube/BaseChannel/index.d.ts +2 -0
  53. package/dist/typings/youtube/SearchResult/proto/index.d.ts +2 -41
  54. package/dist/typings/youtube/Transcript/proto/TranscriptParamsProto.d.ts +2 -11
  55. package/package.json +2 -2
@@ -4,6 +4,7 @@ import { MusicAlbumCompact } from "../MusicAlbumCompact";
4
4
  import { MusicArtistCompact } from "../MusicArtistCompact";
5
5
  import { MusicLyrics } from "../MusicLyrics";
6
6
  import { MusicPlaylistCompact } from "../MusicPlaylistCompact";
7
+ import { MusicSearchResult, MusicSearchType } from "../MusicSearchResult";
7
8
  import { MusicVideoCompact } from "../MusicVideoCompact";
8
9
  export declare type MusicClientOptions = {
9
10
  initialCookie: string;
@@ -25,6 +26,7 @@ export declare class MusicClient {
25
26
  *
26
27
  */
27
28
  search(query: string): Promise<Shelf<MusicVideoCompact[] | MusicAlbumCompact[] | MusicPlaylistCompact[] | MusicArtistCompact[]>[]>;
29
+ search<T extends MusicSearchType>(query: string, type: T): Promise<MusicSearchResult<T>>;
28
30
  /**
29
31
  * Get lyrics of a song
30
32
  *
@@ -1,2 +1 @@
1
1
  export * from "./MusicClient";
2
- export * from "./MusicSearchResultParser";
@@ -0,0 +1,24 @@
1
+ import { MusicBase } from "../MusicBase";
2
+ import { MusicClient } from "../MusicClient";
3
+ /** @hidden */
4
+ export declare type FetchResult<T> = {
5
+ items: T[];
6
+ continuation?: string;
7
+ };
8
+ /** @hidden */
9
+ export declare type MusicContinuableConstructorParams = {
10
+ client: MusicClient;
11
+ strictContinuationCheck?: boolean;
12
+ };
13
+ /** Represents a continuable list of items `T` (like pagination) */
14
+ export declare abstract class MusicContinuable<T> extends MusicBase {
15
+ items: T[];
16
+ continuation?: string | null;
17
+ private strictContinuationCheck;
18
+ /** @hidden */
19
+ constructor({ client, strictContinuationCheck }: MusicContinuableConstructorParams);
20
+ /** Fetch next items using continuation token */
21
+ next(count?: number): Promise<T[]>;
22
+ protected abstract fetch(): Promise<FetchResult<T>>;
23
+ private get hasContinuation();
24
+ }
@@ -0,0 +1 @@
1
+ export * from "./MusicContinuable";
@@ -1,12 +1,13 @@
1
1
  import { Shelf, YoutubeRawData } from "../../common";
2
2
  import { MusicAlbumCompact } from "../MusicAlbumCompact";
3
+ import { MusicClient } from "../MusicClient";
3
4
  import { MusicPlaylistCompact } from "../MusicPlaylistCompact";
5
+ import { MusicSongCompact } from "../MusicSongCompact";
4
6
  import { MusicVideoCompact } from "../MusicVideoCompact";
5
- import { MusicClient } from "./MusicClient";
6
- export declare class MusicSearchResultParser {
7
+ export declare class MusicAllSearchResultParser {
7
8
  static parseSearchResult(data: YoutubeRawData, client: MusicClient): Shelf<MusicVideoCompact[] | MusicAlbumCompact[] | MusicPlaylistCompact[]>[];
8
9
  private static parseSearchItem;
9
- private static parseVideoItem;
10
+ static parseVideoItem(item: YoutubeRawData, pageType: string, client: MusicClient): MusicSongCompact | MusicVideoCompact | undefined;
10
11
  private static parsePlaylistItem;
11
12
  private static parseAlbumItem;
12
13
  private static parseArtistItem;
@@ -0,0 +1,46 @@
1
+ import { FetchResult, MusicContinuable, MusicContinuableConstructorParams } from "../MusicContinuable";
2
+ import { MusicSongCompact } from "../MusicSongCompact";
3
+ import { MusicVideoCompact } from "../MusicVideoCompact";
4
+ export declare enum MusicSearchTypeEnum {
5
+ Song = "song",
6
+ Video = "video"
7
+ }
8
+ export declare type MusicSearchType = "song" | "video" | MusicSearchTypeEnum;
9
+ export declare type MusicSearchResultItem<T = "song"> = T extends "song" ? MusicSongCompact : MusicVideoCompact;
10
+ /**
11
+ * Represents search result, usually returned from `client.search();`.
12
+ *
13
+ * {@link MusicSearchResult} is a helper class to manage search result
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const result = await music.search("Keyword", "song");
18
+ *
19
+ * console.log(result.items); // search result from first page
20
+ *
21
+ * let nextSearchResult = await result.next();
22
+ * console.log(nextSearchResult); // search result from second page
23
+ *
24
+ * nextSearchResult = await result.next();
25
+ * console.log(nextSearchResult); // search result from third page
26
+ *
27
+ * console.log(result.items); // search result from first, second, and third page.
28
+ * ```
29
+ *
30
+ * @noInheritDoc
31
+ */
32
+ export declare class MusicSearchResult<T extends MusicSearchType | undefined = "song"> extends MusicContinuable<MusicSearchResultItem<T>> {
33
+ private type;
34
+ /** @hidden */
35
+ constructor({ client }: MusicContinuableConstructorParams);
36
+ /**
37
+ * Initialize data from search
38
+ *
39
+ * @param query Search query
40
+ * @param options Search Options
41
+ *
42
+ * @hidden
43
+ */
44
+ search(query: string, type: MusicSearchType): Promise<MusicSearchResult<T>>;
45
+ protected fetch(): Promise<FetchResult<MusicSearchResultItem<T>>>;
46
+ }
@@ -0,0 +1,13 @@
1
+ import { YoutubeRawData } from "../../common";
2
+ import { MusicClient } from "../MusicClient";
3
+ import { MusicSearchResultItem, MusicSearchType } from "./MusicSearchResult";
4
+ declare type ParseReturnType = {
5
+ data: MusicSearchResultItem[];
6
+ continuation: string | undefined;
7
+ };
8
+ export declare class MusicSearchResultParser {
9
+ static parseInitialSearchResult(data: YoutubeRawData, type: MusicSearchType, client: MusicClient): ParseReturnType;
10
+ static parseContinuationSearchResult(data: YoutubeRawData, type: MusicSearchType, client: MusicClient): ParseReturnType;
11
+ private static parseSearchResult;
12
+ }
13
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from "./MusicAllSearchResultParser";
2
+ export * from "./MusicSearchResult";
3
+ export * from "./MusicSearchResultParser";
@@ -0,0 +1,14 @@
1
+ declare type Options = {
2
+ song?: 1;
3
+ video?: 1;
4
+ };
5
+ declare type MusicSearchOptions = {
6
+ options?: Options;
7
+ };
8
+ declare type MusicSearchParams = {
9
+ params?: MusicSearchOptions;
10
+ };
11
+ export declare type MusicSearchProto = {
12
+ MusicSearchOptions: MusicSearchParams;
13
+ };
14
+ export {};
@@ -0,0 +1,5 @@
1
+ import protobuf from "protobufjs";
2
+ import { MusicSearchType } from "../MusicSearchResult";
3
+ import { MusicSearchProto as ProtoType } from "./MusicSearchProto";
4
+ export declare const MusicSearchProto: protobuf.Type;
5
+ export declare const optionsToProto: (type: MusicSearchType) => ProtoType["MusicSearchOptions"];
@@ -13,15 +13,15 @@ declare type ConstructorParams = ContinuableConstructorParams & {
13
13
  * await channel.live.next();
14
14
  * console.log(channel.live.items) // first 30 live videos
15
15
  *
16
- * let newVideos = await channel.videos.next();
17
- * console.log(newVideos) // 30 loaded videos
16
+ * let newLives = await channel.videos.next();
17
+ * console.log(newLives) // 30 loaded live videos
18
18
  * console.log(channel.live.items) // first 60 live videos
19
19
  *
20
- * await channel.live.next(0); // load the rest of the videos in the channel
20
+ * await channel.live.next(0); // load the rest of the live videos in the channel
21
21
  * ```
22
22
  */
23
23
  export declare class ChannelLive extends Continuable<VideoCompact> {
24
- /** The channel this videos belongs to */
24
+ /** The channel this live videos belongs to */
25
25
  channel?: BaseChannel;
26
26
  /** @hidden */
27
27
  constructor({ client, channel }: ConstructorParams);
@@ -5,23 +5,23 @@ declare type ConstructorParams = ContinuableConstructorParams & {
5
5
  channel?: BaseChannel;
6
6
  };
7
7
  /**
8
- * {@link Continuable} of videos inside a {@link BaseChannel}
8
+ * {@link Continuable} of shorts inside a {@link BaseChannel}
9
9
  *
10
10
  * @example
11
11
  * ```js
12
12
  * const channel = await youtube.findOne(CHANNEL_NAME, {type: "channel"});
13
- * await channel.videos.next();
14
- * console.log(channel.videos.items) // first 30 videos
13
+ * await channel.short.next();
14
+ * console.log(channel.short.items) // first 30 shorts
15
15
  *
16
- * let newVideos = await channel.videos.next();
17
- * console.log(newVideos) // 30 loaded videos
18
- * console.log(channel.videos.items) // first 60 videos
16
+ * let newShorts = await channel.short.next();
17
+ * console.log(newShorts) // 30 loaded shorts
18
+ * console.log(channel.short.items) // first 60 shorts
19
19
  *
20
- * await channel.videos.next(0); // load the rest of the videos in the channel
20
+ * await channel.short.next(0); // load the rest of the shorts in the channel
21
21
  * ```
22
22
  */
23
23
  export declare class ChannelShorts extends Continuable<VideoCompact> {
24
- /** The channel this videos belongs to */
24
+ /** The channel this shorts belongs to */
25
25
  channel?: BaseChannel;
26
26
  /** @hidden */
27
27
  constructor({ client, channel }: ConstructorParams);
@@ -1,4 +1,6 @@
1
1
  export * from "./BaseChannel";
2
2
  export * from "./BaseChannelParser";
3
+ export * from "./ChannelLive";
3
4
  export * from "./ChannelPlaylists";
5
+ export * from "./ChannelShorts";
4
6
  export * from "./ChannelVideos";
@@ -1,44 +1,5 @@
1
- /// <reference types="node" />
1
+ import protobuf from "protobufjs";
2
2
  import { SearchOptions } from "../SearchResult";
3
3
  import { SearchProto as ProtoType } from "./SearchProto";
4
- export declare const SearchProto: {
5
- SearchOptions: {
6
- encode: (obj: {
7
- sortBy?: number | undefined;
8
- options?: {
9
- uploadDate?: number | undefined;
10
- type?: number | undefined;
11
- duration?: number | undefined;
12
- live?: number | undefined;
13
- "4k"?: number | undefined;
14
- hd?: number | undefined;
15
- subtitles?: number | undefined;
16
- creativeCommons?: number | undefined;
17
- "360"?: number | undefined;
18
- vr180?: number | undefined;
19
- "3d"?: number | undefined;
20
- hdr?: number | undefined;
21
- location?: number | undefined;
22
- } | undefined;
23
- }) => Buffer;
24
- decode: (buf: Buffer) => {
25
- sortBy?: number | undefined;
26
- options?: {
27
- uploadDate?: number | undefined;
28
- type?: number | undefined;
29
- duration?: number | undefined;
30
- live?: number | undefined;
31
- "4k"?: number | undefined;
32
- hd?: number | undefined;
33
- subtitles?: number | undefined;
34
- creativeCommons?: number | undefined;
35
- "360"?: number | undefined;
36
- vr180?: number | undefined;
37
- "3d"?: number | undefined;
38
- hdr?: number | undefined;
39
- location?: number | undefined;
40
- } | undefined;
41
- };
42
- };
43
- };
4
+ export declare const SearchProto: protobuf.Type;
44
5
  export declare const optionsToProto: (options: SearchOptions) => ProtoType["SearchOptions"];
@@ -1,16 +1,7 @@
1
- /// <reference types="node" />
1
+ import protobuf from "protobufjs";
2
2
  export declare type TranscriptParams = {
3
3
  TranscriptParams: {
4
4
  videoId: string;
5
5
  };
6
6
  };
7
- export declare const TranscriptParamsProto: {
8
- TranscriptParams: {
9
- encode: (obj: {
10
- videoId: string;
11
- }) => Buffer;
12
- decode: (buf: Buffer) => {
13
- videoId: string;
14
- };
15
- };
16
- };
7
+ export declare const TranscriptParamsProto: protobuf.Type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "youtubei",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Simple package to get information from youtube such as videos, playlists, channels, video information & comments, related videos, up next video, and more!",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -63,6 +63,6 @@
63
63
  "homepage": "https://suspiciouslookingowl.github.io/youtubei",
64
64
  "dependencies": {
65
65
  "node-fetch": "2.6.7",
66
- "protocol-buffers": "5.0.0"
66
+ "protobufjs": "7.2.4"
67
67
  }
68
68
  }