youtubei 0.0.1-rc.9 → 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 (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 +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/{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/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/{classes/Base.js → cjs/classes/SearchManager/proto/SearchProto.js} +2 -5
  49. package/dist/cjs/classes/SearchManager/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 +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/{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 +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/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 +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/{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/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/{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 +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/{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
@@ -0,0 +1,36 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ import { Base } from "../Base";
15
+ import { ReplyParser } from "./ReplyParser";
16
+ /** Represents a Reply */
17
+ var Reply = /** @class */ (function (_super) {
18
+ __extends(Reply, _super);
19
+ /** @hidden */
20
+ function Reply(attr) {
21
+ var _this = _super.call(this, attr.client) || this;
22
+ Object.assign(_this, attr);
23
+ return _this;
24
+ }
25
+ /**
26
+ * Load this instance with raw data from Youtube
27
+ *
28
+ * @hidden
29
+ */
30
+ Reply.prototype.load = function (data) {
31
+ ReplyParser.loadReply(this, data);
32
+ return this;
33
+ };
34
+ return Reply;
35
+ }(Base));
36
+ export { Reply };
@@ -0,0 +1,26 @@
1
+ import { BaseChannel } from "../BaseChannel";
2
+ import { Thumbnails } from "../Thumbnails";
3
+ var ReplyParser = /** @class */ (function () {
4
+ function ReplyParser() {
5
+ }
6
+ ReplyParser.loadReply = function (target, data) {
7
+ var authorText = data.authorText, authorThumbnail = data.authorThumbnail, authorEndpoint = data.authorEndpoint, contentText = data.contentText, publishedTimeText = data.publishedTimeText, commentId = data.commentId, likeCount = data.likeCount, authorIsChannelOwner = data.authorIsChannelOwner;
8
+ // Basic information
9
+ target.id = commentId;
10
+ target.content = contentText.runs.map(function (r) { return r.text; }).join("");
11
+ target.publishDate = publishedTimeText.runs.shift().text;
12
+ target.likeCount = likeCount;
13
+ target.isAuthorChannelOwner = authorIsChannelOwner;
14
+ // Author
15
+ var browseId = authorEndpoint.browseEndpoint.browseId;
16
+ target.author = new BaseChannel({
17
+ id: browseId,
18
+ name: authorText.simpleText,
19
+ thumbnails: new Thumbnails().load(authorThumbnail.thumbnails),
20
+ client: target.client,
21
+ });
22
+ return target;
23
+ };
24
+ return ReplyParser;
25
+ }());
26
+ export { ReplyParser };
@@ -0,0 +1,2 @@
1
+ export * from "./Reply";
2
+ export * from "./ReplyParser";
@@ -0,0 +1,159 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (_) try {
30
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ var __read = (this && this.__read) || function (o, n) {
51
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
52
+ if (!m) return o;
53
+ var i = m.call(o), r, ar = [], e;
54
+ try {
55
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
56
+ }
57
+ catch (error) { e = { error: error }; }
58
+ finally {
59
+ try {
60
+ if (r && !r.done && (m = i["return"])) m.call(i);
61
+ }
62
+ finally { if (e) throw e.error; }
63
+ }
64
+ return ar;
65
+ };
66
+ var __spread = (this && this.__spread) || function () {
67
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
68
+ return ar;
69
+ };
70
+ import { I_END_POINT } from "../../constants";
71
+ import { Continuable } from "../Continuable";
72
+ import { SearchResultParser } from "./SearchManagerParser";
73
+ import { optionsToProto, SearchProto } from "./proto";
74
+ /**
75
+ * Represents search result, usually returned from `client.search();`.
76
+ *
77
+ * {@link SearchManager} is a helper class to manage search result
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const searchManager = await youtube.search("Keyword");
82
+ *
83
+ * console.log(searchManager.items); // search result from first page
84
+ *
85
+ * let nextSearchResult = await SearchManager.next();
86
+ * console.log(nextSearchResult); // search result from second page
87
+ *
88
+ * nextSearchResult = await SearchManager.next();
89
+ * console.log(nextSearchResult); // search result from third page
90
+ *
91
+ * console.log(searchManager.items); // search result from first, second, and third page.
92
+ * ```
93
+ *
94
+ * @noInheritDoc
95
+ */
96
+ var SearchManager = /** @class */ (function (_super) {
97
+ __extends(SearchManager, _super);
98
+ /** @hidden */
99
+ function SearchManager(_a) {
100
+ var client = _a.client;
101
+ return _super.call(this, { client: client }) || this;
102
+ }
103
+ /**
104
+ * Initialize data from search
105
+ *
106
+ * @param query Search query
107
+ * @param options Search Options
108
+ */
109
+ SearchManager.prototype.search = function (query, options) {
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var bufferParams, response, _a, data, continuation;
112
+ var _b;
113
+ return __generator(this, function (_c) {
114
+ switch (_c.label) {
115
+ case 0:
116
+ this.items = [];
117
+ this.estimatedResults = 0;
118
+ bufferParams = SearchProto.SearchOptions.encode(optionsToProto(options));
119
+ return [4 /*yield*/, this.client.http.post(I_END_POINT + "/search", {
120
+ data: {
121
+ query: query,
122
+ params: Buffer.from(bufferParams).toString("base64"),
123
+ },
124
+ })];
125
+ case 1:
126
+ response = _c.sent();
127
+ this.estimatedResults = +response.data.estimatedResults;
128
+ if (this.estimatedResults > 0) {
129
+ _a = SearchResultParser.parseInitialSearchResult(response.data, this.client), data = _a.data, continuation = _a.continuation;
130
+ (_b = this.items).push.apply(_b, __spread(data));
131
+ this.continuation = continuation;
132
+ }
133
+ return [2 /*return*/, this];
134
+ }
135
+ });
136
+ });
137
+ };
138
+ SearchManager.prototype.fetch = function () {
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var response, _a, data, continuation;
141
+ return __generator(this, function (_b) {
142
+ switch (_b.label) {
143
+ case 0: return [4 /*yield*/, this.client.http.post(I_END_POINT + "/search", {
144
+ data: { continuation: this.continuation },
145
+ })];
146
+ case 1:
147
+ response = _b.sent();
148
+ _a = SearchResultParser.parseContinuationSearchResult(response.data, this.client), data = _a.data, continuation = _a.continuation;
149
+ return [2 /*return*/, {
150
+ items: data,
151
+ continuation: continuation,
152
+ }];
153
+ }
154
+ });
155
+ });
156
+ };
157
+ return SearchManager;
158
+ }(Continuable));
159
+ export { SearchManager };
@@ -0,0 +1,62 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
12
+ import { getContinuationFromItems } from "../../common";
13
+ import { BaseChannel } from "../BaseChannel";
14
+ import { PlaylistCompact } from "../PlaylistCompact";
15
+ import { VideoCompact } from "../VideoCompact";
16
+ var SearchResultParser = /** @class */ (function () {
17
+ function SearchResultParser() {
18
+ }
19
+ SearchResultParser.parseInitialSearchResult = function (data, client) {
20
+ var sectionListContents = data.contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer
21
+ .contents;
22
+ return {
23
+ data: SearchResultParser.parseSearchResult(sectionListContents, client),
24
+ continuation: getContinuationFromItems(sectionListContents),
25
+ };
26
+ };
27
+ SearchResultParser.parseContinuationSearchResult = function (data, client) {
28
+ var sectionListContents = data.onResponseReceivedCommands[0].appendContinuationItemsAction.continuationItems;
29
+ return {
30
+ data: SearchResultParser.parseSearchResult(sectionListContents, client),
31
+ continuation: getContinuationFromItems(sectionListContents),
32
+ };
33
+ };
34
+ SearchResultParser.parseSearchResult = function (sectionListContents, client) {
35
+ var e_1, _a;
36
+ var rawContents = sectionListContents
37
+ .filter(function (c) { return "itemSectionRenderer" in c; })
38
+ .at(-1).itemSectionRenderer.contents;
39
+ var contents = [];
40
+ try {
41
+ for (var rawContents_1 = __values(rawContents), rawContents_1_1 = rawContents_1.next(); !rawContents_1_1.done; rawContents_1_1 = rawContents_1.next()) {
42
+ var c = rawContents_1_1.value;
43
+ if ("playlistRenderer" in c)
44
+ contents.push(new PlaylistCompact({ client: client }).load(c.playlistRenderer));
45
+ else if ("videoRenderer" in c)
46
+ contents.push(new VideoCompact({ client: client }).load(c.videoRenderer));
47
+ else if ("channelRenderer" in c)
48
+ contents.push(new BaseChannel({ client: client }).load(c.channelRenderer));
49
+ }
50
+ }
51
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
52
+ finally {
53
+ try {
54
+ if (rawContents_1_1 && !rawContents_1_1.done && (_a = rawContents_1.return)) _a.call(rawContents_1);
55
+ }
56
+ finally { if (e_1) throw e_1.error; }
57
+ }
58
+ return contents;
59
+ };
60
+ return SearchResultParser;
61
+ }());
62
+ export { SearchResultParser };
@@ -0,0 +1,2 @@
1
+ export * from "./SearchManager";
2
+ export * from "./SearchManagerParser";
@@ -0,0 +1,39 @@
1
+ import proto from "protocol-buffers";
2
+ // TODO move this to .proto file
3
+ export var SearchProto = proto("\n\tmessage SearchOptions {\n\t\tmessage Options {\n\t\t\toptional int32 uploadDate = 1;\n\t\t\toptional int32 type = 2;\n\t\t\toptional int32 duration = 3;\n\t\t}\n\n\t\toptional int32 sortBy = 1;\n\t\toptional Options options = 2;\n\t}\n");
4
+ var searchUploadDateProto = {
5
+ all: 0,
6
+ hour: 1,
7
+ today: 2,
8
+ week: 3,
9
+ month: 4,
10
+ year: 5,
11
+ };
12
+ var searchTypeProto = {
13
+ all: 0,
14
+ video: 1,
15
+ channel: 2,
16
+ playlist: 3,
17
+ };
18
+ var searchDurationProto = {
19
+ all: 0,
20
+ short: 1,
21
+ long: 2,
22
+ medium: 3,
23
+ };
24
+ var searchSortProto = {
25
+ relevance: 0,
26
+ rating: 1,
27
+ date: 2,
28
+ view: 3,
29
+ };
30
+ export var optionsToProto = function (options) {
31
+ return {
32
+ sortBy: options.sortBy && searchSortProto[options.sortBy],
33
+ options: {
34
+ duration: options.duration && searchDurationProto[options.duration],
35
+ type: options.type && searchTypeProto[options.type],
36
+ uploadDate: options.uploadDate && searchUploadDateProto[options.uploadDate],
37
+ },
38
+ };
39
+ };
@@ -0,0 +1,109 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
15
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
19
+ };
20
+ var __read = (this && this.__read) || function (o, n) {
21
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
22
+ if (!m) return o;
23
+ var i = m.call(o), r, ar = [], e;
24
+ try {
25
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
26
+ }
27
+ catch (error) { e = { error: error }; }
28
+ finally {
29
+ try {
30
+ if (r && !r.done && (m = i["return"])) m.call(i);
31
+ }
32
+ finally { if (e) throw e.error; }
33
+ }
34
+ return ar;
35
+ };
36
+ var __spread = (this && this.__spread) || function () {
37
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
38
+ return ar;
39
+ };
40
+ import { extendsBuiltIn } from "../../common";
41
+ /**
42
+ * Represents Thumbnails, usually found inside Playlist / Channel / Video, etc.
43
+ *
44
+ * {@link Thumbnails} is an array of {@link Thumbnail}
45
+ *
46
+ * @noInheritDoc
47
+ */
48
+ var Thumbnails = /** @class */ (function (_super) {
49
+ __extends(Thumbnails, _super);
50
+ /** @hidden */
51
+ function Thumbnails() {
52
+ return _super.call(this) || this;
53
+ }
54
+ Thumbnails_1 = Thumbnails;
55
+ Object.defineProperty(Thumbnails.prototype, "min", {
56
+ /**
57
+ * Returns thumbnail with the lowest resolution, usually the first element of the Thumbnails array
58
+ *
59
+ * @example
60
+ * ```js
61
+ * const min = video.thumbnails.min;
62
+ * ```
63
+ */
64
+ get: function () {
65
+ return Thumbnails_1.parseThumbnailUrl(this[0]);
66
+ },
67
+ enumerable: false,
68
+ configurable: true
69
+ });
70
+ Object.defineProperty(Thumbnails.prototype, "best", {
71
+ /**
72
+ * Returns thumbnail with the highest resolution, usually the last element of the Thumbnails array
73
+ *
74
+ * @example
75
+ * ```js
76
+ * const min = video.thumbnails.min;
77
+ * ```
78
+ */
79
+ get: function () {
80
+ return Thumbnails_1.parseThumbnailUrl(this[this.length - 1]);
81
+ },
82
+ enumerable: false,
83
+ configurable: true
84
+ });
85
+ /**
86
+ * Load this instance with raw data from Youtube
87
+ *
88
+ * @hidden
89
+ */
90
+ Thumbnails.prototype.load = function (thumbnails) {
91
+ this.push.apply(this, __spread(thumbnails));
92
+ return this;
93
+ };
94
+ Thumbnails.parseThumbnailUrl = function (_a) {
95
+ var url = _a.url;
96
+ if (url.startsWith("//"))
97
+ return "https:" + url;
98
+ if (!url.startsWith("https://"))
99
+ return "https://" + url;
100
+ else
101
+ return url;
102
+ };
103
+ var Thumbnails_1;
104
+ Thumbnails = Thumbnails_1 = __decorate([
105
+ extendsBuiltIn()
106
+ ], Thumbnails);
107
+ return Thumbnails;
108
+ }(Array));
109
+ export { Thumbnails };
@@ -0,0 +1 @@
1
+ export * from "./Thumbnails";
@@ -0,0 +1,39 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ import { BaseVideo } from "../BaseVideo";
15
+ import { VideoComments } from "./VideoComments";
16
+ import { VideoParser } from "./VideoParser";
17
+ /** Represents a Video, usually returned from `client.getVideo()` */
18
+ var Video = /** @class */ (function (_super) {
19
+ __extends(Video, _super);
20
+ /** @hidden */
21
+ function Video(attr) {
22
+ var _this = _super.call(this, attr) || this;
23
+ Object.assign(_this, attr);
24
+ _this.comments = new VideoComments({ client: attr.client, video: _this });
25
+ return _this;
26
+ }
27
+ /**
28
+ * Load this instance with raw data from Youtube
29
+ *
30
+ * @hidden
31
+ */
32
+ Video.prototype.load = function (data) {
33
+ _super.prototype.load.call(this, data);
34
+ VideoParser.loadVideo(this, data);
35
+ return this;
36
+ };
37
+ return Video;
38
+ }(BaseVideo));
39
+ export { Video };
@@ -0,0 +1,101 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ extendStatics(d, b);
10
+ function __() { this.constructor = d; }
11
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
+ };
13
+ })();
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
25
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (_) try {
30
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
50
+ import { I_END_POINT } from "../../constants";
51
+ import { Continuable } from "../Continuable";
52
+ import { VideoParser } from "./VideoParser";
53
+ /**
54
+ * {@link Continuable} of videos inside a {@link Video}
55
+ *
56
+ * @example
57
+ * ```js
58
+ * const video = await youtube.getVideo(VIDEO_ID);
59
+ * await video.comments.next();
60
+ * console.log(video.comments) // first 20 comments
61
+ *
62
+ * let newComments = await video.comments.next();
63
+ * console.log(newComments) // 20 loaded comments
64
+ * console.log(video.comments) // first 40 comments
65
+ *
66
+ * await video.comments.next(0); // load the rest of the comments in the video
67
+ * ```
68
+ *
69
+ * @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!)
70
+ *
71
+ * @returns Loaded comments
72
+ */
73
+ var VideoComments = /** @class */ (function (_super) {
74
+ __extends(VideoComments, _super);
75
+ /** @hidden */
76
+ function VideoComments(_a) {
77
+ var client = _a.client, video = _a.video;
78
+ var _this = _super.call(this, { client: client, strictContinuationCheck: true }) || this;
79
+ _this.video = video;
80
+ return _this;
81
+ }
82
+ VideoComments.prototype.fetch = function () {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var response, items, continuation;
85
+ return __generator(this, function (_a) {
86
+ switch (_a.label) {
87
+ case 0: return [4 /*yield*/, this.client.http.post(I_END_POINT + "/next", {
88
+ data: { continuation: this.continuation },
89
+ })];
90
+ case 1:
91
+ response = _a.sent();
92
+ items = VideoParser.parseComments(response.data, this.video);
93
+ continuation = VideoParser.parseCommentContinuation(response.data);
94
+ return [2 /*return*/, { continuation: continuation, items: items }];
95
+ }
96
+ });
97
+ });
98
+ };
99
+ return VideoComments;
100
+ }(Continuable));
101
+ export { VideoComments };
@@ -0,0 +1,31 @@
1
+ import { getContinuationFromItems, mapFilter } from "../../common";
2
+ import { BaseVideoParser } from "../BaseVideo";
3
+ import { Comment } from "../Comment";
4
+ var VideoParser = /** @class */ (function () {
5
+ function VideoParser() {
6
+ }
7
+ VideoParser.loadVideo = function (target, data) {
8
+ var videoInfo = BaseVideoParser.parseRawData(data);
9
+ target.duration = +videoInfo.videoDetails.lengthSeconds;
10
+ var itemSectionRenderer = data[3].response.contents.twoColumnWatchNextResults.results.results.contents
11
+ .reverse()
12
+ .find(function (c) { return c.itemSectionRenderer; }).itemSectionRenderer;
13
+ target.comments.continuation = getContinuationFromItems(itemSectionRenderer.contents);
14
+ return target;
15
+ };
16
+ VideoParser.parseComments = function (data, video) {
17
+ var endpoints = data.onResponseReceivedEndpoints.at(-1);
18
+ var continuationItems = (endpoints.reloadContinuationItemsCommand || endpoints.appendContinuationItemsAction).continuationItems;
19
+ var comments = mapFilter(continuationItems, "commentThreadRenderer");
20
+ return comments.map(function (c) {
21
+ return new Comment({ video: video, client: video.client }).load(c);
22
+ });
23
+ };
24
+ VideoParser.parseCommentContinuation = function (data) {
25
+ var endpoints = data.onResponseReceivedEndpoints.at(-1);
26
+ var continuationItems = (endpoints.reloadContinuationItemsCommand || endpoints.appendContinuationItemsAction).continuationItems;
27
+ return getContinuationFromItems(continuationItems);
28
+ };
29
+ return VideoParser;
30
+ }());
31
+ export { VideoParser };
@@ -0,0 +1,2 @@
1
+ export * from "./Video";
2
+ export * from "./VideoParser";