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.
- 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 +13 -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 +13 -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 +13 -0
- package/dist/cjs/classes/Continuable/Continuable.js +43 -0
- package/dist/cjs/classes/Continuable/index.js +13 -0
- package/dist/{classes → cjs/classes/LiveVideo}/LiveVideo.js +84 -89
- 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/SearchManager/SearchManager.js +83 -0
- package/dist/cjs/classes/SearchManager/SearchManagerParser.js +40 -0
- package/dist/cjs/classes/SearchManager/index.js +14 -0
- package/dist/{classes/Base.js → cjs/classes/SearchManager/proto/SearchProto.js} +2 -5
- package/dist/cjs/classes/SearchManager/proto/index.js +57 -0
- package/dist/{classes → cjs/classes/Thumbnails}/Thumbnails.js +67 -66
- 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 +14 -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 -14
- 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 +1 -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 +1 -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 +1 -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/SearchManager/SearchManager.js +159 -0
- package/dist/esm/classes/SearchManager/SearchManagerParser.js +62 -0
- package/dist/esm/classes/SearchManager/index.js +2 -0
- package/dist/esm/classes/SearchManager/proto/SearchProto.js +1 -0
- package/dist/esm/classes/SearchManager/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 +2 -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 +1 -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 +1 -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 +1 -0
- package/dist/typings/classes/Continuable/Continuable.d.ts +24 -0
- package/dist/typings/classes/Continuable/index.d.ts +1 -0
- package/dist/{classes → typings/classes/LiveVideo}/LiveVideo.d.ts +46 -44
- 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/SearchManager/SearchManager.d.ts +51 -0
- package/dist/typings/classes/SearchManager/SearchManagerParser.d.ts +13 -0
- package/dist/typings/classes/SearchManager/index.d.ts +2 -0
- package/dist/typings/classes/SearchManager/proto/SearchProto.d.ts +13 -0
- package/dist/typings/classes/SearchManager/proto/index.d.ts +24 -0
- package/dist/{classes → typings/classes/Thumbnails}/Thumbnails.d.ts +41 -42
- 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 +2 -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 -5
- 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 -1
- 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 -7
- package/dist/classes/BaseVideo.d.ts +0 -54
- package/dist/classes/BaseVideo.js +0 -82
- package/dist/classes/Channel.d.ts +0 -83
- package/dist/classes/Channel.js +0 -138
- package/dist/classes/Chat.d.ts +0 -29
- package/dist/classes/Chat.js +0 -31
- package/dist/classes/Client.d.ts +0 -30
- package/dist/classes/Client.js +0 -69
- package/dist/classes/Comment.d.ts +0 -43
- package/dist/classes/Comment.js +0 -42
- package/dist/classes/Playlist.d.ts +0 -61
- package/dist/classes/Playlist.js +0 -127
- package/dist/classes/PlaylistCompact.d.ts +0 -30
- package/dist/classes/PlaylistCompact.js +0 -45
- package/dist/classes/SearchResult.d.ts +0 -69
- package/dist/classes/SearchResult.js +0 -139
- package/dist/classes/Video.d.ts +0 -49
- package/dist/classes/Video.js +0 -102
- package/dist/classes/VideoCompact.d.ts +0 -40
- package/dist/classes/VideoCompact.js +0 -50
- package/dist/classes/index.d.ts +0 -13
- package/dist/classes/index.js +0 -32
- package/dist/common/helper.d.ts +0 -2
- package/dist/common/helper.js +0 -37
- package/dist/common/http.d.ts +0 -30
- package/dist/common/http.js +0 -108
- package/dist/common/index.d.ts +0 -5
- package/dist/common/mixins.d.ts +0 -2
|
@@ -0,0 +1,160 @@
|
|
|
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 __values = (this && this.__values) || function(o) {
|
|
51
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
52
|
+
if (m) return m.call(o);
|
|
53
|
+
if (o && typeof o.length === "number") return {
|
|
54
|
+
next: function () {
|
|
55
|
+
if (o && i >= o.length) o = void 0;
|
|
56
|
+
return { value: o && o[i++], done: !o };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
60
|
+
};
|
|
61
|
+
import { EventEmitter } from "events";
|
|
62
|
+
import { applyMixins } from "../../common";
|
|
63
|
+
import { LIVE_CHAT_END_POINT } from "../../constants";
|
|
64
|
+
import { BaseVideo } from "../BaseVideo";
|
|
65
|
+
import { Chat } from "../Chat";
|
|
66
|
+
import { LiveVideoParser } from "./LiveVideoParser";
|
|
67
|
+
/** Represents a video that's currently live, usually returned from `client.getVideo()` */
|
|
68
|
+
var LiveVideo = /** @class */ (function (_super) {
|
|
69
|
+
__extends(LiveVideo, _super);
|
|
70
|
+
/** @hidden */
|
|
71
|
+
function LiveVideo(attr) {
|
|
72
|
+
var _this = _super.call(this, attr) || this;
|
|
73
|
+
_this._delay = 0;
|
|
74
|
+
_this._timeoutMs = 0;
|
|
75
|
+
_this._isChatPlaying = false;
|
|
76
|
+
_this._chatQueue = [];
|
|
77
|
+
Object.assign(_this, attr);
|
|
78
|
+
return _this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Load this instance with raw data from Youtube
|
|
82
|
+
*
|
|
83
|
+
* @hidden
|
|
84
|
+
*/
|
|
85
|
+
LiveVideo.prototype.load = function (data) {
|
|
86
|
+
_super.prototype.load.call(this, data);
|
|
87
|
+
LiveVideoParser.loadLiveVideo(this, data);
|
|
88
|
+
return this;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Start polling for get live chat request
|
|
92
|
+
*
|
|
93
|
+
* @param delay chat delay in millisecond
|
|
94
|
+
*/
|
|
95
|
+
LiveVideo.prototype.playChat = function (delay) {
|
|
96
|
+
if (delay === void 0) { delay = 0; }
|
|
97
|
+
if (this._isChatPlaying)
|
|
98
|
+
return;
|
|
99
|
+
this._delay = delay;
|
|
100
|
+
this._isChatPlaying = true;
|
|
101
|
+
this.pollChatContinuation();
|
|
102
|
+
};
|
|
103
|
+
/** Stop request polling for live chat */
|
|
104
|
+
LiveVideo.prototype.stopChat = function () {
|
|
105
|
+
if (!this._chatRequestPoolingTimeout)
|
|
106
|
+
return;
|
|
107
|
+
this._isChatPlaying = false;
|
|
108
|
+
clearTimeout(this._chatRequestPoolingTimeout);
|
|
109
|
+
};
|
|
110
|
+
/** Start request polling */
|
|
111
|
+
LiveVideo.prototype.pollChatContinuation = function () {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
+
var response, chats, _loop_1, this_1, chats_1, chats_1_1, c, _a, timeout, continuation;
|
|
114
|
+
var e_1, _b;
|
|
115
|
+
var _this = this;
|
|
116
|
+
return __generator(this, function (_c) {
|
|
117
|
+
switch (_c.label) {
|
|
118
|
+
case 0: return [4 /*yield*/, this.client.http.post(LIVE_CHAT_END_POINT, {
|
|
119
|
+
data: { continuation: this.chatContinuation },
|
|
120
|
+
})];
|
|
121
|
+
case 1:
|
|
122
|
+
response = _c.sent();
|
|
123
|
+
if (!response.data.continuationContents)
|
|
124
|
+
return [2 /*return*/];
|
|
125
|
+
chats = LiveVideoParser.parseChats(response.data);
|
|
126
|
+
_loop_1 = function (c) {
|
|
127
|
+
var chat = new Chat({ client: this_1.client }).load(c);
|
|
128
|
+
if (this_1._chatQueue.find(function (c) { return c.id === chat.id; }))
|
|
129
|
+
return "continue";
|
|
130
|
+
this_1._chatQueue.push(chat);
|
|
131
|
+
var timeout_1 = chat.timestamp / 1000 - (new Date().getTime() - this_1._delay);
|
|
132
|
+
setTimeout(function () { return _this.emit("chat", chat); }, timeout_1);
|
|
133
|
+
};
|
|
134
|
+
this_1 = this;
|
|
135
|
+
try {
|
|
136
|
+
for (chats_1 = __values(chats), chats_1_1 = chats_1.next(); !chats_1_1.done; chats_1_1 = chats_1.next()) {
|
|
137
|
+
c = chats_1_1.value;
|
|
138
|
+
_loop_1(c);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
142
|
+
finally {
|
|
143
|
+
try {
|
|
144
|
+
if (chats_1_1 && !chats_1_1.done && (_b = chats_1.return)) _b.call(chats_1);
|
|
145
|
+
}
|
|
146
|
+
finally { if (e_1) throw e_1.error; }
|
|
147
|
+
}
|
|
148
|
+
_a = LiveVideoParser.parseContinuation(response.data), timeout = _a.timeout, continuation = _a.continuation;
|
|
149
|
+
this._timeoutMs = timeout;
|
|
150
|
+
this.chatContinuation = continuation;
|
|
151
|
+
this._chatRequestPoolingTimeout = setTimeout(function () { return _this.pollChatContinuation(); }, this._timeoutMs);
|
|
152
|
+
return [2 /*return*/];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
return LiveVideo;
|
|
158
|
+
}(BaseVideo));
|
|
159
|
+
applyMixins(LiveVideo, [EventEmitter]);
|
|
160
|
+
export { LiveVideo };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseVideoParser } from "../BaseVideo";
|
|
2
|
+
var LiveVideoParser = /** @class */ (function () {
|
|
3
|
+
function LiveVideoParser() {
|
|
4
|
+
}
|
|
5
|
+
LiveVideoParser.loadLiveVideo = function (target, data) {
|
|
6
|
+
var _a;
|
|
7
|
+
var videoInfo = BaseVideoParser.parseRawData(data);
|
|
8
|
+
target.watchingCount = +videoInfo.viewCount.videoViewCountRenderer.viewCount.runs
|
|
9
|
+
.map(function (r) { return r.text; })
|
|
10
|
+
.join(" ")
|
|
11
|
+
.replace(/[^0-9]/g, "");
|
|
12
|
+
target.chatContinuation = (_a = data[3].response.contents.twoColumnWatchNextResults.conversationBar.liveChatRenderer) === null || _a === void 0 ? void 0 : _a.continuations[0].reloadContinuationData.continuation;
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
LiveVideoParser.parseChats = function (data) {
|
|
16
|
+
var _a;
|
|
17
|
+
return (((_a = data.continuationContents.liveChatContinuation.actions) === null || _a === void 0 ? void 0 : _a.flatMap(function (a) { var _a; return ((_a = a.addChatItemAction) === null || _a === void 0 ? void 0 : _a.item.liveChatTextMessageRenderer) || []; })) || []);
|
|
18
|
+
};
|
|
19
|
+
LiveVideoParser.parseContinuation = function (data) {
|
|
20
|
+
var continuation = data.continuationContents.liveChatContinuation.continuations[0];
|
|
21
|
+
var continuationData = continuation.timedContinuationData || continuation.invalidationContinuationData;
|
|
22
|
+
return {
|
|
23
|
+
timeout: continuationData.timeoutMs,
|
|
24
|
+
continuation: continuationData.continuation,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
return LiveVideoParser;
|
|
28
|
+
}());
|
|
29
|
+
export { LiveVideoParser };
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { MixPlaylistParser } from "./MixPlaylistParser";
|
|
16
|
+
/** Represents a MixPlaylist, usually returned from `client.getPlaylist()` */
|
|
17
|
+
var MixPlaylist = /** @class */ (function (_super) {
|
|
18
|
+
__extends(MixPlaylist, _super);
|
|
19
|
+
/** @hidden */
|
|
20
|
+
function MixPlaylist(attr) {
|
|
21
|
+
var _this = _super.call(this, attr.client) || this;
|
|
22
|
+
/** How many viewers does this playlist have */
|
|
23
|
+
_this.videos = [];
|
|
24
|
+
Object.assign(_this, attr);
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Load this instance with raw data from Youtube
|
|
29
|
+
*
|
|
30
|
+
* @hidden
|
|
31
|
+
*/
|
|
32
|
+
MixPlaylist.prototype.load = function (data) {
|
|
33
|
+
MixPlaylistParser.loadMixPlaylist(this, data);
|
|
34
|
+
return this;
|
|
35
|
+
};
|
|
36
|
+
return MixPlaylist;
|
|
37
|
+
}(Base));
|
|
38
|
+
export { MixPlaylist };
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { VideoCompact } from "../VideoCompact";
|
|
13
|
+
var MixPlaylistParser = /** @class */ (function () {
|
|
14
|
+
function MixPlaylistParser() {
|
|
15
|
+
}
|
|
16
|
+
MixPlaylistParser.loadMixPlaylist = function (target, data) {
|
|
17
|
+
var twoColumnWatchNextResults = data.contents.twoColumnWatchNextResults;
|
|
18
|
+
var playlist = twoColumnWatchNextResults.playlist.playlist;
|
|
19
|
+
target.title = playlist.titleText.simpleText;
|
|
20
|
+
target.id = playlist.playlistId;
|
|
21
|
+
target.videoCount = playlist.contents.length;
|
|
22
|
+
target.videos = MixPlaylistParser.parseVideos(playlist.contents, target.client);
|
|
23
|
+
return target;
|
|
24
|
+
};
|
|
25
|
+
MixPlaylistParser.parseVideos = function (data, client) {
|
|
26
|
+
var e_1, _a;
|
|
27
|
+
var videosRenderer = data.map(function (c) { return c.playlistPanelVideoRenderer; });
|
|
28
|
+
var videos = [];
|
|
29
|
+
try {
|
|
30
|
+
for (var videosRenderer_1 = __values(videosRenderer), videosRenderer_1_1 = videosRenderer_1.next(); !videosRenderer_1_1.done; videosRenderer_1_1 = videosRenderer_1.next()) {
|
|
31
|
+
var videoRenderer = videosRenderer_1_1.value;
|
|
32
|
+
if (!videoRenderer)
|
|
33
|
+
continue;
|
|
34
|
+
var video = new VideoCompact({ client: client }).load(videoRenderer);
|
|
35
|
+
videos.push(video);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
39
|
+
finally {
|
|
40
|
+
try {
|
|
41
|
+
if (videosRenderer_1_1 && !videosRenderer_1_1.done && (_a = videosRenderer_1.return)) _a.call(videosRenderer_1);
|
|
42
|
+
}
|
|
43
|
+
finally { if (e_1) throw e_1.error; }
|
|
44
|
+
}
|
|
45
|
+
return videos;
|
|
46
|
+
};
|
|
47
|
+
return MixPlaylistParser;
|
|
48
|
+
}());
|
|
49
|
+
export { MixPlaylistParser };
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { PlaylistParser } from "./PlaylistParser";
|
|
16
|
+
import { PlaylistVideos } from "./PlaylistVideos";
|
|
17
|
+
/** Represents a Playlist, usually returned from `client.getPlaylist()` */
|
|
18
|
+
var Playlist = /** @class */ (function (_super) {
|
|
19
|
+
__extends(Playlist, _super);
|
|
20
|
+
/** @hidden */
|
|
21
|
+
function Playlist(attr) {
|
|
22
|
+
var _this = _super.call(this, attr.client) || this;
|
|
23
|
+
Object.assign(_this, attr);
|
|
24
|
+
_this.videos = new PlaylistVideos({ client: attr.client, playlist: _this });
|
|
25
|
+
return _this;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Load this instance with raw data from Youtube
|
|
29
|
+
*
|
|
30
|
+
* @hidden
|
|
31
|
+
*/
|
|
32
|
+
Playlist.prototype.load = function (data) {
|
|
33
|
+
PlaylistParser.loadPlaylist(this, data);
|
|
34
|
+
return this;
|
|
35
|
+
};
|
|
36
|
+
return Playlist;
|
|
37
|
+
}(Base));
|
|
38
|
+
export { Playlist };
|
|
@@ -0,0 +1,105 @@
|
|
|
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, mapFilter } from "../../common";
|
|
13
|
+
import { BaseChannel } from "../BaseChannel";
|
|
14
|
+
import { Thumbnails } from "../Thumbnails";
|
|
15
|
+
import { VideoCompact } from "../VideoCompact";
|
|
16
|
+
var PlaylistParser = /** @class */ (function () {
|
|
17
|
+
function PlaylistParser() {
|
|
18
|
+
}
|
|
19
|
+
PlaylistParser.loadPlaylist = function (target, data) {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
var sidebarRenderer = data.sidebar.playlistSidebarRenderer.items;
|
|
22
|
+
var primaryRenderer = sidebarRenderer[0].playlistSidebarPrimaryInfoRenderer;
|
|
23
|
+
var metadata = data.metadata.playlistMetadataRenderer;
|
|
24
|
+
// Basic information
|
|
25
|
+
target.id = (_a = Object.values(metadata)
|
|
26
|
+
.find(function (v) { return v.includes("playlist?list="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1];
|
|
27
|
+
target.title = metadata.title;
|
|
28
|
+
var stats = primaryRenderer.stats;
|
|
29
|
+
if (primaryRenderer.stats.length === 3) {
|
|
30
|
+
target.videoCount = PlaylistParser.parseSideBarInfo(stats[0], true);
|
|
31
|
+
target.viewCount = PlaylistParser.parseSideBarInfo(stats[1], true);
|
|
32
|
+
target.lastUpdatedAt = PlaylistParser.parseSideBarInfo(stats[2], false);
|
|
33
|
+
}
|
|
34
|
+
else if (stats.length === 2) {
|
|
35
|
+
target.videoCount = PlaylistParser.parseSideBarInfo(stats[0], true);
|
|
36
|
+
target.lastUpdatedAt = PlaylistParser.parseSideBarInfo(stats[1], false);
|
|
37
|
+
}
|
|
38
|
+
var playlistContents = ((_b = data.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
|
|
39
|
+
.sectionListRenderer.contents[0].itemSectionRenderer.contents[0]
|
|
40
|
+
.playlistVideoListRenderer) === null || _b === void 0 ? void 0 : _b.contents) || [];
|
|
41
|
+
// Channel
|
|
42
|
+
var videoOwner = (_c = sidebarRenderer[1]) === null || _c === void 0 ? void 0 : _c.playlistSidebarSecondaryInfoRenderer.videoOwner;
|
|
43
|
+
if (videoOwner) {
|
|
44
|
+
var _d = videoOwner.videoOwnerRenderer, title = _d.title, thumbnail = _d.thumbnail;
|
|
45
|
+
target.channel = new BaseChannel({
|
|
46
|
+
id: title.runs[0].navigationEndpoint.browseEndpoint.browseId,
|
|
47
|
+
name: title.runs[0].text,
|
|
48
|
+
thumbnails: new Thumbnails().load(thumbnail.thumbnails),
|
|
49
|
+
client: target.client,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// Videos
|
|
53
|
+
target.videos.items = PlaylistParser.parseVideos(playlistContents, target);
|
|
54
|
+
target.videos.continuation = getContinuationFromItems(playlistContents);
|
|
55
|
+
return target;
|
|
56
|
+
};
|
|
57
|
+
PlaylistParser.parseVideoContinuation = function (data) {
|
|
58
|
+
var playlistContents = data.onResponseReceivedActions[0].appendContinuationItemsAction.continuationItems;
|
|
59
|
+
return getContinuationFromItems(playlistContents);
|
|
60
|
+
};
|
|
61
|
+
PlaylistParser.parseContinuationVideos = function (data, client) {
|
|
62
|
+
var playlistContents = data.onResponseReceivedActions[0].appendContinuationItemsAction.continuationItems;
|
|
63
|
+
var videos = mapFilter(playlistContents, "playlistVideoRenderer");
|
|
64
|
+
return videos.map(function (video) { return new VideoCompact({ client: client }).load(video); });
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Get compact videos
|
|
68
|
+
*
|
|
69
|
+
* @param playlistContents raw object from youtubei
|
|
70
|
+
*/
|
|
71
|
+
PlaylistParser.parseVideos = function (playlistContents, playlist) {
|
|
72
|
+
var e_1, _a;
|
|
73
|
+
var videosRenderer = playlistContents.map(function (c) { return c.playlistVideoRenderer; });
|
|
74
|
+
var videos = [];
|
|
75
|
+
try {
|
|
76
|
+
for (var videosRenderer_1 = __values(videosRenderer), videosRenderer_1_1 = videosRenderer_1.next(); !videosRenderer_1_1.done; videosRenderer_1_1 = videosRenderer_1.next()) {
|
|
77
|
+
var videoRenderer = videosRenderer_1_1.value;
|
|
78
|
+
if (!videoRenderer)
|
|
79
|
+
continue;
|
|
80
|
+
var video = new VideoCompact({ client: playlist.client }).load(videoRenderer);
|
|
81
|
+
videos.push(video);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
85
|
+
finally {
|
|
86
|
+
try {
|
|
87
|
+
if (videosRenderer_1_1 && !videosRenderer_1_1.done && (_a = videosRenderer_1.return)) _a.call(videosRenderer_1);
|
|
88
|
+
}
|
|
89
|
+
finally { if (e_1) throw e_1.error; }
|
|
90
|
+
}
|
|
91
|
+
return videos;
|
|
92
|
+
};
|
|
93
|
+
PlaylistParser.parseSideBarInfo = function (stats, parseInt) {
|
|
94
|
+
var data;
|
|
95
|
+
if ("runs" in stats)
|
|
96
|
+
data = stats.runs.map(function (r) { return r.text; }).join("");
|
|
97
|
+
else
|
|
98
|
+
data = stats.simpleText.replace(/[^0-9]/g, "");
|
|
99
|
+
if (parseInt)
|
|
100
|
+
data = +data.replace(/[^0-9]/g, "");
|
|
101
|
+
return data;
|
|
102
|
+
};
|
|
103
|
+
return PlaylistParser;
|
|
104
|
+
}());
|
|
105
|
+
export { PlaylistParser };
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { PlaylistParser } from "./PlaylistParser";
|
|
53
|
+
/**
|
|
54
|
+
* {@link Continuable} of videos inside a {@link Playlist}
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```js
|
|
58
|
+
* const playlist = await youtube.getPlaylist(PLAYLIST_ID);
|
|
59
|
+
* console.log(playlist.videos) // first 100 videos
|
|
60
|
+
*
|
|
61
|
+
* let newVideos = await playlist.videos.next();
|
|
62
|
+
* console.log(newVideos) // 100 loaded videos
|
|
63
|
+
* console.log(playlist.videos) // first 200 videos
|
|
64
|
+
*
|
|
65
|
+
* await playlist.videos.next(0); // load the rest of the videos in the playlist
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param count How many times to load the next videos. Set 0 to load all videos (might take a while on a large playlist!)
|
|
69
|
+
*/
|
|
70
|
+
var PlaylistVideos = /** @class */ (function (_super) {
|
|
71
|
+
__extends(PlaylistVideos, _super);
|
|
72
|
+
/** @hidden */
|
|
73
|
+
function PlaylistVideos(_a) {
|
|
74
|
+
var client = _a.client, playlist = _a.playlist;
|
|
75
|
+
var _this = _super.call(this, { client: client, strictContinuationCheck: true }) || this;
|
|
76
|
+
_this.playlist = playlist;
|
|
77
|
+
return _this;
|
|
78
|
+
}
|
|
79
|
+
PlaylistVideos.prototype.fetch = function () {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var response, items, continuation;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0: return [4 /*yield*/, this.client.http.post(I_END_POINT + "/browse", {
|
|
85
|
+
data: { continuation: this.continuation },
|
|
86
|
+
})];
|
|
87
|
+
case 1:
|
|
88
|
+
response = _a.sent();
|
|
89
|
+
items = PlaylistParser.parseContinuationVideos(response.data, this.client);
|
|
90
|
+
continuation = PlaylistParser.parseVideoContinuation(response.data);
|
|
91
|
+
return [2 /*return*/, { continuation: continuation, items: items }];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return PlaylistVideos;
|
|
97
|
+
}(Continuable));
|
|
98
|
+
export { PlaylistVideos };
|
|
@@ -0,0 +1,90 @@
|
|
|
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 { Base } from "../Base";
|
|
51
|
+
import { PlaylistCompactParser } from "./PlaylistCompactParser";
|
|
52
|
+
/** Represents a Compact Playlist (e.g. from search result, related of a video) */
|
|
53
|
+
var PlaylistCompact = /** @class */ (function (_super) {
|
|
54
|
+
__extends(PlaylistCompact, _super);
|
|
55
|
+
/** @hidden */
|
|
56
|
+
function PlaylistCompact(attr) {
|
|
57
|
+
var _this = _super.call(this, attr.client) || this;
|
|
58
|
+
Object.assign(_this, attr);
|
|
59
|
+
return _this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Load this instance with raw data from Youtube
|
|
63
|
+
*
|
|
64
|
+
* @hidden
|
|
65
|
+
*/
|
|
66
|
+
PlaylistCompact.prototype.load = function (data) {
|
|
67
|
+
PlaylistCompactParser.loadPlaylistCompact(this, data);
|
|
68
|
+
return this;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Get {@link Playlist} object based on current playlist id
|
|
72
|
+
*
|
|
73
|
+
* Equivalent to
|
|
74
|
+
* ```js
|
|
75
|
+
* client.getPlaylist(playlistCompact.id);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
PlaylistCompact.prototype.getPlaylist = function () {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0: return [4 /*yield*/, this.client.getPlaylist(this.id)];
|
|
83
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return PlaylistCompact;
|
|
89
|
+
}(Base));
|
|
90
|
+
export { PlaylistCompact };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { stripToInt } from "../../common";
|
|
2
|
+
import { BaseChannel } from "../BaseChannel";
|
|
3
|
+
import { Thumbnails } from "../Thumbnails";
|
|
4
|
+
var PlaylistCompactParser = /** @class */ (function () {
|
|
5
|
+
function PlaylistCompactParser() {
|
|
6
|
+
}
|
|
7
|
+
PlaylistCompactParser.loadPlaylistCompact = function (target, data) {
|
|
8
|
+
var _a;
|
|
9
|
+
var playlistId = data.playlistId, title = data.title, thumbnail = data.thumbnail, shortBylineText = data.shortBylineText, videoCount = data.videoCount, videoCountShortText = data.videoCountShortText;
|
|
10
|
+
target.id = playlistId;
|
|
11
|
+
target.title = title.simpleText || title.runs[0].text;
|
|
12
|
+
target.videoCount = stripToInt(videoCount || videoCountShortText.simpleText) || 0;
|
|
13
|
+
// Thumbnail
|
|
14
|
+
target.thumbnails = new Thumbnails().load(((_a = data.thumbnails) === null || _a === void 0 ? void 0 : _a[0].thumbnails) || thumbnail.thumbnails);
|
|
15
|
+
// Channel
|
|
16
|
+
if (shortBylineText && shortBylineText.simpleText !== "YouTube") {
|
|
17
|
+
var shortByLine = shortBylineText.runs[0];
|
|
18
|
+
target.channel = new BaseChannel({
|
|
19
|
+
id: shortByLine.navigationEndpoint.browseEndpoint.browseId,
|
|
20
|
+
name: shortByLine.text,
|
|
21
|
+
client: target.client,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
return PlaylistCompactParser;
|
|
27
|
+
}());
|
|
28
|
+
export { PlaylistCompactParser };
|