youtubei 0.0.1-rc.9 → 1.0.0-rc.3

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 (225) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +50 -53
  3. package/dist/cjs/classes/Base/Base.js +10 -0
  4. package/dist/cjs/classes/Base/index.js +13 -0
  5. package/dist/cjs/classes/BaseChannel/BaseChannel.js +31 -0
  6. package/dist/cjs/classes/BaseChannel/BaseChannelParser.js +24 -0
  7. package/dist/cjs/classes/BaseChannel/ChannelPlaylists.js +57 -0
  8. package/dist/cjs/classes/BaseChannel/ChannelVideos.js +57 -0
  9. package/dist/cjs/classes/BaseChannel/index.js +16 -0
  10. package/dist/cjs/classes/BaseVideo/BaseVideo.js +34 -0
  11. package/dist/cjs/classes/BaseVideo/BaseVideoParser.js +82 -0
  12. package/dist/cjs/classes/BaseVideo/VideoRelated.js +39 -0
  13. package/dist/cjs/classes/BaseVideo/index.js +15 -0
  14. package/dist/cjs/classes/Channel/Channel.js +24 -0
  15. package/dist/cjs/classes/Channel/ChannelParser.js +55 -0
  16. package/dist/cjs/classes/Channel/index.js +14 -0
  17. package/dist/cjs/classes/Chat/Chat.js +23 -0
  18. package/dist/cjs/classes/Chat/ChatParser.js +21 -0
  19. package/dist/cjs/classes/Chat/index.js +14 -0
  20. package/dist/cjs/classes/Client/Client.js +101 -0
  21. package/dist/cjs/classes/Client/HTTP.js +59 -0
  22. package/dist/cjs/classes/Client/index.js +13 -0
  23. package/dist/cjs/classes/Comment/Comment.js +29 -0
  24. package/dist/cjs/classes/Comment/CommentParser.js +43 -0
  25. package/dist/cjs/classes/Comment/CommentReplies.js +36 -0
  26. package/dist/cjs/classes/Comment/index.js +15 -0
  27. package/dist/cjs/classes/Continuable/Continuable.js +43 -0
  28. package/dist/cjs/classes/Continuable/index.js +13 -0
  29. package/dist/{classes → cjs/classes/LiveVideo}/LiveVideo.js +84 -89
  30. package/dist/cjs/classes/LiveVideo/LiveVideoParser.js +29 -0
  31. package/dist/cjs/classes/LiveVideo/index.js +14 -0
  32. package/dist/cjs/classes/MixPlaylist/MixPlaylist.js +25 -0
  33. package/dist/cjs/classes/MixPlaylist/MixPlaylistParser.js +27 -0
  34. package/dist/cjs/classes/MixPlaylist/index.js +14 -0
  35. package/dist/cjs/classes/Playlist/Playlist.js +25 -0
  36. package/dist/cjs/classes/Playlist/PlaylistParser.js +83 -0
  37. package/dist/cjs/classes/Playlist/PlaylistVideos.js +50 -0
  38. package/dist/cjs/classes/Playlist/index.js +15 -0
  39. package/dist/cjs/classes/PlaylistCompact/PlaylistCompact.js +45 -0
  40. package/dist/cjs/classes/PlaylistCompact/PlaylistCompactParser.js +28 -0
  41. package/dist/cjs/classes/PlaylistCompact/index.js +14 -0
  42. package/dist/cjs/classes/Reply/Reply.js +23 -0
  43. package/dist/cjs/classes/Reply/ReplyParser.js +26 -0
  44. package/dist/cjs/classes/Reply/index.js +14 -0
  45. package/dist/cjs/classes/SearchResult/SearchResult.js +85 -0
  46. package/dist/cjs/classes/SearchResult/SearchResultParser.js +40 -0
  47. package/dist/cjs/classes/SearchResult/index.js +14 -0
  48. package/dist/{classes/Base.js → cjs/classes/SearchResult/proto/SearchProto.js} +2 -5
  49. package/dist/cjs/classes/SearchResult/proto/index.js +57 -0
  50. package/dist/{classes → cjs/classes/Thumbnails}/Thumbnails.js +67 -66
  51. package/dist/cjs/classes/Thumbnails/index.js +13 -0
  52. package/dist/cjs/classes/Video/Video.js +26 -0
  53. package/dist/cjs/classes/Video/VideoComments.js +53 -0
  54. package/dist/cjs/classes/Video/VideoParser.js +29 -0
  55. package/dist/cjs/classes/Video/index.js +15 -0
  56. package/dist/cjs/classes/VideoCompact/VideoCompact.js +49 -0
  57. package/dist/cjs/classes/VideoCompact/VideoCompactParser.js +36 -0
  58. package/dist/cjs/classes/VideoCompact/index.js +14 -0
  59. package/dist/cjs/classes/index.js +29 -0
  60. package/dist/{common → cjs/common}/decorators.js +14 -14
  61. package/dist/cjs/common/helper.js +45 -0
  62. package/dist/{common → cjs/common}/index.js +16 -23
  63. package/dist/{common → cjs/common}/mixins.js +14 -12
  64. package/dist/{common → cjs/common}/types.js +2 -2
  65. package/dist/{constants.js → cjs/constants.js} +10 -10
  66. package/dist/{index.js → cjs/index.js} +13 -13
  67. package/dist/esm/classes/Base/Base.js +8 -0
  68. package/dist/esm/classes/Base/index.js +1 -0
  69. package/dist/esm/classes/BaseChannel/BaseChannel.js +48 -0
  70. package/dist/esm/classes/BaseChannel/BaseChannelParser.js +24 -0
  71. package/dist/esm/classes/BaseChannel/ChannelPlaylists.js +109 -0
  72. package/dist/esm/classes/BaseChannel/ChannelVideos.js +109 -0
  73. package/dist/esm/classes/BaseChannel/index.js +4 -0
  74. package/dist/esm/classes/BaseVideo/BaseVideo.js +51 -0
  75. package/dist/esm/classes/BaseVideo/BaseVideoParser.js +93 -0
  76. package/dist/esm/classes/BaseVideo/VideoRelated.js +87 -0
  77. package/dist/esm/classes/BaseVideo/index.js +3 -0
  78. package/dist/esm/classes/Channel/Channel.js +37 -0
  79. package/dist/esm/classes/Channel/ChannelParser.js +77 -0
  80. package/dist/esm/classes/Channel/index.js +2 -0
  81. package/dist/esm/classes/Chat/Chat.js +36 -0
  82. package/dist/esm/classes/Chat/ChatParser.js +21 -0
  83. package/dist/esm/classes/Chat/index.js +2 -0
  84. package/dist/esm/classes/Client/Client.js +176 -0
  85. package/dist/esm/classes/Client/HTTP.js +112 -0
  86. package/dist/esm/classes/Client/index.js +1 -0
  87. package/dist/esm/classes/Comment/Comment.js +46 -0
  88. package/dist/esm/classes/Comment/CommentParser.js +45 -0
  89. package/dist/esm/classes/Comment/CommentReplies.js +84 -0
  90. package/dist/esm/classes/Comment/index.js +3 -0
  91. package/dist/esm/classes/Continuable/Continuable.js +125 -0
  92. package/dist/esm/classes/Continuable/index.js +1 -0
  93. package/dist/esm/classes/LiveVideo/LiveVideo.js +160 -0
  94. package/dist/esm/classes/LiveVideo/LiveVideoParser.js +29 -0
  95. package/dist/esm/classes/LiveVideo/index.js +2 -0
  96. package/dist/esm/classes/MixPlaylist/MixPlaylist.js +38 -0
  97. package/dist/esm/classes/MixPlaylist/MixPlaylistParser.js +49 -0
  98. package/dist/esm/classes/MixPlaylist/index.js +2 -0
  99. package/dist/esm/classes/Playlist/Playlist.js +38 -0
  100. package/dist/esm/classes/Playlist/PlaylistParser.js +105 -0
  101. package/dist/esm/classes/Playlist/PlaylistVideos.js +98 -0
  102. package/dist/esm/classes/Playlist/index.js +3 -0
  103. package/dist/esm/classes/PlaylistCompact/PlaylistCompact.js +90 -0
  104. package/dist/esm/classes/PlaylistCompact/PlaylistCompactParser.js +28 -0
  105. package/dist/esm/classes/PlaylistCompact/index.js +2 -0
  106. package/dist/esm/classes/Reply/Reply.js +36 -0
  107. package/dist/esm/classes/Reply/ReplyParser.js +26 -0
  108. package/dist/esm/classes/Reply/index.js +2 -0
  109. package/dist/esm/classes/SearchResult/SearchResult.js +161 -0
  110. package/dist/esm/classes/SearchResult/SearchResultParser.js +62 -0
  111. package/dist/esm/classes/SearchResult/index.js +2 -0
  112. package/dist/esm/classes/SearchResult/proto/SearchProto.js +1 -0
  113. package/dist/esm/classes/SearchResult/proto/index.js +39 -0
  114. package/dist/esm/classes/Thumbnails/Thumbnails.js +109 -0
  115. package/dist/esm/classes/Thumbnails/index.js +1 -0
  116. package/dist/esm/classes/Video/Video.js +39 -0
  117. package/dist/esm/classes/Video/VideoComments.js +101 -0
  118. package/dist/esm/classes/Video/VideoParser.js +31 -0
  119. package/dist/esm/classes/Video/index.js +3 -0
  120. package/dist/esm/classes/VideoCompact/VideoCompact.js +98 -0
  121. package/dist/esm/classes/VideoCompact/VideoCompactParser.js +36 -0
  122. package/dist/esm/classes/VideoCompact/index.js +2 -0
  123. package/dist/esm/classes/index.js +17 -0
  124. package/dist/esm/common/decorators.js +30 -0
  125. package/dist/esm/common/helper.js +61 -0
  126. package/dist/esm/common/index.js +4 -0
  127. package/dist/esm/common/mixins.js +10 -0
  128. package/dist/esm/common/types.js +1 -0
  129. package/dist/esm/constants.js +7 -0
  130. package/dist/esm/index.js +1 -0
  131. package/dist/typings/classes/Base/Base.d.ts +11 -0
  132. package/dist/typings/classes/Base/index.d.ts +1 -0
  133. package/dist/typings/classes/BaseChannel/BaseChannel.d.ts +43 -0
  134. package/dist/typings/classes/BaseChannel/BaseChannelParser.d.ts +7 -0
  135. package/dist/typings/classes/BaseChannel/ChannelPlaylists.d.ts +30 -0
  136. package/dist/typings/classes/BaseChannel/ChannelVideos.d.ts +30 -0
  137. package/dist/typings/classes/BaseChannel/index.d.ts +4 -0
  138. package/dist/typings/classes/BaseVideo/BaseVideo.d.ts +59 -0
  139. package/dist/typings/classes/BaseVideo/BaseVideoParser.d.ts +14 -0
  140. package/dist/typings/classes/BaseVideo/VideoRelated.d.ts +21 -0
  141. package/dist/typings/classes/BaseVideo/index.d.ts +3 -0
  142. package/dist/typings/classes/Channel/Channel.d.ts +33 -0
  143. package/dist/typings/classes/Channel/ChannelParser.d.ts +6 -0
  144. package/dist/typings/classes/Channel/index.d.ts +2 -0
  145. package/dist/typings/classes/Chat/Chat.d.ts +33 -0
  146. package/dist/typings/classes/Chat/ChatParser.d.ts +5 -0
  147. package/dist/typings/classes/Chat/index.d.ts +2 -0
  148. package/dist/typings/classes/Client/Client.d.ts +41 -0
  149. package/dist/typings/classes/Client/HTTP.d.ts +21 -0
  150. package/dist/typings/classes/Client/index.d.ts +1 -0
  151. package/dist/typings/classes/Comment/Comment.d.ts +51 -0
  152. package/dist/typings/classes/Comment/CommentParser.d.ts +8 -0
  153. package/dist/typings/classes/Comment/CommentReplies.d.ts +17 -0
  154. package/dist/typings/classes/Comment/index.d.ts +3 -0
  155. package/dist/typings/classes/Continuable/Continuable.d.ts +24 -0
  156. package/dist/typings/classes/Continuable/index.d.ts +1 -0
  157. package/dist/{classes → typings/classes/LiveVideo}/LiveVideo.d.ts +46 -44
  158. package/dist/typings/classes/LiveVideo/LiveVideoParser.d.ts +10 -0
  159. package/dist/typings/classes/LiveVideo/index.d.ts +2 -0
  160. package/dist/typings/classes/MixPlaylist/MixPlaylist.d.ts +29 -0
  161. package/dist/typings/classes/MixPlaylist/MixPlaylistParser.d.ts +6 -0
  162. package/dist/typings/classes/MixPlaylist/index.d.ts +2 -0
  163. package/dist/typings/classes/Playlist/Playlist.d.ts +39 -0
  164. package/dist/typings/classes/Playlist/PlaylistParser.d.ts +16 -0
  165. package/dist/typings/classes/Playlist/PlaylistVideos.d.ts +31 -0
  166. package/dist/typings/classes/Playlist/index.d.ts +3 -0
  167. package/dist/typings/classes/PlaylistCompact/PlaylistCompact.d.ts +43 -0
  168. package/dist/typings/classes/PlaylistCompact/PlaylistCompactParser.d.ts +5 -0
  169. package/dist/typings/classes/PlaylistCompact/index.d.ts +2 -0
  170. package/dist/typings/classes/Reply/Reply.d.ts +43 -0
  171. package/dist/typings/classes/Reply/ReplyParser.d.ts +5 -0
  172. package/dist/typings/classes/Reply/index.d.ts +2 -0
  173. package/dist/typings/classes/SearchResult/SearchResult.d.ts +53 -0
  174. package/dist/typings/classes/SearchResult/SearchResultParser.d.ts +13 -0
  175. package/dist/typings/classes/SearchResult/index.d.ts +2 -0
  176. package/dist/typings/classes/SearchResult/proto/SearchProto.d.ts +13 -0
  177. package/dist/typings/classes/SearchResult/proto/index.d.ts +24 -0
  178. package/dist/{classes → typings/classes/Thumbnails}/Thumbnails.d.ts +41 -42
  179. package/dist/typings/classes/Thumbnails/index.d.ts +1 -0
  180. package/dist/typings/classes/Video/Video.d.ts +24 -0
  181. package/dist/typings/classes/Video/VideoComments.d.ts +34 -0
  182. package/dist/typings/classes/Video/VideoParser.d.ts +8 -0
  183. package/dist/typings/classes/Video/index.d.ts +3 -0
  184. package/dist/typings/classes/VideoCompact/VideoCompact.d.ts +57 -0
  185. package/dist/typings/classes/VideoCompact/VideoCompactParser.d.ts +5 -0
  186. package/dist/typings/classes/VideoCompact/index.d.ts +2 -0
  187. package/dist/typings/classes/index.d.ts +17 -0
  188. package/dist/{common → typings/common}/decorators.d.ts +5 -5
  189. package/dist/typings/common/helper.d.ts +5 -0
  190. package/dist/typings/common/index.d.ts +4 -0
  191. package/dist/typings/common/mixins.d.ts +1 -0
  192. package/dist/{common → typings/common}/types.d.ts +1 -1
  193. package/dist/{constants.d.ts → typings/constants.d.ts} +7 -7
  194. package/dist/{index.d.ts → typings/index.d.ts} +1 -1
  195. package/package.json +68 -53
  196. package/CHANGELOG.md +0 -6
  197. package/dist/classes/Base.d.ts +0 -7
  198. package/dist/classes/BaseVideo.d.ts +0 -54
  199. package/dist/classes/BaseVideo.js +0 -82
  200. package/dist/classes/Channel.d.ts +0 -83
  201. package/dist/classes/Channel.js +0 -138
  202. package/dist/classes/Chat.d.ts +0 -29
  203. package/dist/classes/Chat.js +0 -31
  204. package/dist/classes/Client.d.ts +0 -30
  205. package/dist/classes/Client.js +0 -69
  206. package/dist/classes/Comment.d.ts +0 -43
  207. package/dist/classes/Comment.js +0 -42
  208. package/dist/classes/Playlist.d.ts +0 -61
  209. package/dist/classes/Playlist.js +0 -127
  210. package/dist/classes/PlaylistCompact.d.ts +0 -30
  211. package/dist/classes/PlaylistCompact.js +0 -45
  212. package/dist/classes/SearchResult.d.ts +0 -69
  213. package/dist/classes/SearchResult.js +0 -139
  214. package/dist/classes/Video.d.ts +0 -49
  215. package/dist/classes/Video.js +0 -102
  216. package/dist/classes/VideoCompact.d.ts +0 -40
  217. package/dist/classes/VideoCompact.js +0 -50
  218. package/dist/classes/index.d.ts +0 -13
  219. package/dist/classes/index.js +0 -32
  220. package/dist/common/helper.d.ts +0 -2
  221. package/dist/common/helper.js +0 -37
  222. package/dist/common/http.d.ts +0 -30
  223. package/dist/common/http.js +0 -108
  224. package/dist/common/index.d.ts +0 -5
  225. package/dist/common/mixins.d.ts +0 -2
