youtubei 1.4.0 → 1.4.2

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.
@@ -4,12 +4,10 @@ exports.BaseChannelParser = void 0;
4
4
  const common_1 = require("../../common");
5
5
  class BaseChannelParser {
6
6
  static loadBaseChannel(target, data) {
7
- var _a;
8
- const { channelId, title, thumbnail, videoCountText, subscriberCountText } = data;
7
+ const { channelId, title, thumbnail, subscriberCountText } = data;
9
8
  target.id = channelId;
10
9
  target.name = title.simpleText;
11
10
  target.thumbnails = new common_1.Thumbnails().load(thumbnail.thumbnails);
12
- target.videoCount = common_1.stripToInt((_a = videoCountText === null || videoCountText === void 0 ? void 0 : videoCountText.runs) === null || _a === void 0 ? void 0 : _a[0].text) || 0; // TODO this sometimes contains subscriber count for some reason
13
11
  target.subscriberCount = subscriberCountText === null || subscriberCountText === void 0 ? void 0 : subscriberCountText.simpleText;
14
12
  return target;
15
13
  }
@@ -18,9 +18,9 @@ const Caption_1 = require("../Caption");
18
18
  * @example
19
19
  * ```js
20
20
  *
21
- * console.log(result.captions.languages.map((l) => `${l.code} - ${l.name}`)); // printing out available languages for captions
21
+ * console.log(video.captions.languages.map((l) => `${l.code} - ${l.name}`)); // printing out available languages for captions
22
22
  *
23
- * console.log(await result.captions.get("en")); // printing out captions of a specific language using language code
23
+ * console.log(await video.captions.get("en")); // printing out captions of a specific language using language code
24
24
  * ```
25
25
  */
26
26
  class VideoCaptions extends Base_1.Base {
@@ -7,16 +7,38 @@ const PlaylistCompact_1 = require("../PlaylistCompact");
7
7
  const VideoCompact_1 = require("../VideoCompact");
8
8
  class ChannelParser {
9
9
  static loadChannel(target, data) {
10
- const { channelId, title, avatar, subscriberCountText, } = data.header.c4TabbedHeaderRenderer;
10
+ var _a, _b, _c, _d, _e, _f, _g, _h;
11
+ let channelId, title, avatar, subscriberCountText, videoCountText, tvBanner, mobileBanner, banner;
12
+ const { c4TabbedHeaderRenderer, pageHeaderRenderer } = data.header;
13
+ if (c4TabbedHeaderRenderer) {
14
+ channelId = c4TabbedHeaderRenderer.channelId;
15
+ title = c4TabbedHeaderRenderer.title;
16
+ subscriberCountText = (_a = c4TabbedHeaderRenderer.subscriberCountText) === null || _a === void 0 ? void 0 : _a.simpleText;
17
+ videoCountText = (_d = (_c = (_b = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.videosCountText) === null || _b === void 0 ? void 0 : _b.runs) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.text;
18
+ avatar = (_e = c4TabbedHeaderRenderer.avatar) === null || _e === void 0 ? void 0 : _e.thumbnails;
19
+ tvBanner = (_f = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.tvBanner) === null || _f === void 0 ? void 0 : _f.thumbnails;
20
+ mobileBanner = (_g = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.mobileBanner) === null || _g === void 0 ? void 0 : _g.thumbnails;
21
+ banner = (_h = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.banner) === null || _h === void 0 ? void 0 : _h.thumbnails;
22
+ }
23
+ else {
24
+ channelId =
25
+ data.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.endpoint
26
+ .browseEndpoint.browseId;
27
+ title = pageHeaderRenderer.pageTitle;
28
+ const { metadata, image: imageModel, banner: bannerModel, } = pageHeaderRenderer.content.pageHeaderViewModel;
29
+ subscriberCountText =
30
+ metadata.contentMetadataViewModel.metadataRows[1].metadataParts[0].text.content;
31
+ avatar = imageModel.decoratedAvatarViewModel.avatar.avatarViewModel.image.sources;
32
+ banner = bannerModel.imageBannerViewModel.image.sources;
33
+ }
11
34
  target.id = channelId;
12
35
  target.name = title;
13
- target.thumbnails = new common_1.Thumbnails().load(avatar.thumbnails);
14
- target.videoCount = 0; // data not available
15
- target.subscriberCount = subscriberCountText === null || subscriberCountText === void 0 ? void 0 : subscriberCountText.simpleText;
16
- const { tvBanner, mobileBanner, banner } = data.header.c4TabbedHeaderRenderer;
17
- target.banner = new common_1.Thumbnails().load((banner === null || banner === void 0 ? void 0 : banner.thumbnails) || []);
18
- target.tvBanner = new common_1.Thumbnails().load((tvBanner === null || tvBanner === void 0 ? void 0 : tvBanner.thumbnails) || []);
19
- target.mobileBanner = new common_1.Thumbnails().load((mobileBanner === null || mobileBanner === void 0 ? void 0 : mobileBanner.thumbnails) || []);
36
+ target.thumbnails = new common_1.Thumbnails().load(avatar);
37
+ target.videoCount = videoCountText;
38
+ target.subscriberCount = subscriberCountText;
39
+ target.banner = new common_1.Thumbnails().load(banner || []);
40
+ target.tvBanner = new common_1.Thumbnails().load(tvBanner || []);
41
+ target.mobileBanner = new common_1.Thumbnails().load(mobileBanner || []);
20
42
  target.shelves = ChannelParser.parseShelves(target, data);
21
43
  return target;
22
44
  }
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./Base"), exports);
14
14
  __exportStar(require("./BaseChannel"), exports);
15
15
  __exportStar(require("./BaseVideo"), exports);
16
+ __exportStar(require("./Caption"), exports);
16
17
  __exportStar(require("./Channel"), exports);
17
18
  __exportStar(require("./Chat"), exports);
18
19
  __exportStar(require("./Client"), exports);
@@ -1,14 +1,12 @@
1
- import { stripToInt, Thumbnails } from "../../common";
1
+ import { Thumbnails } from "../../common";
2
2
  var BaseChannelParser = /** @class */ (function () {
3
3
  function BaseChannelParser() {
4
4
  }
5
5
  BaseChannelParser.loadBaseChannel = function (target, data) {
6
- var _a;
7
- var channelId = data.channelId, title = data.title, thumbnail = data.thumbnail, videoCountText = data.videoCountText, subscriberCountText = data.subscriberCountText;
6
+ var channelId = data.channelId, title = data.title, thumbnail = data.thumbnail, subscriberCountText = data.subscriberCountText;
8
7
  target.id = channelId;
9
8
  target.name = title.simpleText;
10
9
  target.thumbnails = new Thumbnails().load(thumbnail.thumbnails);
11
- target.videoCount = stripToInt((_a = videoCountText === null || videoCountText === void 0 ? void 0 : videoCountText.runs) === null || _a === void 0 ? void 0 : _a[0].text) || 0; // TODO this sometimes contains subscriber count for some reason
12
10
  target.subscriberCount = subscriberCountText === null || subscriberCountText === void 0 ? void 0 : subscriberCountText.simpleText;
13
11
  return target;
14
12
  };
@@ -55,9 +55,9 @@ import { Caption, CaptionLanguage } from "../Caption";
55
55
  * @example
56
56
  * ```js
57
57
  *
58
- * console.log(result.captions.languages.map((l) => `${l.code} - ${l.name}`)); // printing out available languages for captions
58
+ * console.log(video.captions.languages.map((l) => `${l.code} - ${l.name}`)); // printing out available languages for captions
59
59
  *
60
- * console.log(await result.captions.get("en")); // printing out captions of a specific language using language code
60
+ * console.log(await video.captions.get("en")); // printing out captions of a specific language using language code
61
61
  * ```
62
62
  */
63
63
  var VideoCaptions = /** @class */ (function (_super) {
@@ -17,16 +17,38 @@ var ChannelParser = /** @class */ (function () {
17
17
  function ChannelParser() {
18
18
  }
19
19
  ChannelParser.loadChannel = function (target, data) {
20
- var _a = data.header.c4TabbedHeaderRenderer, channelId = _a.channelId, title = _a.title, avatar = _a.avatar, subscriberCountText = _a.subscriberCountText;
20
+ var _a, _b, _c, _d, _e, _f, _g, _h;
21
+ var channelId, title, avatar, subscriberCountText, videoCountText, tvBanner, mobileBanner, banner;
22
+ var _j = data.header, c4TabbedHeaderRenderer = _j.c4TabbedHeaderRenderer, pageHeaderRenderer = _j.pageHeaderRenderer;
23
+ if (c4TabbedHeaderRenderer) {
24
+ channelId = c4TabbedHeaderRenderer.channelId;
25
+ title = c4TabbedHeaderRenderer.title;
26
+ subscriberCountText = (_a = c4TabbedHeaderRenderer.subscriberCountText) === null || _a === void 0 ? void 0 : _a.simpleText;
27
+ videoCountText = (_d = (_c = (_b = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.videosCountText) === null || _b === void 0 ? void 0 : _b.runs) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.text;
28
+ avatar = (_e = c4TabbedHeaderRenderer.avatar) === null || _e === void 0 ? void 0 : _e.thumbnails;
29
+ tvBanner = (_f = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.tvBanner) === null || _f === void 0 ? void 0 : _f.thumbnails;
30
+ mobileBanner = (_g = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.mobileBanner) === null || _g === void 0 ? void 0 : _g.thumbnails;
31
+ banner = (_h = c4TabbedHeaderRenderer === null || c4TabbedHeaderRenderer === void 0 ? void 0 : c4TabbedHeaderRenderer.banner) === null || _h === void 0 ? void 0 : _h.thumbnails;
32
+ }
33
+ else {
34
+ channelId =
35
+ data.contents.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.endpoint
36
+ .browseEndpoint.browseId;
37
+ title = pageHeaderRenderer.pageTitle;
38
+ var _k = pageHeaderRenderer.content.pageHeaderViewModel, metadata = _k.metadata, imageModel = _k.image, bannerModel = _k.banner;
39
+ subscriberCountText =
40
+ metadata.contentMetadataViewModel.metadataRows[1].metadataParts[0].text.content;
41
+ avatar = imageModel.decoratedAvatarViewModel.avatar.avatarViewModel.image.sources;
42
+ banner = bannerModel.imageBannerViewModel.image.sources;
43
+ }
21
44
  target.id = channelId;
22
45
  target.name = title;
23
- target.thumbnails = new Thumbnails().load(avatar.thumbnails);
24
- target.videoCount = 0; // data not available
25
- target.subscriberCount = subscriberCountText === null || subscriberCountText === void 0 ? void 0 : subscriberCountText.simpleText;
26
- var _b = data.header.c4TabbedHeaderRenderer, tvBanner = _b.tvBanner, mobileBanner = _b.mobileBanner, banner = _b.banner;
27
- target.banner = new Thumbnails().load((banner === null || banner === void 0 ? void 0 : banner.thumbnails) || []);
28
- target.tvBanner = new Thumbnails().load((tvBanner === null || tvBanner === void 0 ? void 0 : tvBanner.thumbnails) || []);
29
- target.mobileBanner = new Thumbnails().load((mobileBanner === null || mobileBanner === void 0 ? void 0 : mobileBanner.thumbnails) || []);
46
+ target.thumbnails = new Thumbnails().load(avatar);
47
+ target.videoCount = videoCountText;
48
+ target.subscriberCount = subscriberCountText;
49
+ target.banner = new Thumbnails().load(banner || []);
50
+ target.tvBanner = new Thumbnails().load(tvBanner || []);
51
+ target.mobileBanner = new Thumbnails().load(mobileBanner || []);
30
52
  target.shelves = ChannelParser.parseShelves(target, data);
31
53
  return target;
32
54
  };
@@ -1,6 +1,7 @@
1
1
  export * from "./Base";
2
2
  export * from "./BaseChannel";
3
3
  export * from "./BaseVideo";
4
+ export * from "./Caption";
4
5
  export * from "./Channel";
5
6
  export * from "./Chat";
6
7
  export * from "./Client";
@@ -9,7 +9,6 @@ export interface BaseChannelProperties extends BaseProperties {
9
9
  id?: string;
10
10
  name?: string;
11
11
  thumbnails?: Thumbnails;
12
- videoCount?: number;
13
12
  subscriberCount?: string;
14
13
  }
15
14
  /** Represents a Youtube Channel */
@@ -19,8 +18,6 @@ export declare class BaseChannel extends Base implements BaseChannelProperties {
19
18
  name: string;
20
19
  /** Thumbnails of this Channel */
21
20
  thumbnails?: Thumbnails;
22
- /** How many video does this channel have */
23
- videoCount?: number;
24
21
  /**
25
22
  * How many subscriber does this channel have,
26
23
  *
@@ -14,9 +14,9 @@ interface ConstructorParams {
14
14
  * @example
15
15
  * ```js
16
16
  *
17
- * console.log(result.captions.languages.map((l) => `${l.code} - ${l.name}`)); // printing out available languages for captions
17
+ * console.log(video.captions.languages.map((l) => `${l.code} - ${l.name}`)); // printing out available languages for captions
18
18
  *
19
- * console.log(await result.captions.get("en")); // printing out captions of a specific language using language code
19
+ * console.log(await video.captions.get("en")); // printing out captions of a specific language using language code
20
20
  * ```
21
21
  */
22
22
  export declare class VideoCaptions extends Base {
@@ -7,6 +7,7 @@ export declare type ChannelShelf = Shelf<BaseChannel[] | VideoCompact[] | Playli
7
7
  };
8
8
  /** @hidden */
9
9
  interface ChannelProperties extends BaseChannelProperties {
10
+ videoCount?: string;
10
11
  banner?: Thumbnails;
11
12
  tvBanner?: Thumbnails;
12
13
  mobileBanner?: Thumbnails;
@@ -14,6 +15,8 @@ interface ChannelProperties extends BaseChannelProperties {
14
15
  }
15
16
  /** Represents a Youtube Channel */
16
17
  export declare class Channel extends BaseChannel implements ChannelProperties {
18
+ /** How many video does this channel have */
19
+ videoCount?: string;
17
20
  banner: Thumbnails;
18
21
  mobileBanner: Thumbnails;
19
22
  tvBanner: Thumbnails;
@@ -1,6 +1,7 @@
1
1
  export * from "./Base";
2
2
  export * from "./BaseChannel";
3
3
  export * from "./BaseVideo";
4
+ export * from "./Caption";
4
5
  export * from "./Channel";
5
6
  export * from "./Chat";
6
7
  export * from "./Client";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "youtubei",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
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",
@@ -63,6 +63,6 @@
63
63
  "homepage": "https://suspiciouslookingowl.github.io/youtubei",
64
64
  "dependencies": {
65
65
  "node-fetch": "2.6.7",
66
- "protobufjs": "7.2.4"
66
+ "protobufjs": "7.2.6"
67
67
  }
68
68
  }