youtubei 0.0.1-rc.8 → 1.0.0-rc.2
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.
- package/LICENSE +21 -21
- package/README.md +50 -53
- package/dist/cjs/classes/Base/Base.js +10 -0
- package/dist/cjs/classes/Base/index.js +13 -0
- package/dist/cjs/classes/BaseChannel/BaseChannel.js +31 -0
- package/dist/cjs/classes/BaseChannel/BaseChannelParser.js +24 -0
- package/dist/cjs/classes/BaseChannel/ChannelPlaylists.js +57 -0
- package/dist/cjs/classes/BaseChannel/ChannelVideos.js +57 -0
- package/dist/cjs/classes/BaseChannel/index.js +16 -0
- package/dist/cjs/classes/BaseVideo/BaseVideo.js +34 -0
- package/dist/cjs/classes/BaseVideo/BaseVideoParser.js +82 -0
- package/dist/cjs/classes/BaseVideo/VideoRelated.js +39 -0
- package/dist/cjs/classes/BaseVideo/index.js +15 -0
- package/dist/cjs/classes/Channel/Channel.js +24 -0
- package/dist/cjs/classes/Channel/ChannelParser.js +55 -0
- package/dist/cjs/classes/Channel/index.js +14 -0
- package/dist/cjs/classes/Chat/Chat.js +23 -0
- package/dist/cjs/classes/Chat/ChatParser.js +21 -0
- package/dist/cjs/classes/Chat/index.js +14 -0
- package/dist/cjs/classes/Client/Client.js +101 -0
- package/dist/cjs/classes/Client/HTTP.js +59 -0
- package/dist/cjs/classes/Client/index.js +13 -0
- package/dist/cjs/classes/Comment/Comment.js +29 -0
- package/dist/cjs/classes/Comment/CommentParser.js +43 -0
- package/dist/cjs/classes/Comment/CommentReplies.js +36 -0
- package/dist/cjs/classes/Comment/index.js +15 -0
- package/dist/cjs/classes/Continuable/Continuable.js +43 -0
- package/dist/cjs/classes/Continuable/index.js +13 -0
- package/dist/cjs/classes/LiveVideo/LiveVideo.js +84 -0
- package/dist/cjs/classes/LiveVideo/LiveVideoParser.js +29 -0
- package/dist/cjs/classes/LiveVideo/index.js +14 -0
- package/dist/cjs/classes/MixPlaylist/MixPlaylist.js +25 -0
- package/dist/cjs/classes/MixPlaylist/MixPlaylistParser.js +27 -0
- package/dist/cjs/classes/MixPlaylist/index.js +14 -0
- package/dist/cjs/classes/Playlist/Playlist.js +25 -0
- package/dist/cjs/classes/Playlist/PlaylistParser.js +83 -0
- package/dist/cjs/classes/Playlist/PlaylistVideos.js +50 -0
- package/dist/cjs/classes/Playlist/index.js +15 -0
- package/dist/cjs/classes/PlaylistCompact/PlaylistCompact.js +45 -0
- package/dist/cjs/classes/PlaylistCompact/PlaylistCompactParser.js +28 -0
- package/dist/cjs/classes/PlaylistCompact/index.js +14 -0
- package/dist/cjs/classes/Reply/Reply.js +23 -0
- package/dist/cjs/classes/Reply/ReplyParser.js +26 -0
- package/dist/cjs/classes/Reply/index.js +14 -0
- package/dist/cjs/classes/SearchResult/SearchResult.js +85 -0
- package/dist/cjs/classes/SearchResult/SearchResultParser.js +40 -0
- package/dist/cjs/classes/SearchResult/index.js +14 -0
- package/dist/cjs/classes/SearchResult/proto/SearchProto.js +2 -0
- package/dist/cjs/classes/SearchResult/proto/index.js +57 -0
- package/dist/{classes → cjs/classes/Thumbnails}/Thumbnails.js +67 -50
- package/dist/cjs/classes/Thumbnails/index.js +13 -0
- package/dist/cjs/classes/Video/Video.js +26 -0
- package/dist/cjs/classes/Video/VideoComments.js +53 -0
- package/dist/cjs/classes/Video/VideoParser.js +29 -0
- package/dist/cjs/classes/Video/index.js +15 -0
- package/dist/cjs/classes/VideoCompact/VideoCompact.js +49 -0
- package/dist/cjs/classes/VideoCompact/VideoCompactParser.js +36 -0
- package/dist/cjs/classes/VideoCompact/index.js +14 -0
- package/dist/cjs/classes/index.js +29 -0
- package/dist/{common → cjs/common}/decorators.js +14 -15
- package/dist/cjs/common/helper.js +45 -0
- package/dist/{common → cjs/common}/index.js +16 -23
- package/dist/{common → cjs/common}/mixins.js +14 -12
- package/dist/{common → cjs/common}/types.js +2 -2
- package/dist/{constants.js → cjs/constants.js} +10 -10
- package/dist/{index.js → cjs/index.js} +13 -13
- package/dist/esm/classes/Base/Base.js +8 -0
- package/dist/esm/classes/Base/index.js +1 -0
- package/dist/esm/classes/BaseChannel/BaseChannel.js +48 -0
- package/dist/esm/classes/BaseChannel/BaseChannelParser.js +24 -0
- package/dist/esm/classes/BaseChannel/ChannelPlaylists.js +109 -0
- package/dist/esm/classes/BaseChannel/ChannelVideos.js +109 -0
- package/dist/esm/classes/BaseChannel/index.js +4 -0
- package/dist/esm/classes/BaseVideo/BaseVideo.js +51 -0
- package/dist/esm/classes/BaseVideo/BaseVideoParser.js +93 -0
- package/dist/esm/classes/BaseVideo/VideoRelated.js +87 -0
- package/dist/esm/classes/BaseVideo/index.js +3 -0
- package/dist/esm/classes/Channel/Channel.js +37 -0
- package/dist/esm/classes/Channel/ChannelParser.js +77 -0
- package/dist/esm/classes/Channel/index.js +2 -0
- package/dist/esm/classes/Chat/Chat.js +36 -0
- package/dist/esm/classes/Chat/ChatParser.js +21 -0
- package/dist/esm/classes/Chat/index.js +2 -0
- package/dist/esm/classes/Client/Client.js +176 -0
- package/dist/esm/classes/Client/HTTP.js +112 -0
- package/dist/esm/classes/Client/index.js +1 -0
- package/dist/esm/classes/Comment/Comment.js +46 -0
- package/dist/esm/classes/Comment/CommentParser.js +45 -0
- package/dist/esm/classes/Comment/CommentReplies.js +84 -0
- package/dist/esm/classes/Comment/index.js +3 -0
- package/dist/esm/classes/Continuable/Continuable.js +125 -0
- package/dist/esm/classes/Continuable/index.js +1 -0
- package/dist/esm/classes/LiveVideo/LiveVideo.js +160 -0
- package/dist/esm/classes/LiveVideo/LiveVideoParser.js +29 -0
- package/dist/esm/classes/LiveVideo/index.js +2 -0
- package/dist/esm/classes/MixPlaylist/MixPlaylist.js +38 -0
- package/dist/esm/classes/MixPlaylist/MixPlaylistParser.js +49 -0
- package/dist/esm/classes/MixPlaylist/index.js +2 -0
- package/dist/esm/classes/Playlist/Playlist.js +38 -0
- package/dist/esm/classes/Playlist/PlaylistParser.js +105 -0
- package/dist/esm/classes/Playlist/PlaylistVideos.js +98 -0
- package/dist/esm/classes/Playlist/index.js +3 -0
- package/dist/esm/classes/PlaylistCompact/PlaylistCompact.js +90 -0
- package/dist/esm/classes/PlaylistCompact/PlaylistCompactParser.js +28 -0
- package/dist/esm/classes/PlaylistCompact/index.js +2 -0
- package/dist/esm/classes/Reply/Reply.js +36 -0
- package/dist/esm/classes/Reply/ReplyParser.js +26 -0
- package/dist/esm/classes/Reply/index.js +2 -0
- package/dist/esm/classes/SearchResult/SearchResult.js +161 -0
- package/dist/esm/classes/SearchResult/SearchResultParser.js +62 -0
- package/dist/esm/classes/SearchResult/index.js +2 -0
- package/dist/esm/classes/SearchResult/proto/SearchProto.js +1 -0
- package/dist/esm/classes/SearchResult/proto/index.js +39 -0
- package/dist/esm/classes/Thumbnails/Thumbnails.js +109 -0
- package/dist/esm/classes/Thumbnails/index.js +1 -0
- package/dist/esm/classes/Video/Video.js +39 -0
- package/dist/esm/classes/Video/VideoComments.js +101 -0
- package/dist/esm/classes/Video/VideoParser.js +31 -0
- package/dist/esm/classes/Video/index.js +3 -0
- package/dist/esm/classes/VideoCompact/VideoCompact.js +98 -0
- package/dist/esm/classes/VideoCompact/VideoCompactParser.js +36 -0
- package/dist/esm/classes/VideoCompact/index.js +2 -0
- package/dist/esm/classes/index.js +17 -0
- package/dist/esm/common/decorators.js +30 -0
- package/dist/esm/common/helper.js +61 -0
- package/dist/esm/common/index.js +4 -0
- package/dist/esm/common/mixins.js +10 -0
- package/dist/esm/common/types.js +1 -0
- package/dist/esm/constants.js +7 -0
- package/dist/esm/index.js +1 -0
- package/dist/typings/classes/Base/Base.d.ts +11 -0
- package/dist/typings/classes/Base/index.d.ts +1 -0
- package/dist/typings/classes/BaseChannel/BaseChannel.d.ts +43 -0
- package/dist/typings/classes/BaseChannel/BaseChannelParser.d.ts +7 -0
- package/dist/typings/classes/BaseChannel/ChannelPlaylists.d.ts +30 -0
- package/dist/typings/classes/BaseChannel/ChannelVideos.d.ts +30 -0
- package/dist/typings/classes/BaseChannel/index.d.ts +4 -0
- package/dist/typings/classes/BaseVideo/BaseVideo.d.ts +59 -0
- package/dist/typings/classes/BaseVideo/BaseVideoParser.d.ts +14 -0
- package/dist/typings/classes/BaseVideo/VideoRelated.d.ts +21 -0
- package/dist/typings/classes/BaseVideo/index.d.ts +3 -0
- package/dist/typings/classes/Channel/Channel.d.ts +33 -0
- package/dist/typings/classes/Channel/ChannelParser.d.ts +6 -0
- package/dist/typings/classes/Channel/index.d.ts +2 -0
- package/dist/typings/classes/Chat/Chat.d.ts +33 -0
- package/dist/typings/classes/Chat/ChatParser.d.ts +5 -0
- package/dist/typings/classes/Chat/index.d.ts +2 -0
- package/dist/typings/classes/Client/Client.d.ts +41 -0
- package/dist/typings/classes/Client/HTTP.d.ts +21 -0
- package/dist/typings/classes/Client/index.d.ts +1 -0
- package/dist/typings/classes/Comment/Comment.d.ts +51 -0
- package/dist/typings/classes/Comment/CommentParser.d.ts +8 -0
- package/dist/typings/classes/Comment/CommentReplies.d.ts +17 -0
- package/dist/typings/classes/Comment/index.d.ts +3 -0
- package/dist/typings/classes/Continuable/Continuable.d.ts +24 -0
- package/dist/typings/classes/Continuable/index.d.ts +1 -0
- package/dist/typings/classes/LiveVideo/LiveVideo.d.ts +46 -0
- package/dist/typings/classes/LiveVideo/LiveVideoParser.d.ts +10 -0
- package/dist/typings/classes/LiveVideo/index.d.ts +2 -0
- package/dist/typings/classes/MixPlaylist/MixPlaylist.d.ts +29 -0
- package/dist/typings/classes/MixPlaylist/MixPlaylistParser.d.ts +6 -0
- package/dist/typings/classes/MixPlaylist/index.d.ts +2 -0
- package/dist/typings/classes/Playlist/Playlist.d.ts +39 -0
- package/dist/typings/classes/Playlist/PlaylistParser.d.ts +16 -0
- package/dist/typings/classes/Playlist/PlaylistVideos.d.ts +31 -0
- package/dist/typings/classes/Playlist/index.d.ts +3 -0
- package/dist/typings/classes/PlaylistCompact/PlaylistCompact.d.ts +43 -0
- package/dist/typings/classes/PlaylistCompact/PlaylistCompactParser.d.ts +5 -0
- package/dist/typings/classes/PlaylistCompact/index.d.ts +2 -0
- package/dist/typings/classes/Reply/Reply.d.ts +43 -0
- package/dist/typings/classes/Reply/ReplyParser.d.ts +5 -0
- package/dist/typings/classes/Reply/index.d.ts +2 -0
- package/dist/typings/classes/SearchResult/SearchResult.d.ts +53 -0
- package/dist/typings/classes/SearchResult/SearchResultParser.d.ts +13 -0
- package/dist/typings/classes/SearchResult/index.d.ts +2 -0
- package/dist/typings/classes/SearchResult/proto/SearchProto.d.ts +13 -0
- package/dist/typings/classes/SearchResult/proto/index.d.ts +24 -0
- package/dist/typings/classes/Thumbnails/Thumbnails.d.ts +41 -0
- package/dist/typings/classes/Thumbnails/index.d.ts +1 -0
- package/dist/typings/classes/Video/Video.d.ts +24 -0
- package/dist/typings/classes/Video/VideoComments.d.ts +34 -0
- package/dist/typings/classes/Video/VideoParser.d.ts +8 -0
- package/dist/typings/classes/Video/index.d.ts +3 -0
- package/dist/typings/classes/VideoCompact/VideoCompact.d.ts +57 -0
- package/dist/typings/classes/VideoCompact/VideoCompactParser.d.ts +5 -0
- package/dist/typings/classes/VideoCompact/index.d.ts +2 -0
- package/dist/typings/classes/index.d.ts +17 -0
- package/dist/{common → typings/common}/decorators.d.ts +5 -7
- package/dist/typings/common/helper.d.ts +5 -0
- package/dist/typings/common/index.d.ts +4 -0
- package/dist/typings/common/mixins.d.ts +1 -0
- package/dist/{common → typings/common}/types.d.ts +1 -2
- package/dist/{constants.d.ts → typings/constants.d.ts} +7 -7
- package/dist/{index.d.ts → typings/index.d.ts} +1 -1
- package/package.json +68 -53
- package/CHANGELOG.md +0 -6
- package/dist/classes/Base.d.ts +0 -8
- package/dist/classes/Base.js +0 -10
- package/dist/classes/Channel.d.ts +0 -63
- package/dist/classes/Channel.js +0 -115
- package/dist/classes/Chat.d.ts +0 -35
- package/dist/classes/Chat.js +0 -34
- package/dist/classes/Client.d.ts +0 -17
- package/dist/classes/Client.js +0 -59
- package/dist/classes/Comment.d.ts +0 -51
- package/dist/classes/Comment.js +0 -47
- package/dist/classes/LiveVideo.d.ts +0 -20
- package/dist/classes/LiveVideo.js +0 -59
- package/dist/classes/Playlist.d.ts +0 -66
- package/dist/classes/Playlist.js +0 -133
- package/dist/classes/PlaylistCompact.d.ts +0 -35
- package/dist/classes/PlaylistCompact.js +0 -47
- package/dist/classes/SearchResult.d.ts +0 -51
- package/dist/classes/SearchResult.js +0 -121
- package/dist/classes/Thumbnails.d.ts +0 -26
- package/dist/classes/Video.d.ts +0 -90
- package/dist/classes/Video.js +0 -153
- package/dist/classes/VideoCompact.d.ts +0 -46
- package/dist/classes/VideoCompact.js +0 -53
- package/dist/classes/index.d.ts +0 -12
- package/dist/classes/index.js +0 -30
- package/dist/common/helper.d.ts +0 -4
- package/dist/common/helper.js +0 -39
- package/dist/common/http.d.ts +0 -33
- package/dist/common/http.js +0 -105
- package/dist/common/index.d.ts +0 -5
- 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,161 @@
|
|
|
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 "./SearchResultParser";
|
|
73
|
+
import { optionsToProto, SearchProto } from "./proto";
|
|
74
|
+
/**
|
|
75
|
+
* Represents search result, usually returned from `client.search();`.
|
|
76
|
+
*
|
|
77
|
+
* {@link SearchResult} is a helper class to manage search result
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const result = await youtube.search("Keyword");
|
|
82
|
+
*
|
|
83
|
+
* console.log(result.items); // search result from first page
|
|
84
|
+
*
|
|
85
|
+
* let nextSearchResult = await result.next();
|
|
86
|
+
* console.log(nextSearchResult); // search result from second page
|
|
87
|
+
*
|
|
88
|
+
* nextSearchResult = await result.next();
|
|
89
|
+
* console.log(nextSearchResult); // search result from third page
|
|
90
|
+
*
|
|
91
|
+
* console.log(result.items); // search result from first, second, and third page.
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @noInheritDoc
|
|
95
|
+
*/
|
|
96
|
+
var SearchResult = /** @class */ (function (_super) {
|
|
97
|
+
__extends(SearchResult, _super);
|
|
98
|
+
/** @hidden */
|
|
99
|
+
function SearchResult(_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
|
+
* @hidden
|
|
110
|
+
*/
|
|
111
|
+
SearchResult.prototype.search = function (query, options) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var bufferParams, response, _a, data, continuation;
|
|
114
|
+
var _b;
|
|
115
|
+
return __generator(this, function (_c) {
|
|
116
|
+
switch (_c.label) {
|
|
117
|
+
case 0:
|
|
118
|
+
this.items = [];
|
|
119
|
+
this.estimatedResults = 0;
|
|
120
|
+
bufferParams = SearchProto.SearchOptions.encode(optionsToProto(options));
|
|
121
|
+
return [4 /*yield*/, this.client.http.post(I_END_POINT + "/search", {
|
|
122
|
+
data: {
|
|
123
|
+
query: query,
|
|
124
|
+
params: Buffer.from(bufferParams).toString("base64"),
|
|
125
|
+
},
|
|
126
|
+
})];
|
|
127
|
+
case 1:
|
|
128
|
+
response = _c.sent();
|
|
129
|
+
this.estimatedResults = +response.data.estimatedResults;
|
|
130
|
+
if (this.estimatedResults > 0) {
|
|
131
|
+
_a = SearchResultParser.parseInitialSearchResult(response.data, this.client), data = _a.data, continuation = _a.continuation;
|
|
132
|
+
(_b = this.items).push.apply(_b, __spread(data));
|
|
133
|
+
this.continuation = continuation;
|
|
134
|
+
}
|
|
135
|
+
return [2 /*return*/, this];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
SearchResult.prototype.fetch = function () {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
var response, _a, data, continuation;
|
|
143
|
+
return __generator(this, function (_b) {
|
|
144
|
+
switch (_b.label) {
|
|
145
|
+
case 0: return [4 /*yield*/, this.client.http.post(I_END_POINT + "/search", {
|
|
146
|
+
data: { continuation: this.continuation },
|
|
147
|
+
})];
|
|
148
|
+
case 1:
|
|
149
|
+
response = _b.sent();
|
|
150
|
+
_a = SearchResultParser.parseContinuationSearchResult(response.data, this.client), data = _a.data, continuation = _a.continuation;
|
|
151
|
+
return [2 /*return*/, {
|
|
152
|
+
items: data,
|
|
153
|
+
continuation: continuation,
|
|
154
|
+
}];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
return SearchResult;
|
|
160
|
+
}(Continuable));
|
|
161
|
+
export { SearchResult };
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 };
|