@@ -1,83 +0,0 @@
1
- import { YoutubeRawData } from "../common";
2
- import { Base, PlaylistCompact, Thumbnails, VideoCompact, BaseAttributes } from ".";
3
- /** @hidden */
4
- interface ChannelAttributes extends BaseAttributes {
5
- name: string;
6
- url: string;
7
- thumbnails: Thumbnails;
8
- videoCount?: number;
9
- }
10
- /** Represents a Youtube Channel */
11
- export default class Channel extends Base implements ChannelAttributes {
12
- /** The channel's name */
13
- name: string;
14
- /** The URL to the channel page */
15
- url: string;
16
- /** Thumbnails of the Channel with different sizes */
17
- thumbnails: Thumbnails;
18
- /** How many video does this channel have */
19
- videoCount?: number;
20
- /** Loaded videos on the channel, fetched from `channel.nextVideos()` */
21
- videos: VideoCompact[];
22
- /** Loaded playlists on the channel, fetched from `channel.nextPlaylists()` */
23
- playlists: PlaylistCompact[];
24
- private _videoContinuation?;
25
- private _playlistContinuation?;
26
- /** @hidden */
27
- constructor(channel?: Partial<ChannelAttributes>);
28
- /**
29
- * Load this instance with raw data from Youtube
30
- *
31
- * @hidden
32
- */
33
- load(data: YoutubeRawData): Channel;
34
- /**
35
- * Load next 30 videos made by the channel, and push the loaded videos to {@link Channel.videos}
36
- *
37
- * @example
38
- * ```js
39
- * const channel = await youtube.findOne(CHANNEL_NAME, {type: "channel"});
40
- * await channel.nextVideos();
41
- * console.log(channel.videos) // first 30 videos
42
- *
43
- * let newVideos = await channel.nextVideos();
44
- * console.log(newVideos) // 30 loaded videos
45
- * console.log(channel.videos) // first 60 videos
46
- *
47
- * await channel.nextVideos(0); // load the rest of the videos in the channel
48
- * ```
49
- *
50
- * @param count How many time to load the next videos, pass `0` to load all
51
- *
52
- * @return New loaded videos
53
- */
54
- nextVideos(count?: number): Promise<VideoCompact[]>;
55
- /**
56
- * Load next 30 playlists made by the channel, and push the loaded playlists to {@link Channel.playlists}
57
- *
58
- * @example
59
- * ```js
60
- * const channel = await youtube.findOne(CHANNEL_NAME, {type: "channel"});
61
- * await channel.nextPlaylists();
62
- * console.log(channel.playlists) // first 30 playlists
63
- *
64
- * let newPlaylists = await channel.nextPlaylists();
65
- * console.log(newPlaylists) // 30 loaded playlists
66
- * console.log(channel.playlists) // first 60 playlists
67
- *
68
- * await channel.nextPlaylists(0); // load the rest of the playlists in the channel
69
- * ```
70
- *
71
- * @param count How many time to load the next playlists, pass `0` to load all
72
- *
73
- * @return New loaded playlists
74
- */
75
- nextPlaylists(count?: number): Promise<PlaylistCompact[]>;
76
- /** Get tab data from youtube */
77
- private getTabData;
78
- /** Parse tab data from request, tab name is ignored if it's a continuation data */
79
- private static parseTabData;
80
- /** Get continuation token from items (if exists) */
81
- private static getContinuationFromItems;
82
- }
83
- export {};
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const common_1 = require("../common");
13
- const _1 = require(".");
14
- const constants_1 = require("../constants");
15
- /** Represents a Youtube Channel */
16
- class Channel extends _1.Base {
17
- /** @hidden */
18
- constructor(channel = {}) {
19
- super();
20
- this._videoContinuation = null;
21
- this._playlistContinuation = null;
22
- Object.assign(this, channel);
23
- }
24
- /**
25
- * Load this instance with raw data from Youtube
26
- *
27
- * @hidden
28
- */
29
- load(data) {
30
- var _a;
31
- const { channelId, title, thumbnail, videoCountText, navigationEndpoint } = data;
32
- const { browseId, canonicalBaseUrl } = navigationEndpoint.browseEndpoint;
33
- this.id = channelId;
34
- this.name = title.simpleText;
35
- this.thumbnails = new _1.Thumbnails().load(thumbnail.thumbnails);
36
- this.url = "https://www.youtube.com" + (canonicalBaseUrl || `/channel/${browseId}`);
37
- this.videoCount = (_a = +(videoCountText === null || videoCountText === void 0 ? void 0 : videoCountText.runs[0].text.replace(/[^0-9]/g, ""))) !== null && _a !== void 0 ? _a : 0;
38
- this.videos = [];
39
- this.playlists = [];
40
- return this;
41
- }
42
- /**
43
- * Load next 30 videos made by the channel, and push the loaded videos to {@link Channel.videos}
44
- *
45
- * @example
46
- * ```js
47
- * const channel = await youtube.findOne(CHANNEL_NAME, {type: "channel"});
48
- * await channel.nextVideos();
49
- * console.log(channel.videos) // first 30 videos
50
- *
51
- * let newVideos = await channel.nextVideos();
52
- * console.log(newVideos) // 30 loaded videos
53
- * console.log(channel.videos) // first 60 videos
54
- *
55
- * await channel.nextVideos(0); // load the rest of the videos in the channel
56
- * ```
57
- *
58
- * @param count How many time to load the next videos, pass `0` to load all
59
- *
60
- * @return New loaded videos
61
- */
62
- nextVideos(count = 1) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const newVideos = [];
65
- for (let i = 0; i < count || count == 0; i++) {
66
- if (this._videoContinuation === undefined)
67
- break;
68
- const items = yield this.getTabData("videos");
69
- this._videoContinuation = Channel.getContinuationFromItems(items);
70
- newVideos.push(...items
71
- .filter((i) => i.gridVideoRenderer)
72
- .map((i) => new _1.VideoCompact().load(i.gridVideoRenderer)));
73
- }
74
- this.videos.push(...newVideos);
75
- return newVideos;
76
- });
77
- }
78
- /**
79
- * Load next 30 playlists made by the channel, and push the loaded playlists to {@link Channel.playlists}
80
- *
81
- * @example
82
- * ```js
83
- * const channel = await youtube.findOne(CHANNEL_NAME, {type: "channel"});
84
- * await channel.nextPlaylists();
85
- * console.log(channel.playlists) // first 30 playlists
86
- *
87
- * let newPlaylists = await channel.nextPlaylists();
88
- * console.log(newPlaylists) // 30 loaded playlists
89
- * console.log(channel.playlists) // first 60 playlists
90
- *
91
- * await channel.nextPlaylists(0); // load the rest of the playlists in the channel
92
- * ```
93
- *
94
- * @param count How many time to load the next playlists, pass `0` to load all
95
- *
96
- * @return New loaded playlists
97
- */
98
- nextPlaylists(count = 1) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const newPlaylists = [];
101
- for (let i = 0; i < count || count == 0; i++) {
102
- if (this._playlistContinuation === undefined)
103
- break;
104
- const items = yield this.getTabData("playlists");
105
- this._playlistContinuation = Channel.getContinuationFromItems(items);
106
- newPlaylists.push(...items
107
- .filter((i) => i.gridPlaylistRenderer)
108
- .map((i) => new _1.PlaylistCompact().load(i.gridPlaylistRenderer)));
109
- }
110
- this.playlists.push(...newPlaylists);
111
- return newPlaylists;
112
- });
113
- }
114
- /** Get tab data from youtube */
115
- getTabData(name) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- const params = name === "videos" ? "EgZ2aWRlb3M%3D" : "EglwbGF5bGlzdHMgAQ%3D%3D";
118
- const continuation = name === "videos" ? this._videoContinuation : this._playlistContinuation;
119
- const response = yield common_1.http.post(`${constants_1.I_END_POINT}/browse`, {
120
- data: { browseId: this.id, params, continuation },
121
- });
122
- return Channel.parseTabData(name, response.data);
123
- });
124
- }
125
- /** Parse tab data from request, tab name is ignored if it's a continuation data */
126
- static parseTabData(name, data) {
127
- var _a;
128
- const index = name === "videos" ? 1 : 2;
129
- return (((_a = data.contents) === null || _a === void 0 ? void 0 : _a.twoColumnBrowseResultsRenderer.tabs[index].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer.items) ||
130
- data.onResponseReceivedActions[0].appendContinuationItemsAction.continuationItems);
131
- }
132
- /** Get continuation token from items (if exists) */
133
- static getContinuationFromItems(items) {
134
- var _a;
135
- return (_a = items[items.length - 1].continuationItemRenderer) === null || _a === void 0 ? void 0 : _a.continuationEndpoint.continuationCommand.token;
136
- }
137
- }
138
- exports.default = Channel;
@@ -1,29 +0,0 @@
1
- import { Base, Channel, Video, BaseAttributes } from ".";
2
- import { YoutubeRawData } from "../common";
3
- /** @hidden */
4
- interface ChatAttributes extends BaseAttributes {
5
- video: Video;
6
- author: Channel;
7
- message: string;
8
- timestamp: number;
9
- }
10
- /** Represents a chat in a live stream */
11
- export default class Chat extends Base implements ChatAttributes {
12
- /** The video this chat belongs to */
13
- video: Video;
14
- /** The chat's author */
15
- author: Channel;
16
- /** The message of this chat */
17
- message: string;
18
- /** Timestamp in usec / microsecond */
19
- timestamp: number;
20
- /** @hidden */
21
- constructor(chat?: Partial<ChatAttributes>);
22
- /**
23
- * Load this instance with raw data from Youtube
24
- *
25
- * @hidden
26
- */
27
- load(data: YoutubeRawData): Chat;
28
- }
29
- export {};
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- /** Represents a chat in a live stream */
5
- class Chat extends _1.Base {
6
- /** @hidden */
7
- constructor(chat = {}) {
8
- super();
9
- Object.assign(this, chat);
10
- }
11
- /**
12
- * Load this instance with raw data from Youtube
13
- *
14
- * @hidden
15
- */
16
- load(data) {
17
- const { id, message, authorName, authorPhoto, timestampUsec, authorExternalChannelId, } = data;
18
- // Basic information
19
- this.id = id;
20
- this.message = message.runs.map((r) => r.text).join("");
21
- this.author = new _1.Channel({
22
- id: authorExternalChannelId,
23
- name: authorName.simpleText,
24
- thumbnails: authorPhoto.thumbnails,
25
- url: `https://www.youtube.com/channel/${authorExternalChannelId}`,
26
- });
27
- this.timestamp = timestampUsec;
28
- return this;
29
- }
30
- }
31
- exports.default = Chat;
@@ -1,30 +0,0 @@
1
- import { Playlist, Video, SearchResult, LiveVideo } from ".";
2
- import { SearchResultType } from "./SearchResult";
3
- export declare namespace Client {
4
- type SearchType = "video" | "channel" | "playlist" | "all";
5
- type SearchOptions = {
6
- /** Search type, can be `"video"`, `"channel"`, `"playlist"`, or `"all"` */
7
- type: SearchType;
8
- };
9
- }
10
- /** Youtube Client */
11
- export default class Client {
12
- /**
13
- * Searches for videos / playlists / channels
14
- *
15
- * @param query The search query
16
- * @param searchOptions Search options
17
- *
18
- */
19
- search<T extends Client.SearchOptions>(query: string, searchOptions?: Partial<T>): Promise<SearchResult<T>>;
20
- /**
21
- * Search for videos / playlists / channels and returns the first result
22
- *
23
- * @return Can be {@link VideoCompact} | {@link PlaylistCompact} | {@link Channel} | `undefined`
24
- */
25
- findOne<T extends Client.SearchOptions>(query: string, searchOptions?: Partial<T>): Promise<SearchResultType<T> | undefined>;
26
- /** Get playlist information and its videos by playlist id or URL */
27
- getPlaylist(playlistIdOrUrl: string): Promise<Playlist | undefined>;
28
- /** Get video information by video id or URL */
29
- getVideo(videoIdOrUrl: string): Promise<Video | LiveVideo | undefined>;
30
- }
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const constants_1 = require("../constants");
13
- const common_1 = require("../common");
14
- const _1 = require(".");
15
- /** Youtube Client */
16
- class Client {
17
- /**
18
- * Searches for videos / playlists / channels
19
- *
20
- * @param query The search query
21
- * @param searchOptions Search options
22
- *
23
- */
24
- search(query, searchOptions) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const options = Object.assign({ type: "all" }, searchOptions);
27
- const result = new _1.SearchResult();
28
- yield result.init(query, options);
29
- return result;
30
- });
31
- }
32
- /**
33
- * Search for videos / playlists / channels and returns the first result
34
- *
35
- * @return Can be {@link VideoCompact} | {@link PlaylistCompact} | {@link Channel} | `undefined`
36
- */
37
- findOne(query, searchOptions) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- return (yield this.search(query, searchOptions)).shift();
40
- });
41
- }
42
- /** Get playlist information and its videos by playlist id or URL */
43
- getPlaylist(playlistIdOrUrl) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const playlistId = common_1.getQueryParameter(playlistIdOrUrl, "list");
46
- const response = yield common_1.http.post(`${constants_1.I_END_POINT}/browse`, {
47
- data: { browseId: `VL${playlistId}` },
48
- });
49
- if (response.data.error || response.data.alerts)
50
- return undefined;
51
- return new _1.Playlist().load(response.data);
52
- });
53
- }
54
- /** Get video information by video id or URL */
55
- getVideo(videoIdOrUrl) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const videoId = common_1.getQueryParameter(videoIdOrUrl, "v");
58
- const response = yield common_1.http.get(`${constants_1.WATCH_END_POINT}`, {
59
- params: { v: videoId, pbj: "1" },
60
- });
61
- if (!response.data[3].response.contents)
62
- return undefined;
63
- return !response.data[2].playerResponse.playabilityStatus.liveStreamability
64
- ? new _1.Video().load(response.data)
65
- : new _1.LiveVideo().load(response.data);
66
- });
67
- }
68
- }
69
- exports.default = Client;
@@ -1,43 +0,0 @@
1
- import { Base, Channel, Video, BaseAttributes } from ".";
2
- import { YoutubeRawData } from "../common";
3
- /** @hidden */
4
- interface CommentAttributes extends BaseAttributes {
5
- video: Video;
6
- author: Channel;
7
- content: string;
8
- publishDate: string;
9
- likeCount: number;
10
- isAuthorChannelOwner: boolean;
11
- isPinnedComment: boolean;
12
- replyCount: number;
13
- }
14
- /** Represents a Comment / Reply */
15
- export default class Comment extends Base implements CommentAttributes {
16
- /** The video this comment belongs to */
17
- video: Video;
18
- /** The comment's author */
19
- author: Channel;
20
- /** The content of this comment */
21
- content: string;
22
- /** The publish date of the comment */
23
- publishDate: string;
24
- /** How many likes does this comment have */
25
- likeCount: number;
26
- /** Whether the comment is posted by the video uploader / owner */
27
- isAuthorChannelOwner: boolean;
28
- /** Whether the comment is pinned */
29
- isPinnedComment: boolean;
30
- /** Comment's reply count */
31
- replyCount: number;
32
- /** @hidden */
33
- constructor(channel?: Partial<CommentAttributes>);
34
- /**
35
- * Load this instance with raw data from Youtube
36
- *
37
- * @hidden
38
- */
39
- load(data: YoutubeRawData): Comment;
40
- /** URL to the video with this comment being highlighted (appears on top of the comment section) */
41
- get url(): string;
42
- }
43
- export {};
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- /** Represents a Comment / Reply */
5
- class Comment extends _1.Base {
6
- // TODO: Add replies
7
- /** @hidden */
8
- constructor(channel = {}) {
9
- super();
10
- Object.assign(this, channel);
11
- }
12
- /**
13
- * Load this instance with raw data from Youtube
14
- *
15
- * @hidden
16
- */
17
- load(data) {
18
- const { authorText, authorThumbnail, authorEndpoint, contentText, publishedTimeText, commentId, likeCount, authorIsChannelOwner, pinnedCommentBadge, replyCount, } = data.comment.commentRenderer;
19
- // Basic information
20
- this.id = commentId;
21
- this.content = contentText.runs.map((r) => r.text).join("");
22
- this.publishDate = publishedTimeText.runs.shift().text;
23
- this.likeCount = likeCount;
24
- this.isAuthorChannelOwner = authorIsChannelOwner;
25
- this.isPinnedComment = !!pinnedCommentBadge;
26
- this.replyCount = replyCount;
27
- // Author
28
- const { browseId, canonicalBaseUrl } = authorEndpoint.browseEndpoint;
29
- this.author = new _1.Channel({
30
- id: browseId,
31
- name: authorText.simpleText,
32
- thumbnails: new _1.Thumbnails().load(authorThumbnail.thumbnails),
33
- url: "https://www.youtube.com" + (canonicalBaseUrl || `/channel/${browseId}`),
34
- });
35
- return this;
36
- }
37
- /** URL to the video with this comment being highlighted (appears on top of the comment section) */
38
- get url() {
39
- return `https://www.youtube.com?watch=${this.video.id}&lc=${this.id}`;
40
- }
41
- }
42
- exports.default = Comment;
@@ -1,61 +0,0 @@
1
- import { BaseAttributes, VideoCompact, Channel, Base } from ".";
2
- import { YoutubeRawData } from "../common";
3
- /** @hidden */
4
- interface PlaylistAttributes extends BaseAttributes {
5
- title: string;
6
- videoCount: number;
7
- viewCount: number;
8
- lastUpdatedAt: string;
9
- channel?: Channel;
10
- videos: VideoCompact[];
11
- }
12
- /** Represents a Playlist, usually returned from `client.getPlaylist()` */
13
- export default class Playlist extends Base implements PlaylistAttributes {
14
- /** The title of this playlist */
15
- title: string;
16
- /** How many videos in this playlist */
17
- videoCount: number;
18
- /** How many viewers does this playlist have */
19
- viewCount: number;
20
- /** Last time this playlist is updated */
21
- lastUpdatedAt: string;
22
- /** The channel that made this playlist */
23
- channel?: Channel;
24
- /** Videos in the playlist */
25
- videos: VideoCompact[];
26
- private _continuation;
27
- /** @hidden */
28
- constructor(playlist?: Partial<Playlist>);
29
- /**
30
- * Load this instance with raw data from Youtube
31
- *
32
- * @hidden
33
- */
34
- load(data: YoutubeRawData): Playlist;
35
- /**
36
- * Load next 100 videos of the playlist, and push the loaded videos to {@link Playlist.videos}
37
- *
38
- * @example
39
- * ```js
40
- * const playlist = await youtube.getPlaylist(PLAYLIST_ID);
41
- * console.log(playlist.videos) // first 100 videos
42
- *
43
- * let newVideos = await playlist.next();
44
- * console.log(newVideos) // 100 loaded videos
45
- * console.log(playlist.videos) // first 200 videos
46
- *
47
- * await playlist.next(0); // load the rest of the videos in the playlist
48
- * ```
49
- *
50
- * @param count How many times to load the next videos. Set 0 to load all videos (might take a while on a large playlist!)
51
- */
52
- next(count?: number): Promise<VideoCompact[]>;
53
- /**
54
- * Get compact videos
55
- *
56
- * @param playlistContents raw object from youtubei
57
- */
58
- private static getVideos;
59
- private static getSideBarInfo;
60
- }
61
- export {};
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const _1 = require(".");
13
- const common_1 = require("../common");
14
- const constants_1 = require("../constants");
15
- /** Represents a Playlist, usually returned from `client.getPlaylist()` */
16
- class Playlist extends _1.Base {
17
- /** @hidden */
18
- constructor(playlist = {}) {
19
- super();
20
- Object.assign(this, playlist);
21
- }
22
- /**
23
- * Load this instance with raw data from Youtube
24
- *
25
- * @hidden
26
- */
27
- load(data) {
28
- var _a, _b;
29
- const sidebarRenderer = data.sidebar.playlistSidebarRenderer.items;
30
- const primaryRenderer = sidebarRenderer[0].playlistSidebarPrimaryInfoRenderer;
31
- // Basic information
32
- this.id = primaryRenderer.title.runs[0].navigationEndpoint.watchEndpoint.playlistId;
33
- this.title = primaryRenderer.title.runs[0].text;
34
- const { stats } = primaryRenderer;
35
- if (primaryRenderer.stats.length === 3) {
36
- this.videoCount = Playlist.getSideBarInfo(stats[0], true);
37
- this.viewCount = Playlist.getSideBarInfo(stats[1], true);
38
- this.lastUpdatedAt = Playlist.getSideBarInfo(stats[2], false);
39
- }
40
- else if (stats.length === 2) {
41
- this.videoCount = Playlist.getSideBarInfo(stats[0], true);
42
- this.lastUpdatedAt = Playlist.getSideBarInfo(stats[1], false);
43
- }
44
- // Videos
45
- const playlistContents = data.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
46
- .sectionListRenderer.contents[0].itemSectionRenderer.contents[0]
47
- .playlistVideoListRenderer.contents;
48
- this.videos = Playlist.getVideos(playlistContents);
49
- // Video Continuation Token
50
- this._continuation = (_a = playlistContents[100]) === null || _a === void 0 ? void 0 : _a.continuationItemRenderer.continuationEndpoint.continuationCommand.token;
51
- // Channel
52
- const videoOwner = ((_b = sidebarRenderer[1]) === null || _b === void 0 ? void 0 : _b.playlistSidebarSecondaryInfoRenderer.videoOwner) || undefined;
53
- if (videoOwner) {
54
- const { title, thumbnail } = videoOwner.videoOwnerRenderer;
55
- this.channel = new _1.Channel({
56
- id: title.runs[0].navigationEndpoint.browseEndpoint.browseId,
57
- name: title.runs[0].text,
58
- thumbnails: new _1.Thumbnails().load(thumbnail.thumbnails),
59
- url: "https://www.youtube.com" +
60
- title.runs[0].navigationEndpoint.commandMetadata.webCommandMetadata.url,
61
- });
62
- }
63
- return this;
64
- }
65
- /**
66
- * Load next 100 videos of the playlist, and push the loaded videos to {@link Playlist.videos}
67
- *
68
- * @example
69
- * ```js
70
- * const playlist = await youtube.getPlaylist(PLAYLIST_ID);
71
- * console.log(playlist.videos) // first 100 videos
72
- *
73
- * let newVideos = await playlist.next();
74
- * console.log(newVideos) // 100 loaded videos
75
- * console.log(playlist.videos) // first 200 videos
76
- *
77
- * await playlist.next(0); // load the rest of the videos in the playlist
78
- * ```
79
- *
80
- * @param count How many times to load the next videos. Set 0 to load all videos (might take a while on a large playlist!)
81
- */
82
- next(count = 1) {
83
- var _a;
84
- return __awaiter(this, void 0, void 0, function* () {
85
- const newVideos = [];
86
- for (let i = 0; i < count || count == 0; i++) {
87
- if (!this._continuation)
88
- break;
89
- const response = yield common_1.http.post(`${constants_1.I_END_POINT}/browse`, {
90
- data: { continuation: this._continuation },
91
- });
92
- const playlistContents = response.data.onResponseReceivedActions[0].appendContinuationItemsAction
93
- .continuationItems;
94
- newVideos.push(...Playlist.getVideos(playlistContents));
95
- this._continuation = (_a = playlistContents[100]) === null || _a === void 0 ? void 0 : _a.continuationItemRenderer.continuationEndpoint.continuationCommand.token;
96
- }
97
- this.videos.push(...newVideos);
98
- return newVideos;
99
- });
100
- }
101
- /**
102
- * Get compact videos
103
- *
104
- * @param playlistContents raw object from youtubei
105
- */
106
- static getVideos(playlistContents) {
107
- const videosRenderer = playlistContents.map((c) => c.playlistVideoRenderer);
108
- const videos = [];
109
- for (const videoRenderer of videosRenderer) {
110
- if (!videoRenderer)
111
- continue;
112
- videos.push(new _1.VideoCompact().load(videoRenderer));
113
- }
114
- return videos;
115
- }
116
- static getSideBarInfo(stats, parseInt) {
117
- let data;
118
- if ("runs" in stats)
119
- data = stats.runs.map((r) => r.text).join("");
120
- else
121
- data = stats.simpleText.replace(/[^0-9]/g, "");
122
- if (parseInt)
123
- data = +data.replace(/[^0-9]/g, "");
124
- return data;
125
- }
126
- }
127
- exports.default = Playlist;