youtubei 0.0.1-rc.7 → 1.0.0-rc.1

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 (264) 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/{index.js → cjs/classes/Base/index.js} +13 -13
  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/{classes/client → cjs/classes/BaseChannel}/index.js +16 -19
  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/{common → cjs/classes/BaseVideo}/index.js +15 -21
  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 +13 -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 +13 -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 +13 -0
  27. package/dist/cjs/classes/Continuable/Continuable.js +43 -0
  28. package/dist/cjs/classes/Continuable/index.js +13 -0
  29. package/dist/cjs/classes/LiveVideo/LiveVideo.js +84 -0
  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/SearchManager/SearchManager.js +83 -0
  46. package/dist/cjs/classes/SearchManager/SearchManagerParser.js +40 -0
  47. package/dist/cjs/classes/SearchManager/index.js +14 -0
  48. package/dist/{common/types.js → cjs/classes/SearchManager/proto/SearchProto.js} +2 -2
  49. package/dist/cjs/classes/SearchManager/proto/index.js +57 -0
  50. package/dist/cjs/classes/Thumbnails/Thumbnails.js +67 -0
  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 +14 -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/{src → cjs}/common/decorators.js +14 -15
  61. package/dist/cjs/common/helper.js +45 -0
  62. package/dist/{src → cjs}/common/index.js +16 -21
  63. package/dist/cjs/common/mixins.js +14 -0
  64. package/dist/{classes/client → cjs/common}/types.js +2 -2
  65. package/dist/{src → cjs}/constants.js +10 -9
  66. package/dist/{src → 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 +1 -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 +1 -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 +1 -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/SearchManager/SearchManager.js +159 -0
  110. package/dist/esm/classes/SearchManager/SearchManagerParser.js +62 -0
  111. package/dist/esm/classes/SearchManager/index.js +2 -0
  112. package/dist/esm/classes/SearchManager/proto/SearchProto.js +1 -0
  113. package/dist/esm/classes/SearchManager/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 +2 -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/{common/index.d.ts → esm/common/index.js} +4 -4
  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/{index.d.ts → esm/index.js} +1 -1
  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 +1 -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 +1 -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 +1 -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/typings/classes/LiveVideo/LiveVideo.d.ts +46 -0
  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/SearchManager/SearchManager.d.ts +51 -0
  174. package/dist/typings/classes/SearchManager/SearchManagerParser.d.ts +13 -0
  175. package/dist/typings/classes/SearchManager/index.d.ts +2 -0
  176. package/dist/typings/classes/SearchManager/proto/SearchProto.d.ts +13 -0
  177. package/dist/typings/classes/SearchManager/proto/index.d.ts +24 -0
  178. package/dist/typings/classes/Thumbnails/Thumbnails.d.ts +41 -0
  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 +2 -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/{src → typings}/common/decorators.d.ts +5 -7
  189. package/dist/typings/common/helper.d.ts +5 -0
  190. package/dist/{src → typings}/common/index.d.ts +4 -4
  191. package/dist/typings/common/mixins.d.ts +1 -0
  192. package/dist/{common → typings/common}/types.d.ts +1 -2
  193. package/dist/{constants.d.ts → typings/constants.d.ts} +7 -6
  194. package/dist/{src → 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 -8
  198. package/dist/classes/Base.js +0 -10
  199. package/dist/classes/Channel.d.ts +0 -63
  200. package/dist/classes/Channel.js +0 -115
  201. package/dist/classes/Comment.d.ts +0 -51
  202. package/dist/classes/Comment.js +0 -47
  203. package/dist/classes/LiveVideo.d.ts +0 -3
  204. package/dist/classes/LiveVideo.js +0 -12
  205. package/dist/classes/Playlist.d.ts +0 -66
  206. package/dist/classes/Playlist.js +0 -133
  207. package/dist/classes/PlaylistCompact.d.ts +0 -35
  208. package/dist/classes/PlaylistCompact.js +0 -47
  209. package/dist/classes/SearchResult.d.ts +0 -52
  210. package/dist/classes/SearchResult.js +0 -121
  211. package/dist/classes/Test.d.ts +0 -7
  212. package/dist/classes/Test.js +0 -9
  213. package/dist/classes/Thumbnails.d.ts +0 -23
  214. package/dist/classes/Thumbnails.js +0 -42
  215. package/dist/classes/Video.d.ts +0 -90
  216. package/dist/classes/Video.js +0 -153
  217. package/dist/classes/VideoCompact.d.ts +0 -46
  218. package/dist/classes/VideoCompact.js +0 -53
  219. package/dist/classes/client/Client.d.ts +0 -26
  220. package/dist/classes/client/Client.js +0 -63
  221. package/dist/classes/client/index.d.ts +0 -2
  222. package/dist/classes/client/types.d.ts +0 -12
  223. package/dist/classes/client.d.ts +0 -17
  224. package/dist/classes/client.js +0 -57
  225. package/dist/classes/index.d.ts +0 -10
  226. package/dist/classes/index.js +0 -26
  227. package/dist/common/decorators.d.ts +0 -7
  228. package/dist/common/decorators.js +0 -15
  229. package/dist/common/helper.d.ts +0 -4
  230. package/dist/common/helper.js +0 -39
  231. package/dist/common/http.d.ts +0 -33
  232. package/dist/common/http.js +0 -105
  233. package/dist/constants.js +0 -9
  234. package/dist/src/classes/Base.d.ts +0 -8
  235. package/dist/src/classes/Base.js +0 -10
  236. package/dist/src/classes/Channel.d.ts +0 -37
  237. package/dist/src/classes/Channel.js +0 -82
  238. package/dist/src/classes/Client.d.ts +0 -14
  239. package/dist/src/classes/Client.js +0 -51
  240. package/dist/src/classes/Comment.d.ts +0 -51
  241. package/dist/src/classes/Comment.js +0 -47
  242. package/dist/src/classes/Playlist.d.ts +0 -66
  243. package/dist/src/classes/Playlist.js +0 -133
  244. package/dist/src/classes/PlaylistCompact.d.ts +0 -35
  245. package/dist/src/classes/PlaylistCompact.js +0 -47
  246. package/dist/src/classes/SearchResult.d.ts +0 -53
  247. package/dist/src/classes/SearchResult.js +0 -122
  248. package/dist/src/classes/Thumbnails.d.ts +0 -24
  249. package/dist/src/classes/Thumbnails.js +0 -42
  250. package/dist/src/classes/Video.d.ts +0 -90
  251. package/dist/src/classes/Video.js +0 -153
  252. package/dist/src/classes/VideoCompact.d.ts +0 -46
  253. package/dist/src/classes/VideoCompact.js +0 -53
  254. package/dist/src/classes/index.d.ts +0 -10
  255. package/dist/src/classes/index.js +0 -26
  256. package/dist/src/common/helper.d.ts +0 -4
  257. package/dist/src/common/helper.js +0 -39
  258. package/dist/src/common/http.d.ts +0 -33
  259. package/dist/src/common/http.js +0 -105
  260. package/dist/src/common/types.d.ts +0 -2
  261. package/dist/src/common/types.js +0 -2
  262. package/dist/src/constants.d.ts +0 -6
  263. package/dist/tempCodeRunnerFile.d.ts +0 -8
  264. package/dist/tempCodeRunnerFile.js +0 -15
@@ -1,153 +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 Video, usually returned from `client.getVideo()` */
16
- class Video extends _1.Base {
17
- /** @hidden */
18
- constructor(video = {}) {
19
- super();
20
- Object.assign(this, video);
21
- }
22
- /**
23
- * Load instance attributes from youtube raw data
24
- *
25
- * @param youtubeRawData raw object from youtubei
26
- * @hidden
27
- */
28
- load(youtubeRawData) {
29
- var _a, _b, _c, _d, _e, _f;
30
- const contents = youtubeRawData[3].response.contents.twoColumnWatchNextResults.results.results.contents;
31
- const primaryInfo = contents.find((c) => "videoPrimaryInfoRenderer" in c)
32
- .videoPrimaryInfoRenderer;
33
- const secondaryInfo = contents.find((c) => "videoSecondaryInfoRenderer" in c).videoSecondaryInfoRenderer;
34
- const videoDetails = youtubeRawData[2].playerResponse.videoDetails;
35
- const videoInfo = Object.assign(Object.assign(Object.assign({}, secondaryInfo), primaryInfo), { videoDetails });
36
- // Comment Continuation Token
37
- this.comments = [];
38
- const continuation = (_a = contents.find((c) => "itemSectionRenderer" in c)) === null || _a === void 0 ? void 0 : _a.itemSectionRenderer.continuations[0].nextContinuationData;
39
- if (continuation) {
40
- this._commentContinuation = {
41
- token: continuation.continuation,
42
- itct: continuation.clickTrackingParams,
43
- xsrfToken: youtubeRawData[3].xsrf_token,
44
- };
45
- }
46
- // Basic information
47
- this.id = videoInfo.videoDetails.videoId;
48
- this.title = videoInfo.videoDetails.title;
49
- this.duration = +videoInfo.videoDetails.lengthSeconds || null;
50
- this.uploadDate = videoInfo.dateText.simpleText;
51
- this.viewCount = +videoInfo.videoDetails.viewCount;
52
- this.isLiveContent = videoInfo.videoDetails.isLiveContent;
53
- this.thumbnails = new _1.Thumbnails().load(videoInfo.videoDetails.thumbnail.thumbnails);
54
- // Channel
55
- const { title, thumbnail } = videoInfo.owner.videoOwnerRenderer;
56
- this.channel = new _1.Channel({
57
- id: title.runs[0].navigationEndpoint.browseEndpoint.browseId,
58
- name: title.runs[0].text,
59
- thumbnails: new _1.Thumbnails().load(thumbnail.thumbnails),
60
- url: `https://www.youtube.com/channel/${title.runs[0].navigationEndpoint.browseEndpoint.browseId}`,
61
- });
62
- // Like Count and Dislike Count
63
- const topLevelButtons = videoInfo.videoActions.menuRenderer.topLevelButtons;
64
- this.likeCount =
65
- +((_b = topLevelButtons[0].toggleButtonRenderer.defaultText.accessibility) === null || _b === void 0 ? void 0 : _b.accessibilityData.label.replace(/[^0-9]/g, "")) || null;
66
- this.dislikeCount =
67
- +((_c = topLevelButtons[1].toggleButtonRenderer.defaultText.accessibility) === null || _c === void 0 ? void 0 : _c.accessibilityData.label.replace(/[^0-9]/g, "")) || null;
68
- // Tags and description
69
- this.tags =
70
- ((_e = (_d = videoInfo.superTitleLink) === null || _d === void 0 ? void 0 : _d.runs) === null || _e === void 0 ? void 0 : _e.reduce((tags, t) => {
71
- if (t.text.trim())
72
- tags.push(t.text.trim());
73
- return tags;
74
- }, [])) || [];
75
- this.description =
76
- ((_f = videoInfo.description) === null || _f === void 0 ? void 0 : _f.runs.map((d) => d.text).join("")) || "";
77
- // Up Next and related videos
78
- this.related = [];
79
- const secondaryContents = youtubeRawData[3].response.contents.twoColumnWatchNextResults.secondaryResults
80
- .secondaryResults.results;
81
- for (const secondaryContent of secondaryContents) {
82
- if ("compactAutoplayRenderer" in secondaryContent) {
83
- const content = secondaryContent.compactAutoplayRenderer.contents[0];
84
- if ("compactVideoRenderer" in content) {
85
- this.upNext = new _1.VideoCompact().load(content.compactVideoRenderer);
86
- }
87
- else if ("compactRadioRenderer" in content) {
88
- this.upNext = new _1.PlaylistCompact().load(content.compactRadioRenderer);
89
- }
90
- }
91
- else if ("compactVideoRenderer" in secondaryContent) {
92
- this.related.push(new _1.VideoCompact().load(secondaryContent.compactVideoRenderer));
93
- }
94
- else if ("compactRadioRenderer" in secondaryContent) {
95
- this.related.push(new _1.PlaylistCompact().load(secondaryContent.compactRadioRenderer));
96
- }
97
- }
98
- return this;
99
- }
100
- /**
101
- * Load next 20 comments of the video
102
- *
103
- * @example
104
- * ```js
105
- * const video = await youtube.getVideo(VIDEO_ID);
106
- * console.log(video.comments) // first 20 comments
107
- *
108
- * let newComments = await video.nextComments();
109
- * console.log(newComments) // 20 loaded comments
110
- * console.log(video.comments) // first 40 comments
111
- *
112
- * await video.nextComments(0); // load the rest of the comments in the playlist
113
- * ```
114
- *
115
- * @param count How many times to load the next comments. Set 0 to load all comments (might take a while on a video with many comments!)
116
- */
117
- nextComments(count = 1) {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- const newComments = [];
120
- for (let i = 0; i < count || count == 0; i++) {
121
- if (!this._commentContinuation)
122
- break;
123
- // Send request
124
- const response = yield common_1.http.post(constants_1.COMMENT_END_POINT, {
125
- data: { session_token: this._commentContinuation.xsrfToken },
126
- headers: { "content-type": "application/x-www-form-urlencoded" },
127
- params: {
128
- action_get_comments: "1",
129
- pbj: "1",
130
- ctoken: this._commentContinuation.token,
131
- continuation: this._commentContinuation.token,
132
- itct: this._commentContinuation.itct,
133
- },
134
- });
135
- const { contents: comments, continuations, } = response.data.response.continuationContents.itemSectionContinuation;
136
- const continuation = continuations === null || continuations === void 0 ? void 0 : continuations.pop().nextContinuationData;
137
- this._commentContinuation = continuation
138
- ? {
139
- token: continuation.continuation,
140
- itct: continuation.clickTrackingParams,
141
- xsrfToken: response.data.xsrf_token,
142
- }
143
- : undefined;
144
- for (const comment of comments.map((c) => c.commentThreadRenderer)) {
145
- newComments.push(new _1.Comment({ video: this }).load(comment));
146
- }
147
- }
148
- this.comments.push(...newComments);
149
- return newComments;
150
- });
151
- }
152
- }
153
- exports.default = Video;
@@ -1,46 +0,0 @@
1
- import { YoutubeRawData } from "../common";
2
- import { Base, Channel, Thumbnails } from ".";
3
- /** @hidden */
4
- interface VideoCompactAttributes {
5
- id: string;
6
- title: string;
7
- thumbnails: Thumbnails;
8
- duration: number | null;
9
- isLiveContent: boolean;
10
- channel?: Channel;
11
- uploadDate?: string;
12
- viewCount?: number;
13
- }
14
- /** Represent a compact video (e.g. from search result, playlist's videos, channel's videos) */
15
- export default class VideoCompact extends Base implements VideoCompactAttributes {
16
- /** The video's ID */
17
- id: string;
18
- /** The title of the video */
19
- title: string;
20
- /** Thumbnails of the video with different sizes */
21
- thumbnails: Thumbnails;
22
- /** The duration of this video in second, null if the video is live */
23
- duration: number | null;
24
- /** Whether this video is a live content or not */
25
- isLiveContent: boolean;
26
- /** The channel who uploads this video */
27
- channel?: Channel;
28
- /** The date this video is uploaded at */
29
- uploadDate?: string;
30
- /** How many view does this video have, null if the view count is hidden */
31
- viewCount?: number;
32
- /** @hidden */
33
- constructor(videoCompact?: Partial<VideoCompactAttributes>);
34
- /**
35
- * Load instance attributes from youtube raw data
36
- *
37
- * @param youtubeRawData raw object from youtubei
38
- * @hidden
39
- */
40
- load(youtubeRawData: YoutubeRawData): VideoCompact;
41
- /**
42
- * Whether this video is private / deleted or not, only useful in playlist's videos
43
- */
44
- get isPrivateOrDeleted(): boolean;
45
- }
46
- export {};
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const common_1 = require("../common");
4
- const _1 = require(".");
5
- /** Represent a compact video (e.g. from search result, playlist's videos, channel's videos) */
6
- class VideoCompact extends _1.Base {
7
- /** @hidden */
8
- constructor(videoCompact = {}) {
9
- super();
10
- Object.assign(this, videoCompact);
11
- }
12
- /**
13
- * Load instance attributes from youtube raw data
14
- *
15
- * @param youtubeRawData raw object from youtubei
16
- * @hidden
17
- */
18
- load(youtubeRawData) {
19
- var _a, _b, _c;
20
- const { videoId, title, lengthText, thumbnail, ownerText, shortBylineText, publishedTimeText, viewCountText, badges, thumbnailOverlays, } = youtubeRawData;
21
- this.id = videoId;
22
- this.title = title.simpleText || ((_a = title.runs[0]) === null || _a === void 0 ? void 0 : _a.text);
23
- this.thumbnails = new _1.Thumbnails().load(thumbnail.thumbnails);
24
- this.uploadDate = publishedTimeText === null || publishedTimeText === void 0 ? void 0 : publishedTimeText.simpleText;
25
- this.duration =
26
- common_1.getDuration((lengthText === null || lengthText === void 0 ? void 0 : lengthText.simpleText) || ((_b = thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer) === null || _b === void 0 ? void 0 : _b.text.simpleText) ||
27
- "") || null;
28
- this.isLiveContent = badges
29
- ? badges[0].metadataBadgeRenderer.style === "BADGE_STYLE_TYPE_LIVE_NOW"
30
- : false;
31
- // Channel
32
- if (ownerText || shortBylineText) {
33
- const { browseId, canonicalBaseUrl } = (ownerText || shortBylineText).runs[0].navigationEndpoint.browseEndpoint;
34
- this.channel = new _1.Channel({
35
- id: browseId,
36
- name: (ownerText || shortBylineText).runs[0].text,
37
- url: "https://www.youtube.com" + (canonicalBaseUrl || `/channel/${browseId}`),
38
- });
39
- }
40
- if (!this.isLiveContent)
41
- this.viewCount = +((_c = viewCountText === null || viewCountText === void 0 ? void 0 : viewCountText.simpleText) === null || _c === void 0 ? void 0 : _c.replace(/[^0-9]/g, "")) || undefined;
42
- else
43
- this.viewCount = +(viewCountText === null || viewCountText === void 0 ? void 0 : viewCountText.runs[0].text.replace(/[^0-9]/g, "")) || undefined;
44
- return this;
45
- }
46
- /**
47
- * Whether this video is private / deleted or not, only useful in playlist's videos
48
- */
49
- get isPrivateOrDeleted() {
50
- return !this.duration;
51
- }
52
- }
53
- exports.default = VideoCompact;
@@ -1,26 +0,0 @@
1
- import { Playlist, Video, SearchResult } from "..";
2
- export declare type SearchType = "video" | "channel" | "playlist" | "all";
3
- export declare type SearchOptions = {
4
- type: SearchType;
5
- };
6
- export default class YoutubeClient {
7
- /**
8
- * Searches for videos / playlists / channels
9
- *
10
- * @param {string} query
11
- * @param {SearchOptions} searchOptions
12
- */
13
- search<T extends SearchOptions>(query: string, searchOptions?: Partial<T>): Promise<SearchResult<T>>;
14
- /**
15
- * Get playlist information and its videos by playlist id or URL
16
- *
17
- * @param playlistIdOrUrl
18
- */
19
- getPlaylist(playlistIdOrUrl: string): Promise<Playlist | undefined>;
20
- /**
21
- * Get video information by video id or URL
22
- *
23
- * @param videoIdOrUrl
24
- */
25
- getVideo(videoIdOrUrl: string): Promise<Video | undefined>;
26
- }
@@ -1,63 +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
- class YoutubeClient {
16
- /**
17
- * Searches for videos / playlists / channels
18
- *
19
- * @param {string} query
20
- * @param {SearchOptions} searchOptions
21
- */
22
- search(query, searchOptions) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const options = Object.assign({ type: "all" }, searchOptions);
25
- const result = new __1.SearchResult();
26
- yield result.init(query, options);
27
- return result;
28
- });
29
- }
30
- /**
31
- * Get playlist information and its videos by playlist id or URL
32
- *
33
- * @param playlistIdOrUrl
34
- */
35
- getPlaylist(playlistIdOrUrl) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const playlistId = common_1.getQueryParameter(playlistIdOrUrl, "list");
38
- const response = yield common_1.http.post(`${constants_1.I_END_POINT}/browse`, {
39
- data: { browseId: `VL${playlistId}` },
40
- });
41
- if (response.data.error || response.data.alerts)
42
- return undefined;
43
- return new __1.Playlist().load(response.data);
44
- });
45
- }
46
- /**
47
- * Get video information by video id or URL
48
- *
49
- * @param videoIdOrUrl
50
- */
51
- getVideo(videoIdOrUrl) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const videoId = common_1.getQueryParameter(videoIdOrUrl, "v");
54
- const response = yield common_1.http.get(`${constants_1.WATCH_END_POINT}`, {
55
- params: { v: videoId, pbj: "1" },
56
- });
57
- if (!response.data[3].response.contents)
58
- return undefined;
59
- return new __1.Video().load(response.data);
60
- });
61
- }
62
- }
63
- exports.default = YoutubeClient;
@@ -1,2 +0,0 @@
1
- export { default as Client } from "./Client";
2
- export * from "./types";
@@ -1,12 +0,0 @@
1
- import { Channel, PlaylistCompact, VideoCompact } from "..";
2
- export declare type SearchType = "video" | "channel" | "playlist" | "all";
3
- export declare type SearchOptions = {
4
- type: SearchType;
5
- };
6
- export declare type SearchResultType<T> = T extends {
7
- type: "video";
8
- } ? VideoCompact : T extends {
9
- type: "channel";
10
- } ? Channel : T extends {
11
- type: "playlist";
12
- } ? PlaylistCompact : VideoCompact | Channel | PlaylistCompact;
@@ -1,17 +0,0 @@
1
- import { Playlist, Video, SearchResult } from ".";
2
- import { SearchResultType } from "./SearchResult";
3
- export declare type SearchType = "video" | "channel" | "playlist" | "all";
4
- export declare type SearchOptions = {
5
- type: SearchType;
6
- };
7
- /** Youtube Client */
8
- export default class Client {
9
- /** Searches for videos / playlists / channels */
10
- search<T extends SearchOptions>(query: string, searchOptions?: Partial<T>): Promise<SearchResult<T>>;
11
- /** Search for videos / playlists / channels and returns the first result */
12
- findOne<T extends SearchOptions>(query: string, searchOptions?: Partial<T>): Promise<SearchResultType<T> | undefined>;
13
- /** Get playlist information and its videos by playlist id or URL */
14
- getPlaylist(playlistIdOrUrl: string): Promise<Playlist | undefined>;
15
- /** Get video information by video id or URL */
16
- getVideo(videoIdOrUrl: string): Promise<Video | undefined>;
17
- }
@@ -1,57 +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
- /** Searches for videos / playlists / channels */
18
- search(query, searchOptions) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const options = Object.assign({ type: "all" }, searchOptions);
21
- const result = new _1.SearchResult();
22
- yield result.init(query, options);
23
- return result;
24
- });
25
- }
26
- /** Search for videos / playlists / channels and returns the first result */
27
- findOne(query, searchOptions) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- return (yield this.search(query, searchOptions)).shift();
30
- });
31
- }
32
- /** Get playlist information and its videos by playlist id or URL */
33
- getPlaylist(playlistIdOrUrl) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const playlistId = common_1.getQueryParameter(playlistIdOrUrl, "list");
36
- const response = yield common_1.http.post(`${constants_1.I_END_POINT}/browse`, {
37
- data: { browseId: `VL${playlistId}` },
38
- });
39
- if (response.data.error || response.data.alerts)
40
- return undefined;
41
- return new _1.Playlist().load(response.data);
42
- });
43
- }
44
- /** Get video information by video id or URL */
45
- getVideo(videoIdOrUrl) {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const videoId = common_1.getQueryParameter(videoIdOrUrl, "v");
48
- const response = yield common_1.http.get(`${constants_1.WATCH_END_POINT}`, {
49
- params: { v: videoId, pbj: "1" },
50
- });
51
- if (!response.data[3].response.contents)
52
- return undefined;
53
- return new _1.Video().load(response.data);
54
- });
55
- }
56
- }
57
- exports.default = Client;
@@ -1,10 +0,0 @@
1
- export { default as Client, SearchOptions, SearchType } from "./Client";
2
- export { default as Base } from "./Base";
3
- export { default as VideoCompact } from "./VideoCompact";
4
- export { default as Thumbnails } from "./Thumbnails";
5
- export { default as Channel } from "./Channel";
6
- export { default as Comment } from "./Comment";
7
- export { default as PlaylistCompact } from "./PlaylistCompact";
8
- export { default as Playlist } from "./Playlist";
9
- export { default as Video } from "./Video";
10
- export { default as SearchResult } from "./SearchResult";
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SearchResult = exports.Video = exports.Playlist = exports.PlaylistCompact = exports.Comment = exports.Channel = exports.Thumbnails = exports.VideoCompact = exports.Base = exports.Client = void 0;
7
- var Client_1 = require("./Client");
8
- Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return __importDefault(Client_1).default; } });
9
- var Base_1 = require("./Base");
10
- Object.defineProperty(exports, "Base", { enumerable: true, get: function () { return __importDefault(Base_1).default; } });
11
- var VideoCompact_1 = require("./VideoCompact");
12
- Object.defineProperty(exports, "VideoCompact", { enumerable: true, get: function () { return __importDefault(VideoCompact_1).default; } });
13
- var Thumbnails_1 = require("./Thumbnails");
14
- Object.defineProperty(exports, "Thumbnails", { enumerable: true, get: function () { return __importDefault(Thumbnails_1).default; } });
15
- var Channel_1 = require("./Channel");
16
- Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return __importDefault(Channel_1).default; } });
17
- var Comment_1 = require("./Comment");
18
- Object.defineProperty(exports, "Comment", { enumerable: true, get: function () { return __importDefault(Comment_1).default; } });
19
- var PlaylistCompact_1 = require("./PlaylistCompact");
20
- Object.defineProperty(exports, "PlaylistCompact", { enumerable: true, get: function () { return __importDefault(PlaylistCompact_1).default; } });
21
- var Playlist_1 = require("./Playlist");
22
- Object.defineProperty(exports, "Playlist", { enumerable: true, get: function () { return __importDefault(Playlist_1).default; } });
23
- var Video_1 = require("./Video");
24
- Object.defineProperty(exports, "Video", { enumerable: true, get: function () { return __importDefault(Video_1).default; } });
25
- var SearchResult_1 = require("./SearchResult");
26
- Object.defineProperty(exports, "SearchResult", { enumerable: true, get: function () { return __importDefault(SearchResult_1).default; } });
@@ -1,7 +0,0 @@
1
- /** @hidden */
2
- interface Constructor<T> {
3
- new (...args: any[]): T;
4
- }
5
- /** @hidden */
6
- export declare function extendsBuiltIn(): (target: Constructor<any>) => any;
7
- export {};
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extendsBuiltIn = void 0;
4
- /** @hidden */
5
- function extendsBuiltIn() {
6
- return (target) => {
7
- return class extends target {
8
- constructor(...args) {
9
- super(args);
10
- Object.setPrototypeOf(this, target.prototype);
11
- }
12
- };
13
- };
14
- }
15
- exports.extendsBuiltIn = extendsBuiltIn;
@@ -1,4 +0,0 @@
1
- /** @hidden */
2
- export declare const getDuration: (s: string) => number;
3
- /** @hidden */
4
- export declare const getQueryParameter: (url: string, queryName: string) => string;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getQueryParameter = exports.getDuration = void 0;
4
- const url_1 = require("url");
5
- /** @hidden */
6
- const getDuration = (s) => {
7
- s = s.replace(/:/g, ".");
8
- const spl = s.split(".");
9
- if (spl.length === 0)
10
- return +spl;
11
- else {
12
- const sumStr = spl.pop();
13
- if (sumStr !== undefined) {
14
- let sum = +sumStr;
15
- if (spl.length === 1)
16
- sum += +spl[0] * 60;
17
- if (spl.length === 2) {
18
- sum += +spl[1] * 60;
19
- sum += +spl[0] * 3600;
20
- }
21
- return sum;
22
- }
23
- else {
24
- return 0;
25
- }
26
- }
27
- };
28
- exports.getDuration = getDuration;
29
- /** @hidden */
30
- const getQueryParameter = (url, queryName) => {
31
- try {
32
- return new url_1.URL(url).searchParams.get(queryName) || url;
33
- }
34
- catch (err) {
35
- /* not an URL */
36
- return url;
37
- }
38
- };
39
- exports.getQueryParameter = getQueryParameter;
@@ -1,33 +0,0 @@
1
- /** @ignore */ /** */
2
- /// <reference types="node" />
3
- import https from "https";
4
- import { IncomingHttpHeaders } from "http";
5
- import { YoutubeRawData } from "./types";
6
- /** @hidden */
7
- interface Options extends https.RequestOptions {
8
- params: Record<string, any>;
9
- data: any;
10
- headers: Record<string, string>;
11
- }
12
- /** @hidden */
13
- interface Response<T = any> {
14
- data: T;
15
- headers: IncomingHttpHeaders;
16
- status: number | undefined;
17
- }
18
- /** @hidden */
19
- export default class HTTP {
20
- /**
21
- * Send request to Youtube
22
- */
23
- static request(partialOptions: Partial<Options>): Promise<Response>;
24
- /**
25
- * Send GET request to Youtube
26
- */
27
- static get(path: string, options: Partial<Options>): Promise<YoutubeRawData>;
28
- /**
29
- * Send POST request to Youtube
30
- */
31
- static post(path: string, options: Partial<Options>): Promise<YoutubeRawData>;
32
- }
33
- export {};