youtubei 1.8.8 → 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.
@@ -55,16 +55,15 @@ class HTTP {
55
55
  }
56
56
  request(path, partialOptions) {
57
57
  return __awaiter(this, void 0, void 0, function* () {
58
- if (this.authorizationPromise)
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
@@ -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 response = yield this.http.post(`${constants_1.I_END_POINT}/get_watch`, {
86
- data: { playerRequest: { videoId }, watchNextRequest: { videoId } },
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
- if (!this.authorizationPromise) return [3 /*break*/, 2];
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:
@@ -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 response, data;
150
- return __generator(this, function (_c) {
151
- switch (_c.label) {
152
- case 0: return [4 /*yield*/, this.http.post(I_END_POINT + "/get_watch", {
153
- data: { playerRequest: { videoId: videoId }, watchNextRequest: { videoId: videoId } },
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
- response = _c.sent();
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.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",