youtubei 1.0.0-rc.7 → 1.0.0-rc.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.
@@ -21,11 +21,6 @@ class Video extends BaseVideo_1.BaseVideo {
21
21
  Object.assign(this, attr);
22
22
  this.comments = new VideoComments_1.VideoComments({ client: attr.client, video: this });
23
23
  }
24
- getTranscript() {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return this.client.getVideoTranscript(this.id);
27
- });
28
- }
29
24
  /**
30
25
  * Load this instance with raw data from Youtube
31
26
  *
@@ -36,5 +31,18 @@ class Video extends BaseVideo_1.BaseVideo {
36
31
  VideoParser_1.VideoParser.loadVideo(this, data);
37
32
  return this;
38
33
  }
34
+ /**
35
+ * Get Video transcript (if exists)
36
+ *
37
+ * Equivalent to
38
+ * ```js
39
+ * client.getVideoTranscript(video.id);
40
+ * ```
41
+ */
42
+ getTranscript() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ return this.client.getVideoTranscript(this.id);
45
+ });
46
+ }
39
47
  }
40
48
  exports.Video = Video;
@@ -4,15 +4,23 @@ exports.VideoParser = void 0;
4
4
  const common_1 = require("../../common");
5
5
  const BaseVideo_1 = require("../BaseVideo");
6
6
  const Comment_1 = require("../Comment");
7
+ const Thumbnails_1 = require("../Thumbnails");
7
8
  class VideoParser {
8
9
  static loadVideo(target, data) {
9
- var _a;
10
+ var _a, _b, _c;
10
11
  const videoInfo = BaseVideo_1.BaseVideoParser.parseRawData(data);
11
12
  target.duration = +videoInfo.videoDetails.lengthSeconds;
12
13
  const itemSectionRenderer = (_a = data[3].response.contents.twoColumnWatchNextResults.results.results.contents
13
14
  .reverse()
14
15
  .find((c) => c.itemSectionRenderer)) === null || _a === void 0 ? void 0 : _a.itemSectionRenderer;
15
16
  target.comments.continuation = common_1.getContinuationFromItems((itemSectionRenderer === null || itemSectionRenderer === void 0 ? void 0 : itemSectionRenderer.contents) || []);
17
+ const chapters = (_c = (_b = data[3].response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer) === null || _b === void 0 ? void 0 : _b.decoratedPlayerBarRenderer.playerBar.multiMarkersPlayerBarRenderer.markersMap) === null || _c === void 0 ? void 0 : _c[0].value.chapters;
18
+ target.chapters =
19
+ (chapters === null || chapters === void 0 ? void 0 : chapters.map(({ chapterRenderer: c }) => ({
20
+ title: c.title.simpleText,
21
+ start: c.timeRangeStartMillis,
22
+ thumbnails: new Thumbnails_1.Thumbnails().load(c.thumbnail.thumbnails),
23
+ }))) || [];
16
24
  return target;
17
25
  }
18
26
  static parseComments(data, video) {
@@ -23,11 +23,6 @@ class VideoCompact extends Base_1.Base {
23
23
  get isPrivateOrDeleted() {
24
24
  return !this.duration;
25
25
  }
26
- getTranscript() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return this.client.getVideoTranscript(this.id);
29
- });
30
- }
31
26
  /**
32
27
  * Load this instance with raw data from Youtube
33
28
  *
@@ -50,5 +45,18 @@ class VideoCompact extends Base_1.Base {
50
45
  return yield this.client.getVideo(this.id);
51
46
  });
52
47
  }
48
+ /**
49
+ * Get Video transcript (if exists)
50
+ *
51
+ * Equivalent to
52
+ * ```js
53
+ * client.getVideoTranscript(video.id);
54
+ * ```
55
+ */
56
+ getTranscript() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ return this.client.getVideoTranscript(this.id);
59
+ });
60
+ }
53
61
  }
54
62
  exports.VideoCompact = VideoCompact;
