youtubei 1.8.8 → 1.8.10
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/dist/cjs/common/shared/HTTP/HTTP.js +4 -5
- package/dist/cjs/youtube/BaseChannel/ChannelLive.js +20 -2
- package/dist/cjs/youtube/BaseChannel/ChannelVideos.js +20 -2
- package/dist/cjs/youtube/BaseVideo/BaseVideoParser.js +5 -6
- package/dist/cjs/youtube/Client/Client.js +6 -11
- package/dist/esm/common/shared/HTTP/HTTP.js +5 -6
- package/dist/esm/youtube/BaseChannel/ChannelLive.js +44 -6
- package/dist/esm/youtube/BaseChannel/ChannelVideos.js +44 -6
- package/dist/esm/youtube/BaseVideo/BaseVideoParser.js +6 -7
- package/dist/esm/youtube/Client/Client.js +27 -15
- package/package.json +3 -3
|
@@ -55,16 +55,15 @@ class HTTP {
|
|
|
55
55
|
}
|
|
56
56
|
request(path, partialOptions) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
|
|
58
|
+
const requiresAuth = new URL(`https://${this.baseUrl}/${path}`).pathname.endsWith("/player");
|
|
59
|
+
if (this.authorizationPromise && requiresAuth)
|
|
59
60
|
yield this.authorizationPromise;
|
|
60
61
|
const options = Object.assign(Object.assign(Object.assign({}, partialOptions), this.defaultFetchOptions), { headers: Object.assign(Object.assign(Object.assign(Object.assign({}, this.defaultHeaders), { cookie: this.cookie, referer: `https://${this.baseUrl}/` }), partialOptions.headers), this.defaultFetchOptions.headers), body: partialOptions.data ? JSON.stringify(partialOptions.data) : undefined });
|
|
61
|
-
if (this.oauth.enabled) {
|
|
62
|
+
if (this.oauth.enabled && requiresAuth) {
|
|
62
63
|
this.authorizationPromise = this.authorize();
|
|
63
64
|
yield this.authorizationPromise;
|
|
64
65
|
if (this.oauth.token) {
|
|
65
|
-
options.headers = {
|
|
66
|
-
Authorization: `Bearer ${this.oauth.token}`,
|
|
67
|
-
};
|
|
66
|
+
options.headers = Object.assign(Object.assign({}, options.headers), { Authorization: `Bearer ${this.oauth.token}`, cookie: undefined });
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
// if URL is a full URL, ignore baseUrl
|
|
@@ -46,10 +46,28 @@ class ChannelLive extends Continuable_1.Continuable {
|
|
|
46
46
|
});
|
|
47
47
|
const items = BaseChannelParser_1.BaseChannelParser.parseTabData("live", response.data);
|
|
48
48
|
const continuation = common_1.getContinuationFromItems(items);
|
|
49
|
-
const
|
|
49
|
+
const videoRenderers = common_1.mapFilter(items, "videoRenderer");
|
|
50
|
+
const lockupViewModels = common_1.mapFilter(items, "lockupViewModel");
|
|
51
|
+
const fromVideoRenderer = videoRenderers.map((i) => new VideoCompact_1.VideoCompact({ client: this.client, channel: this.channel }).load(i));
|
|
52
|
+
const fromLockup = lockupViewModels.map((i) => {
|
|
53
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
54
|
+
const v = new VideoCompact_1.VideoCompact({ client: this.client, channel: this.channel });
|
|
55
|
+
v.id = i.contentId;
|
|
56
|
+
v.title = (_c = (_b = (_a = i.metadata) === null || _a === void 0 ? void 0 : _a.lockupMetadataViewModel) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.content;
|
|
57
|
+
v.thumbnails = new common_1.Thumbnails().load(((_f = (_e = (_d = i.contentImage) === null || _d === void 0 ? void 0 : _d.thumbnailViewModel) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f.sources) || []);
|
|
58
|
+
const overlays = ((_j = (_h = (_g = i.contentImage) === null || _g === void 0 ? void 0 : _g.thumbnailViewModel) === null || _h === void 0 ? void 0 : _h.overlays) === null || _j === void 0 ? void 0 : _j[0]) || {};
|
|
59
|
+
const badges = ((_k = overlays.thumbnailBottomOverlayViewModel) === null || _k === void 0 ? void 0 : _k.badges) || [];
|
|
60
|
+
const badgeText = ((_m = (_l = badges[0]) === null || _l === void 0 ? void 0 : _l.thumbnailBadgeViewModel) === null || _m === void 0 ? void 0 : _m.text) || "";
|
|
61
|
+
v.isLive = badgeText === "LIVE";
|
|
62
|
+
v.duration = !v.isLive && badgeText ? common_1.getDuration(badgeText) : null;
|
|
63
|
+
const metaRows = ((_r = (_q = (_p = (_o = i.metadata) === null || _o === void 0 ? void 0 : _o.lockupMetadataViewModel) === null || _p === void 0 ? void 0 : _p.metadata) === null || _q === void 0 ? void 0 : _q.contentMetadataViewModel) === null || _r === void 0 ? void 0 : _r.metadataRows) || [];
|
|
64
|
+
const metaText = ((_v = (_u = (_t = (_s = metaRows[0]) === null || _s === void 0 ? void 0 : _s.metadataParts) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.text) === null || _v === void 0 ? void 0 : _v.content) || "";
|
|
65
|
+
v.viewCount = common_1.stripToInt(metaText);
|
|
66
|
+
return v;
|
|
67
|
+
});
|
|
50
68
|
return {
|
|
51
69
|
continuation,
|
|
52
|
-
items:
|
|
70
|
+
items: [...fromVideoRenderer, ...fromLockup],
|
|
53
71
|
};
|
|
54
72
|
});
|
|
55
73
|
}
|
|
@@ -46,10 +46,28 @@ class ChannelVideos extends Continuable_1.Continuable {
|
|
|
46
46
|
});
|
|
47
47
|
const items = BaseChannelParser_1.BaseChannelParser.parseTabData("videos", response.data);
|
|
48
48
|
const continuation = common_1.getContinuationFromItems(items);
|
|
49
|
-
const
|
|
49
|
+
const videoRenderers = common_1.mapFilter(items, "videoRenderer");
|
|
50
|
+
const lockupViewModels = common_1.mapFilter(items, "lockupViewModel");
|
|
51
|
+
const fromVideoRenderer = videoRenderers.map((i) => new VideoCompact_1.VideoCompact({ client: this.client, channel: this.channel }).load(i));
|
|
52
|
+
const fromLockup = lockupViewModels.map((i) => {
|
|
53
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
54
|
+
const v = new VideoCompact_1.VideoCompact({ client: this.client, channel: this.channel });
|
|
55
|
+
v.id = i.contentId;
|
|
56
|
+
v.title = (_c = (_b = (_a = i.metadata) === null || _a === void 0 ? void 0 : _a.lockupMetadataViewModel) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.content;
|
|
57
|
+
v.thumbnails = new common_1.Thumbnails().load(((_f = (_e = (_d = i.contentImage) === null || _d === void 0 ? void 0 : _d.thumbnailViewModel) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f.sources) || []);
|
|
58
|
+
const overlays = ((_j = (_h = (_g = i.contentImage) === null || _g === void 0 ? void 0 : _g.thumbnailViewModel) === null || _h === void 0 ? void 0 : _h.overlays) === null || _j === void 0 ? void 0 : _j[0]) || {};
|
|
59
|
+
const badges = ((_k = overlays.thumbnailBottomOverlayViewModel) === null || _k === void 0 ? void 0 : _k.badges) || [];
|
|
60
|
+
const badgeText = ((_m = (_l = badges[0]) === null || _l === void 0 ? void 0 : _l.thumbnailBadgeViewModel) === null || _m === void 0 ? void 0 : _m.text) || "";
|
|
61
|
+
v.isLive = badgeText === "LIVE";
|
|
62
|
+
v.duration = !v.isLive && badgeText ? common_1.getDuration(badgeText) : null;
|
|
63
|
+
const metaRows = ((_r = (_q = (_p = (_o = i.metadata) === null || _o === void 0 ? void 0 : _o.lockupMetadataViewModel) === null || _p === void 0 ? void 0 : _p.metadata) === null || _q === void 0 ? void 0 : _q.contentMetadataViewModel) === null || _r === void 0 ? void 0 : _r.metadataRows) || [];
|
|
64
|
+
const metaText = ((_v = (_u = (_t = (_s = metaRows[0]) === null || _s === void 0 ? void 0 : _s.metadataParts) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.text) === null || _v === void 0 ? void 0 : _v.content) || "";
|
|
65
|
+
v.viewCount = common_1.stripToInt(metaText);
|
|
66
|
+
return v;
|
|
67
|
+
});
|
|
50
68
|
return {
|
|
51
69
|
continuation,
|
|
52
|
-
items:
|
|
70
|
+
items: [...fromVideoRenderer, ...fromLockup],
|
|
53
71
|
};
|
|
54
72
|
});
|
|
55
73
|
}
|
|
@@ -8,7 +8,7 @@ const VideoCompact_1 = require("../VideoCompact");
|
|
|
8
8
|
const VideoCaptions_1 = require("./VideoCaptions");
|
|
9
9
|
class BaseVideoParser {
|
|
10
10
|
static loadBaseVideo(target, data) {
|
|
11
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
12
12
|
const videoInfo = BaseVideoParser.parseRawData(data);
|
|
13
13
|
// Basic information
|
|
14
14
|
target.id = videoInfo.currentVideoEndpoint.watchEndpoint.videoId;
|
|
@@ -59,14 +59,13 @@ class BaseVideoParser {
|
|
|
59
59
|
target.tags =
|
|
60
60
|
((_f = (_e = videoInfo.superTitleLink) === null || _e === void 0 ? void 0 : _e.runs) === null || _f === void 0 ? void 0 : _f.map((r) => r.text.trim()).filter((t) => t)) || [];
|
|
61
61
|
target.description =
|
|
62
|
-
((_g = videoInfo.videoDetails) === null || _g === void 0 ? void 0 : _g.shortDescription) ||
|
|
63
|
-
videoInfo.attributedDescription.content ||
|
|
62
|
+
((_g = videoInfo.videoDetails) === null || _g === void 0 ? void 0 : _g.shortDescription) || ((_h = videoInfo.attributedDescription) === null || _h === void 0 ? void 0 : _h.content) ||
|
|
64
63
|
"";
|
|
65
64
|
// related videos
|
|
66
|
-
let secondaryContents = (
|
|
67
|
-
const itemSectionRenderer = (
|
|
65
|
+
let secondaryContents = (_j = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _j === void 0 ? void 0 : _j.secondaryResults.results;
|
|
66
|
+
const itemSectionRenderer = (_k = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find((c) => {
|
|
68
67
|
return c.itemSectionRenderer;
|
|
69
|
-
})) === null ||
|
|
68
|
+
})) === null || _k === void 0 ? void 0 : _k.itemSectionRenderer;
|
|
70
69
|
if (itemSectionRenderer)
|
|
71
70
|
secondaryContents = itemSectionRenderer.contents;
|
|
72
71
|
if (secondaryContents) {
|
|
@@ -80,19 +80,14 @@ class Client {
|
|
|
80
80
|
}
|
|
81
81
|
/** Get video information by video id or URL */
|
|
82
82
|
getVideo(videoId) {
|
|
83
|
-
var _a, _b;
|
|
83
|
+
var _a, _b, _c, _d;
|
|
84
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const data = {
|
|
89
|
-
response: response.data.find((r) => "watchNextResponse" in r)
|
|
90
|
-
.watchNextResponse,
|
|
91
|
-
playerResponse: response.data.find((r) => "playerResponse" in r)
|
|
92
|
-
.playerResponse,
|
|
93
|
-
};
|
|
85
|
+
const nextPromise = this.http.post(`${constants_1.I_END_POINT}/next`, { data: { videoId } });
|
|
86
|
+
const playerPromise = this.http.post(`${constants_1.I_END_POINT}/player`, { data: { videoId } });
|
|
87
|
+
const [nextResponse, playerResponse] = yield Promise.all([nextPromise, playerPromise]);
|
|
88
|
+
const data = { response: nextResponse.data, playerResponse: playerResponse.data };
|
|
94
89
|
if (!((_b = (_a = data.response) === null || _a === void 0 ? void 0 : _a.contents) === null || _b === void 0 ? void 0 : _b.twoColumnWatchNextResults.results.results.contents) ||
|
|
95
|
-
data.playerResponse.playabilityStatus.status === "ERROR") {
|
|
90
|
+
((_d = (_c = data.playerResponse) === null || _c === void 0 ? void 0 : _c.playabilityStatus) === null || _d === void 0 ? void 0 : _d.status) === "ERROR") {
|
|
96
91
|
return undefined;
|
|
97
92
|
}
|
|
98
93
|
return (!data.playerResponse.playabilityStatus.liveStreamability
|
|
@@ -124,27 +124,26 @@ var HTTP = /** @class */ (function () {
|
|
|
124
124
|
};
|
|
125
125
|
HTTP.prototype.request = function (path, partialOptions) {
|
|
126
126
|
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
-
var options, urlString, url, _a, _b, _c, key, value, response, data;
|
|
127
|
+
var requiresAuth, options, urlString, url, _a, _b, _c, key, value, response, data;
|
|
128
128
|
var e_1, _d;
|
|
129
129
|
return __generator(this, function (_e) {
|
|
130
130
|
switch (_e.label) {
|
|
131
131
|
case 0:
|
|
132
|
-
|
|
132
|
+
requiresAuth = new URL("https://" + this.baseUrl + "/" + path).pathname.endsWith("/player");
|
|
133
|
+
if (!(this.authorizationPromise && requiresAuth)) return [3 /*break*/, 2];
|
|
133
134
|
return [4 /*yield*/, this.authorizationPromise];
|
|
134
135
|
case 1:
|
|
135
136
|
_e.sent();
|
|
136
137
|
_e.label = 2;
|
|
137
138
|
case 2:
|
|
138
139
|
options = __assign(__assign(__assign({}, partialOptions), this.defaultFetchOptions), { headers: __assign(__assign(__assign(__assign({}, this.defaultHeaders), { cookie: this.cookie, referer: "https://" + this.baseUrl + "/" }), partialOptions.headers), this.defaultFetchOptions.headers), body: partialOptions.data ? JSON.stringify(partialOptions.data) : undefined });
|
|
139
|
-
if (!this.oauth.enabled) return [3 /*break*/, 4];
|
|
140
|
+
if (!(this.oauth.enabled && requiresAuth)) return [3 /*break*/, 4];
|
|
140
141
|
this.authorizationPromise = this.authorize();
|
|
141
142
|
return [4 /*yield*/, this.authorizationPromise];
|
|
142
143
|
case 3:
|
|
143
144
|
_e.sent();
|
|
144
145
|
if (this.oauth.token) {
|
|
145
|
-
options.headers = {
|
|
146
|
-
Authorization: "Bearer " + this.oauth.token,
|
|
147
|
-
};
|
|
146
|
+
options.headers = __assign(__assign({}, options.headers), { Authorization: "Bearer " + this.oauth.token, cookie: undefined });
|
|
148
147
|
}
|
|
149
148
|
_e.label = 4;
|
|
150
149
|
case 4:
|
|
@@ -47,7 +47,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
|
|
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 { Thumbnails, getContinuationFromItems, getDuration, mapFilter, stripToInt } from "../../common";
|
|
51
71
|
import { Continuable } from "../Continuable";
|
|
52
72
|
import { VideoCompact } from "../VideoCompact";
|
|
53
73
|
import { I_END_POINT } from "../constants";
|
|
@@ -80,7 +100,7 @@ var ChannelLive = /** @class */ (function (_super) {
|
|
|
80
100
|
ChannelLive.prototype.fetch = function () {
|
|
81
101
|
var _a;
|
|
82
102
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var params, response, items, continuation,
|
|
103
|
+
var params, response, items, continuation, videoRenderers, lockupViewModels, fromVideoRenderer, fromLockup;
|
|
84
104
|
var _this = this;
|
|
85
105
|
return __generator(this, function (_b) {
|
|
86
106
|
switch (_b.label) {
|
|
@@ -93,12 +113,30 @@ var ChannelLive = /** @class */ (function (_super) {
|
|
|
93
113
|
response = _b.sent();
|
|
94
114
|
items = BaseChannelParser.parseTabData("live", response.data);
|
|
95
115
|
continuation = getContinuationFromItems(items);
|
|
96
|
-
|
|
116
|
+
videoRenderers = mapFilter(items, "videoRenderer");
|
|
117
|
+
lockupViewModels = mapFilter(items, "lockupViewModel");
|
|
118
|
+
fromVideoRenderer = videoRenderers.map(function (i) {
|
|
119
|
+
return new VideoCompact({ client: _this.client, channel: _this.channel }).load(i);
|
|
120
|
+
});
|
|
121
|
+
fromLockup = lockupViewModels.map(function (i) {
|
|
122
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
123
|
+
var v = new VideoCompact({ client: _this.client, channel: _this.channel });
|
|
124
|
+
v.id = i.contentId;
|
|
125
|
+
v.title = (_c = (_b = (_a = i.metadata) === null || _a === void 0 ? void 0 : _a.lockupMetadataViewModel) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.content;
|
|
126
|
+
v.thumbnails = new Thumbnails().load(((_f = (_e = (_d = i.contentImage) === null || _d === void 0 ? void 0 : _d.thumbnailViewModel) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f.sources) || []);
|
|
127
|
+
var overlays = ((_j = (_h = (_g = i.contentImage) === null || _g === void 0 ? void 0 : _g.thumbnailViewModel) === null || _h === void 0 ? void 0 : _h.overlays) === null || _j === void 0 ? void 0 : _j[0]) || {};
|
|
128
|
+
var badges = ((_k = overlays.thumbnailBottomOverlayViewModel) === null || _k === void 0 ? void 0 : _k.badges) || [];
|
|
129
|
+
var badgeText = ((_m = (_l = badges[0]) === null || _l === void 0 ? void 0 : _l.thumbnailBadgeViewModel) === null || _m === void 0 ? void 0 : _m.text) || "";
|
|
130
|
+
v.isLive = badgeText === "LIVE";
|
|
131
|
+
v.duration = !v.isLive && badgeText ? getDuration(badgeText) : null;
|
|
132
|
+
var metaRows = ((_r = (_q = (_p = (_o = i.metadata) === null || _o === void 0 ? void 0 : _o.lockupMetadataViewModel) === null || _p === void 0 ? void 0 : _p.metadata) === null || _q === void 0 ? void 0 : _q.contentMetadataViewModel) === null || _r === void 0 ? void 0 : _r.metadataRows) || [];
|
|
133
|
+
var metaText = ((_v = (_u = (_t = (_s = metaRows[0]) === null || _s === void 0 ? void 0 : _s.metadataParts) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.text) === null || _v === void 0 ? void 0 : _v.content) || "";
|
|
134
|
+
v.viewCount = stripToInt(metaText);
|
|
135
|
+
return v;
|
|
136
|
+
});
|
|
97
137
|
return [2 /*return*/, {
|
|
98
138
|
continuation: continuation,
|
|
99
|
-
items:
|
|
100
|
-
return new VideoCompact({ client: _this.client, channel: _this.channel }).load(i);
|
|
101
|
-
}),
|
|
139
|
+
items: __spread(fromVideoRenderer, fromLockup),
|
|
102
140
|
}];
|
|
103
141
|
}
|
|
104
142
|
});
|
|
@@ -47,7 +47,27 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
|
|
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 { getContinuationFromItems, getDuration, mapFilter, stripToInt, Thumbnails } from "../../common";
|
|
51
71
|
import { Continuable } from "../Continuable";
|
|
52
72
|
import { VideoCompact } from "../VideoCompact";
|
|
53
73
|
import { I_END_POINT } from "../constants";
|
|
@@ -80,7 +100,7 @@ var ChannelVideos = /** @class */ (function (_super) {
|
|
|
80
100
|
ChannelVideos.prototype.fetch = function () {
|
|
81
101
|
var _a;
|
|
82
102
|
return __awaiter(this, void 0, void 0, function () {
|
|
83
|
-
var params, response, items, continuation,
|
|
103
|
+
var params, response, items, continuation, videoRenderers, lockupViewModels, fromVideoRenderer, fromLockup;
|
|
84
104
|
var _this = this;
|
|
85
105
|
return __generator(this, function (_b) {
|
|
86
106
|
switch (_b.label) {
|
|
@@ -93,12 +113,30 @@ var ChannelVideos = /** @class */ (function (_super) {
|
|
|
93
113
|
response = _b.sent();
|
|
94
114
|
items = BaseChannelParser.parseTabData("videos", response.data);
|
|
95
115
|
continuation = getContinuationFromItems(items);
|
|
96
|
-
|
|
116
|
+
videoRenderers = mapFilter(items, "videoRenderer");
|
|
117
|
+
lockupViewModels = mapFilter(items, "lockupViewModel");
|
|
118
|
+
fromVideoRenderer = videoRenderers.map(function (i) {
|
|
119
|
+
return new VideoCompact({ client: _this.client, channel: _this.channel }).load(i);
|
|
120
|
+
});
|
|
121
|
+
fromLockup = lockupViewModels.map(function (i) {
|
|
122
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
123
|
+
var v = new VideoCompact({ client: _this.client, channel: _this.channel });
|
|
124
|
+
v.id = i.contentId;
|
|
125
|
+
v.title = (_c = (_b = (_a = i.metadata) === null || _a === void 0 ? void 0 : _a.lockupMetadataViewModel) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.content;
|
|
126
|
+
v.thumbnails = new Thumbnails().load(((_f = (_e = (_d = i.contentImage) === null || _d === void 0 ? void 0 : _d.thumbnailViewModel) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f.sources) || []);
|
|
127
|
+
var overlays = ((_j = (_h = (_g = i.contentImage) === null || _g === void 0 ? void 0 : _g.thumbnailViewModel) === null || _h === void 0 ? void 0 : _h.overlays) === null || _j === void 0 ? void 0 : _j[0]) || {};
|
|
128
|
+
var badges = ((_k = overlays.thumbnailBottomOverlayViewModel) === null || _k === void 0 ? void 0 : _k.badges) || [];
|
|
129
|
+
var badgeText = ((_m = (_l = badges[0]) === null || _l === void 0 ? void 0 : _l.thumbnailBadgeViewModel) === null || _m === void 0 ? void 0 : _m.text) || "";
|
|
130
|
+
v.isLive = badgeText === "LIVE";
|
|
131
|
+
v.duration = !v.isLive && badgeText ? getDuration(badgeText) : null;
|
|
132
|
+
var metaRows = ((_r = (_q = (_p = (_o = i.metadata) === null || _o === void 0 ? void 0 : _o.lockupMetadataViewModel) === null || _p === void 0 ? void 0 : _p.metadata) === null || _q === void 0 ? void 0 : _q.contentMetadataViewModel) === null || _r === void 0 ? void 0 : _r.metadataRows) || [];
|
|
133
|
+
var metaText = ((_v = (_u = (_t = (_s = metaRows[0]) === null || _s === void 0 ? void 0 : _s.metadataParts) === null || _t === void 0 ? void 0 : _t[0]) === null || _u === void 0 ? void 0 : _u.text) === null || _v === void 0 ? void 0 : _v.content) || "";
|
|
134
|
+
v.viewCount = stripToInt(metaText);
|
|
135
|
+
return v;
|
|
136
|
+
});
|
|
97
137
|
return [2 /*return*/, {
|
|
98
138
|
continuation: continuation,
|
|
99
|
-
items:
|
|
100
|
-
return new VideoCompact({ client: _this.client, channel: _this.channel }).load(i);
|
|
101
|
-
}),
|
|
139
|
+
items: __spread(fromVideoRenderer, fromLockup),
|
|
102
140
|
}];
|
|
103
141
|
}
|
|
104
142
|
});
|
|
@@ -18,7 +18,7 @@ var BaseVideoParser = /** @class */ (function () {
|
|
|
18
18
|
function BaseVideoParser() {
|
|
19
19
|
}
|
|
20
20
|
BaseVideoParser.loadBaseVideo = function (target, data) {
|
|
21
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
22
22
|
var videoInfo = BaseVideoParser.parseRawData(data);
|
|
23
23
|
// Basic information
|
|
24
24
|
target.id = videoInfo.currentVideoEndpoint.watchEndpoint.videoId;
|
|
@@ -32,7 +32,7 @@ var BaseVideoParser = /** @class */ (function () {
|
|
|
32
32
|
target.adaptiveFormats = ((_c = videoInfo.streamingData) === null || _c === void 0 ? void 0 : _c.adaptiveFormats) || [];
|
|
33
33
|
target.thumbnails = new Thumbnails().load(((_d = videoInfo.videoDetails) === null || _d === void 0 ? void 0 : _d.thumbnail.thumbnails) || getThumbnailFromId(target.id));
|
|
34
34
|
// Channel
|
|
35
|
-
var
|
|
35
|
+
var _l = videoInfo.owner.videoOwnerRenderer, title = _l.title, thumbnail = _l.thumbnail, subscriberCountText = _l.subscriberCountText;
|
|
36
36
|
if (title) {
|
|
37
37
|
target.channel = new BaseChannel({
|
|
38
38
|
client: target.client,
|
|
@@ -69,14 +69,13 @@ var BaseVideoParser = /** @class */ (function () {
|
|
|
69
69
|
target.tags =
|
|
70
70
|
((_f = (_e = videoInfo.superTitleLink) === null || _e === void 0 ? void 0 : _e.runs) === null || _f === void 0 ? void 0 : _f.map(function (r) { return r.text.trim(); }).filter(function (t) { return t; })) || [];
|
|
71
71
|
target.description =
|
|
72
|
-
((_g = videoInfo.videoDetails) === null || _g === void 0 ? void 0 : _g.shortDescription) ||
|
|
73
|
-
videoInfo.attributedDescription.content ||
|
|
72
|
+
((_g = videoInfo.videoDetails) === null || _g === void 0 ? void 0 : _g.shortDescription) || ((_h = videoInfo.attributedDescription) === null || _h === void 0 ? void 0 : _h.content) ||
|
|
74
73
|
"";
|
|
75
74
|
// related videos
|
|
76
|
-
var secondaryContents = (
|
|
77
|
-
var itemSectionRenderer = (
|
|
75
|
+
var secondaryContents = (_j = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _j === void 0 ? void 0 : _j.secondaryResults.results;
|
|
76
|
+
var itemSectionRenderer = (_k = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find(function (c) {
|
|
78
77
|
return c.itemSectionRenderer;
|
|
79
|
-
})) === null ||
|
|
78
|
+
})) === null || _k === void 0 ? void 0 : _k.itemSectionRenderer;
|
|
80
79
|
if (itemSectionRenderer)
|
|
81
80
|
secondaryContents = itemSectionRenderer.contents;
|
|
82
81
|
if (secondaryContents) {
|
|
@@ -45,6 +45,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
45
45
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
49
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
50
|
+
if (!m) return o;
|
|
51
|
+
var i = m.call(o), r, ar = [], e;
|
|
52
|
+
try {
|
|
53
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
54
|
+
}
|
|
55
|
+
catch (error) { e = { error: error }; }
|
|
56
|
+
finally {
|
|
57
|
+
try {
|
|
58
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
59
|
+
}
|
|
60
|
+
finally { if (e) throw e.error; }
|
|
61
|
+
}
|
|
62
|
+
return ar;
|
|
63
|
+
};
|
|
48
64
|
import { HTTP } from "../../common";
|
|
49
65
|
import { Channel } from "../Channel";
|
|
50
66
|
import { LiveVideo } from "../LiveVideo";
|
|
@@ -144,24 +160,20 @@ var Client = /** @class */ (function () {
|
|
|
144
160
|
};
|
|
145
161
|
/** Get video information by video id or URL */
|
|
146
162
|
Client.prototype.getVideo = function (videoId) {
|
|
147
|
-
var _a, _b;
|
|
163
|
+
var _a, _b, _c, _d;
|
|
148
164
|
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
-
var
|
|
150
|
-
return __generator(this, function (
|
|
151
|
-
switch (
|
|
152
|
-
case 0:
|
|
153
|
-
|
|
154
|
-
})
|
|
165
|
+
var nextPromise, playerPromise, _e, nextResponse, playerResponse, data;
|
|
166
|
+
return __generator(this, function (_f) {
|
|
167
|
+
switch (_f.label) {
|
|
168
|
+
case 0:
|
|
169
|
+
nextPromise = this.http.post(I_END_POINT + "/next", { data: { videoId: videoId } });
|
|
170
|
+
playerPromise = this.http.post(I_END_POINT + "/player", { data: { videoId: videoId } });
|
|
171
|
+
return [4 /*yield*/, Promise.all([nextPromise, playerPromise])];
|
|
155
172
|
case 1:
|
|
156
|
-
|
|
157
|
-
data = {
|
|
158
|
-
response: response.data.find(function (r) { return "watchNextResponse" in r; })
|
|
159
|
-
.watchNextResponse,
|
|
160
|
-
playerResponse: response.data.find(function (r) { return "playerResponse" in r; })
|
|
161
|
-
.playerResponse,
|
|
162
|
-
};
|
|
173
|
+
_e = __read.apply(void 0, [_f.sent(), 2]), nextResponse = _e[0], playerResponse = _e[1];
|
|
174
|
+
data = { response: nextResponse.data, playerResponse: playerResponse.data };
|
|
163
175
|
if (!((_b = (_a = data.response) === null || _a === void 0 ? void 0 : _a.contents) === null || _b === void 0 ? void 0 : _b.twoColumnWatchNextResults.results.results.contents) ||
|
|
164
|
-
data.playerResponse.playabilityStatus.status === "ERROR") {
|
|
176
|
+
((_d = (_c = data.playerResponse) === null || _c === void 0 ? void 0 : _c.playabilityStatus) === null || _d === void 0 ? void 0 : _d.status) === "ERROR") {
|
|
165
177
|
return [2 /*return*/, undefined];
|
|
166
178
|
}
|
|
167
179
|
return [2 /*return*/, (!data.playerResponse.playabilityStatus.liveStreamability
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "youtubei",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.10",
|
|
4
4
|
"description": "Simple package to get information from youtube such as videos, playlists, channels, video information & comments, related videos, up next video, and more!",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://suspiciouslookingowl.github.io/youtubei",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"node-fetch": "2.
|
|
66
|
-
"protobufjs": "
|
|
65
|
+
"node-fetch": "2.7.0",
|
|
66
|
+
"protobufjs": "8.4.0"
|
|
67
67
|
}
|
|
68
68
|
}
|