youtubei 1.8.7 → 1.8.9
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/BaseVideo/BaseVideoParser.js +8 -5
- package/dist/cjs/youtube/Client/Client.js +2 -2
- package/dist/cjs/youtube/Video/VideoParser.js +2 -1
- package/dist/esm/common/shared/HTTP/HTTP.js +5 -6
- package/dist/esm/youtube/BaseVideo/BaseVideoParser.js +9 -6
- package/dist/esm/youtube/Client/Client.js +6 -6
- package/dist/esm/youtube/Video/VideoParser.js +2 -1
- package/package.json +1 -1
|
@@ -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
|
|
@@ -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;
|
|
11
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
12
12
|
const videoInfo = BaseVideoParser.parseRawData(data);
|
|
13
13
|
// Basic information
|
|
14
14
|
target.id = videoInfo.currentVideoEndpoint.watchEndpoint.videoId;
|
|
@@ -58,12 +58,15 @@ class BaseVideoParser {
|
|
|
58
58
|
// Tags and description
|
|
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
|
-
target.description =
|
|
61
|
+
target.description =
|
|
62
|
+
((_g = videoInfo.videoDetails) === null || _g === void 0 ? void 0 : _g.shortDescription) ||
|
|
63
|
+
videoInfo.attributedDescription.content ||
|
|
64
|
+
"";
|
|
62
65
|
// related videos
|
|
63
|
-
let secondaryContents = (
|
|
64
|
-
const itemSectionRenderer = (
|
|
66
|
+
let secondaryContents = (_h = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _h === void 0 ? void 0 : _h.secondaryResults.results;
|
|
67
|
+
const itemSectionRenderer = (_j = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find((c) => {
|
|
65
68
|
return c.itemSectionRenderer;
|
|
66
|
-
})) === null ||
|
|
69
|
+
})) === null || _j === void 0 ? void 0 : _j.itemSectionRenderer;
|
|
67
70
|
if (itemSectionRenderer)
|
|
68
71
|
secondaryContents = itemSectionRenderer.contents;
|
|
69
72
|
if (secondaryContents) {
|
|
@@ -80,14 +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
85
|
const nextPromise = this.http.post(`${constants_1.I_END_POINT}/next`, { data: { videoId } });
|
|
86
86
|
const playerPromise = this.http.post(`${constants_1.I_END_POINT}/player`, { data: { videoId } });
|
|
87
87
|
const [nextResponse, playerResponse] = yield Promise.all([nextPromise, playerPromise]);
|
|
88
88
|
const data = { response: nextResponse.data, playerResponse: playerResponse.data };
|
|
89
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) ||
|
|
90
|
-
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") {
|
|
91
91
|
return undefined;
|
|
92
92
|
}
|
|
93
93
|
return (!data.playerResponse.playabilityStatus.liveStreamability
|
|
@@ -9,7 +9,8 @@ class VideoParser {
|
|
|
9
9
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10
10
|
const videoInfo = BaseVideo_1.BaseVideoParser.parseRawData(data);
|
|
11
11
|
const mutations = videoInfo.frameworkUpdates.entityBatchUpdate.mutations;
|
|
12
|
-
const lastMarkers = (_a = mutations
|
|
12
|
+
const lastMarkers = (_a = mutations
|
|
13
|
+
.find((m) => { var _a; return (_a = m.payload) === null || _a === void 0 ? void 0 : _a.macroMarkersListEntity; })) === null || _a === void 0 ? void 0 : _a.payload.macroMarkersListEntity.markersList.markers.at(-1);
|
|
13
14
|
target.duration =
|
|
14
15
|
+((_b = videoInfo.videoDetails) === null || _b === void 0 ? void 0 : _b.lengthSeconds) ||
|
|
15
16
|
(lastMarkers ? (+lastMarkers.startMillis + +lastMarkers.durationMillis) / 1000 : 0);
|
|
@@ -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:
|
|
@@ -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;
|
|
21
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
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 _k = videoInfo.owner.videoOwnerRenderer, title = _k.title, thumbnail = _k.thumbnail, subscriberCountText = _k.subscriberCountText;
|
|
36
36
|
if (title) {
|
|
37
37
|
target.channel = new BaseChannel({
|
|
38
38
|
client: target.client,
|
|
@@ -68,12 +68,15 @@ var BaseVideoParser = /** @class */ (function () {
|
|
|
68
68
|
// Tags and description
|
|
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
|
-
target.description =
|
|
71
|
+
target.description =
|
|
72
|
+
((_g = videoInfo.videoDetails) === null || _g === void 0 ? void 0 : _g.shortDescription) ||
|
|
73
|
+
videoInfo.attributedDescription.content ||
|
|
74
|
+
"";
|
|
72
75
|
// related videos
|
|
73
|
-
var secondaryContents = (
|
|
74
|
-
var itemSectionRenderer = (
|
|
76
|
+
var secondaryContents = (_h = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _h === void 0 ? void 0 : _h.secondaryResults.results;
|
|
77
|
+
var itemSectionRenderer = (_j = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find(function (c) {
|
|
75
78
|
return c.itemSectionRenderer;
|
|
76
|
-
})) === null ||
|
|
79
|
+
})) === null || _j === void 0 ? void 0 : _j.itemSectionRenderer;
|
|
77
80
|
if (itemSectionRenderer)
|
|
78
81
|
secondaryContents = itemSectionRenderer.contents;
|
|
79
82
|
if (secondaryContents) {
|
|
@@ -160,20 +160,20 @@ var Client = /** @class */ (function () {
|
|
|
160
160
|
};
|
|
161
161
|
/** Get video information by video id or URL */
|
|
162
162
|
Client.prototype.getVideo = function (videoId) {
|
|
163
|
-
var _a, _b;
|
|
163
|
+
var _a, _b, _c, _d;
|
|
164
164
|
return __awaiter(this, void 0, void 0, function () {
|
|
165
|
-
var nextPromise, playerPromise,
|
|
166
|
-
return __generator(this, function (
|
|
167
|
-
switch (
|
|
165
|
+
var nextPromise, playerPromise, _e, nextResponse, playerResponse, data;
|
|
166
|
+
return __generator(this, function (_f) {
|
|
167
|
+
switch (_f.label) {
|
|
168
168
|
case 0:
|
|
169
169
|
nextPromise = this.http.post(I_END_POINT + "/next", { data: { videoId: videoId } });
|
|
170
170
|
playerPromise = this.http.post(I_END_POINT + "/player", { data: { videoId: videoId } });
|
|
171
171
|
return [4 /*yield*/, Promise.all([nextPromise, playerPromise])];
|
|
172
172
|
case 1:
|
|
173
|
-
|
|
173
|
+
_e = __read.apply(void 0, [_f.sent(), 2]), nextResponse = _e[0], playerResponse = _e[1];
|
|
174
174
|
data = { response: nextResponse.data, playerResponse: playerResponse.data };
|
|
175
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) ||
|
|
176
|
-
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") {
|
|
177
177
|
return [2 /*return*/, undefined];
|
|
178
178
|
}
|
|
179
179
|
return [2 /*return*/, (!data.playerResponse.playabilityStatus.liveStreamability
|
|
@@ -19,7 +19,8 @@ var VideoParser = /** @class */ (function () {
|
|
|
19
19
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
20
20
|
var videoInfo = BaseVideoParser.parseRawData(data);
|
|
21
21
|
var mutations = videoInfo.frameworkUpdates.entityBatchUpdate.mutations;
|
|
22
|
-
var lastMarkers = (_a = mutations
|
|
22
|
+
var lastMarkers = (_a = mutations
|
|
23
|
+
.find(function (m) { var _a; return (_a = m.payload) === null || _a === void 0 ? void 0 : _a.macroMarkersListEntity; })) === null || _a === void 0 ? void 0 : _a.payload.macroMarkersListEntity.markersList.markers.at(-1);
|
|
23
24
|
target.duration =
|
|
24
25
|
+((_b = videoInfo.videoDetails) === null || _b === void 0 ? void 0 : _b.lengthSeconds) ||
|
|
25
26
|
(lastMarkers ? (+lastMarkers.startMillis + +lastMarkers.durationMillis) / 1000 : 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "youtubei",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9",
|
|
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",
|