@@ -20,14 +20,18 @@ class VideoCompactParser {
20
20
  target.isLive = !!((badges === null || badges === void 0 ? void 0 : badges[0].metadataBadgeRenderer.style) === "BADGE_STYLE_TYPE_LIVE_NOW");
21
21
  // Channel
22
22
  if (ownerText || shortBylineText) {
23
- const { browseId } = (ownerText || shortBylineText).runs[0].navigationEndpoint.browseEndpoint;
24
- const thumbnails = channelThumbnailSupportedRenderers === null || channelThumbnailSupportedRenderers === void 0 ? void 0 : channelThumbnailSupportedRenderers.channelThumbnailWithLinkRenderer.thumbnail.thumbnails;
25
- target.channel = new BaseChannel_1.BaseChannel({
26
- id: browseId,
27
- name: (ownerText || shortBylineText).runs[0].text,
28
- thumbnails: thumbnails ? new Thumbnails_1.Thumbnails().load(thumbnails) : undefined,
29
- client: target.client,
30
- });
23
+ const browseEndpoint = (ownerText || shortBylineText).runs[0].navigationEndpoint
24
+ .browseEndpoint;
25
+ if (browseEndpoint) {
26
+ const id = browseEndpoint.browseId;
27
+ const thumbnails = channelThumbnailSupportedRenderers === null || channelThumbnailSupportedRenderers === void 0 ? void 0 : channelThumbnailSupportedRenderers.channelThumbnailWithLinkRenderer.thumbnail.thumbnails;
28
+ target.channel = new BaseChannel_1.BaseChannel({
29
+ id,
30
+ name: (ownerText || shortBylineText).runs[0].text,
31
+ thumbnails: thumbnails ? new Thumbnails_1.Thumbnails().load(thumbnails) : undefined,
32
+ client: target.client,
33
+ });
34
+ }
31
35
  }
32
36
  target.viewCount = common_1.stripToInt((viewCountText === null || viewCountText === void 0 ? void 0 : viewCountText.simpleText) || (viewCountText === null || viewCountText === void 0 ? void 0 : viewCountText.runs[0].text));
33
37
  return target;
@@ -60,13 +60,6 @@ var Video = /** @class */ (function (_super) {
60
60
  _this.comments = new VideoComments({ client: attr.client, video: _this });
61
61
  return _this;
62
62
  }
63
- Video.prototype.getTranscript = function () {
64
- return __awaiter(this, void 0, void 0, function () {
65
- return __generator(this, function (_a) {
66
- return [2 /*return*/, this.client.getVideoTranscript(this.id)];
67
- });
68
- });
69
- };
70
63
  /**
71
64
  * Load this instance with raw data from Youtube
72
65
  *
@@ -77,6 +70,21 @@ var Video = /** @class */ (function (_super) {
77
70
  VideoParser.loadVideo(this, data);
78
71
  return this;
79
72
  };
73
+ /**
74
+ * Get Video transcript (if exists)
75
+ *
76
+ * Equivalent to
77
+ * ```js
78
+ * client.getVideoTranscript(video.id);
79
+ * ```
80
+ */
81
+ Video.prototype.getTranscript = function () {
82
+ return __awaiter(this, void 0, void 0, function () {
83
+ return __generator(this, function (_a) {
84
+ return [2 /*return*/, this.client.getVideoTranscript(this.id)];
85
+ });
86
+ });
87
+ };
80
88
  return Video;
81
89
  }(BaseVideo));
82
90
  export { Video };
@@ -1,17 +1,28 @@
1
1
  import { getContinuationFromItems, mapFilter } from "../../common";
2
2
  import { BaseVideoParser } from "../BaseVideo";
3
3
  import { Comment } from "../Comment";
4
+ import { Thumbnails } from "../Thumbnails";
4
5
  var VideoParser = /** @class */ (function () {
5
6
  function VideoParser() {
6
7
  }
7
8
  VideoParser.loadVideo = function (target, data) {
8
- var _a;
9
+ var _a, _b, _c;
9
10
  var videoInfo = BaseVideoParser.parseRawData(data);
10
11
  target.duration = +videoInfo.videoDetails.lengthSeconds;
11
12
  var itemSectionRenderer = (_a = data[3].response.contents.twoColumnWatchNextResults.results.results.contents
12
13
  .reverse()
13
14
  .find(function (c) { return c.itemSectionRenderer; })) === null || _a === void 0 ? void 0 : _a.itemSectionRenderer;
14
15
  target.comments.continuation = getContinuationFromItems((itemSectionRenderer === null || itemSectionRenderer === void 0 ? void 0 : itemSectionRenderer.contents) || []);
16
+ var chapters = (_c = (_b = data[3].response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer) === null || _b === void 0 ? void 0 : _b.decoratedPlayerBarRenderer.playerBar.multiMarkersPlayerBarRenderer.markersMap) === null || _c === void 0 ? void 0 : _c[0].value.chapters;
17
+ target.chapters =
18
+ (chapters === null || chapters === void 0 ? void 0 : chapters.map(function (_a) {
19
+ var c = _a.chapterRenderer;
20
+ return ({
21
+ title: c.title.simpleText,
22
+ start: c.timeRangeStartMillis,
23
+ thumbnails: new Thumbnails().load(c.thumbnail.thumbnails),
24
+ });
25
+ })) || [];
15
26
  return target;
16
27
  };
17
28
  VideoParser.parseComments = function (data, video) {
@@ -66,13 +66,6 @@ var VideoCompact = /** @class */ (function (_super) {
66
66
  enumerable: false,
67
67
  configurable: true
68
68
  });
69
- VideoCompact.prototype.getTranscript = function () {
70
- return __awaiter(this, void 0, void 0, function () {
71
- return __generator(this, function (_a) {
72
- return [2 /*return*/, this.client.getVideoTranscript(this.id)];
73
- });
74
- });
75
- };
76
69
  /**
77
70
  * Load this instance with raw data from Youtube
78
71
  *
@@ -100,6 +93,21 @@ var VideoCompact = /** @class */ (function (_super) {
100
93
  });
101
94
  });
102
95
  };
96
+ /**
97
+ * Get Video transcript (if exists)
98
+ *
99
+ * Equivalent to
100
+ * ```js
101
+ * client.getVideoTranscript(video.id);
102
+ * ```
103
+ */
104
+ VideoCompact.prototype.getTranscript = function () {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ return __generator(this, function (_a) {
107
+ return [2 /*return*/, this.client.getVideoTranscript(this.id)];
108
+ });
109
+ });
110
+ };
103
111
  return VideoCompact;
104
112
  }(Base));
105
113
  export { VideoCompact };
@@ -19,14 +19,18 @@ var VideoCompactParser = /** @class */ (function () {
19
19
  target.isLive = !!((badges === null || badges === void 0 ? void 0 : badges[0].metadataBadgeRenderer.style) === "BADGE_STYLE_TYPE_LIVE_NOW");
20
20
  // Channel
21
21
  if (ownerText || shortBylineText) {
22
- var browseId = (ownerText || shortBylineText).runs[0].navigationEndpoint.browseEndpoint.browseId;
23
- var thumbnails = channelThumbnailSupportedRenderers === null || channelThumbnailSupportedRenderers === void 0 ? void 0 : channelThumbnailSupportedRenderers.channelThumbnailWithLinkRenderer.thumbnail.thumbnails;
24
- target.channel = new BaseChannel({
25
- id: browseId,
26
- name: (ownerText || shortBylineText).runs[0].text,
27
- thumbnails: thumbnails ? new Thumbnails().load(thumbnails) : undefined,
28
- client: target.client,
29
- });
22
+ var browseEndpoint = (ownerText || shortBylineText).runs[0].navigationEndpoint
23
+ .browseEndpoint;
24
+ if (browseEndpoint) {
25
+ var id = browseEndpoint.browseId;
26
+ var thumbnails = channelThumbnailSupportedRenderers === null || channelThumbnailSupportedRenderers === void 0 ? void 0 : channelThumbnailSupportedRenderers.channelThumbnailWithLinkRenderer.thumbnail.thumbnails;
27
+ target.channel = new BaseChannel({
28
+ id: id,
29
+ name: (ownerText || shortBylineText).runs[0].text,
30
+ thumbnails: thumbnails ? new Thumbnails().load(thumbnails) : undefined,
31
+ client: target.client,
32
+ });
33
+ }
30
34
  }
31
35
  target.viewCount = stripToInt((viewCountText === null || viewCountText === void 0 ? void 0 : viewCountText.simpleText) || (viewCountText === null || viewCountText === void 0 ? void 0 : viewCountText.runs[0].text));
32
36
  return target;
@@ -1,26 +1,43 @@
1
1
  import { YoutubeRawData } from "../../common";
2
2
  import { BaseVideo, BaseVideoProperties } from "../BaseVideo";
3
+ import { Thumbnails } from "../Thumbnails";
3
4
  import { Transcript } from "../Transcript";
4
5
  import { VideoComments } from "./VideoComments";
6
+ export declare type Chapter = {
7
+ title: string;
8
+ start: number;
9
+ thumbnails: Thumbnails;
10
+ };
5
11
  /** @hidden */
6
12
  interface VideoProperties extends BaseVideoProperties {
7
13
  duration?: number;
8
14
  comments?: VideoComments;
15
+ chapters?: Chapter[];
9
16
  }
10
17
  /** Represents a Video, usually returned from `client.getVideo()` */
11
18
  export declare class Video extends BaseVideo implements VideoProperties {
12
19
  /** The duration of this video in second */
13
20
  duration: number;
21
+ /** Chapters on this video if exists */
22
+ chapters: Chapter[];
14
23
  /** {@link Continuable} of videos inside a {@link Video} */
15
24
  comments: VideoComments;
16
25
  /** @hidden */
17
26
  constructor(attr: VideoProperties);
18
- getTranscript(): Promise<Transcript[] | undefined>;
19
27
  /**
20
28
  * Load this instance with raw data from Youtube
21
29
  *
22
30
  * @hidden
23
31
  */
24
32
  load(data: YoutubeRawData): Video;
33
+ /**
34
+ * Get Video transcript (if exists)
35
+ *
36
+ * Equivalent to
37
+ * ```js
38
+ * client.getVideoTranscript(video.id);
39
+ * ```
40
+ */
41
+ getTranscript(): Promise<Transcript[] | undefined>;
25
42
  }
26
43
  export {};
@@ -39,7 +39,6 @@ export declare class VideoCompact extends Base implements VideoCompactProperties
39
39
  constructor(attr: VideoCompactProperties);
40
40
  /** Whether this video is private / deleted or not, only useful in playlist's videos */
41
41
  get isPrivateOrDeleted(): boolean;
42
- getTranscript(): Promise<Transcript[] | undefined>;
43
42
  /**
44
43
  * Load this instance with raw data from Youtube
45
44
  *
@@ -55,5 +54,14 @@ export declare class VideoCompact extends Base implements VideoCompactProperties
55
54
  * ```
56
55
  */
57
56
  getVideo<T extends Video | LiveVideo>(): Promise<T>;
57
+ /**
58
+ * Get Video transcript (if exists)
59
+ *
60
+ * Equivalent to
61
+ * ```js
62
+ * client.getVideoTranscript(video.id);
63
+ * ```
64
+ */
65
+ getTranscript(): Promise<Transcript[] | undefined>;
58
66
  }
59
67
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "youtubei",
3
- "version": "1.0.0-rc.7",
3
+ "version": "1.0.0-rc.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",