youtubei 1.8.6 → 1.8.7

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapFilter = exports.getContinuationFromItems = exports.stripToInt = exports.getDuration = void 0;
3
+ exports.getThumbnailFromId = exports.mapFilter = exports.getContinuationFromItems = exports.stripToInt = exports.getDuration = void 0;
4
4
  const getDuration = (s) => {
5
5
  s = s.replace(/:/g, ".");
6
6
  const spl = s.split(".");
@@ -47,3 +47,23 @@ const mapFilter = (items, key) => {
47
47
  .map((item) => item[key]);
48
48
  };
49
49
  exports.mapFilter = mapFilter;
50
+ const getThumbnailFromId = (id) => {
51
+ return [
52
+ {
53
+ url: `https://i.ytimg.com/vi/${id}/default.jpg`,
54
+ width: 120,
55
+ height: 90,
56
+ },
57
+ {
58
+ url: `https://i.ytimg.com/vi/${id}/mqdefault.jpg`,
59
+ width: 320,
60
+ height: 180,
61
+ },
62
+ {
63
+ url: `https://i.ytimg.com/vi/${id}/hqdefault.jpg`,
64
+ width: 480,
65
+ height: 360,
66
+ },
67
+ ];
68
+ };
69
+ exports.getThumbnailFromId = getThumbnailFromId;
@@ -8,17 +8,19 @@ 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;
11
+ var _a, _b, _c, _d, _e, _f, _g, _h;
12
12
  const videoInfo = BaseVideoParser.parseRawData(data);
13
13
  // Basic information
14
- target.id = videoInfo.videoDetails.videoId;
15
- target.title = videoInfo.videoDetails.title;
14
+ target.id = videoInfo.currentVideoEndpoint.watchEndpoint.videoId;
15
+ target.title =
16
+ videoInfo.playerOverlays.playerOverlayRenderer.videoDetails.playerOverlayVideoDetailsRenderer.title.simpleText;
17
+ target.viewCount =
18
+ common_1.stripToInt(videoInfo.viewCount.videoViewCountRenderer.viewCount.simpleText) || null;
19
+ target.isLiveContent = !!((_a = videoInfo.videoDetails) === null || _a === void 0 ? void 0 : _a.isLiveContent); // TODO remove dependence on player data
16
20
  target.uploadDate = videoInfo.dateText.simpleText;
17
- target.viewCount = +videoInfo.videoDetails.viewCount || null;
18
- target.isLiveContent = videoInfo.videoDetails.isLiveContent;
19
- target.formats = ((_a = videoInfo.streamingData) === null || _a === void 0 ? void 0 : _a.formats) || [];
20
- target.adaptiveFormats = ((_b = videoInfo.streamingData) === null || _b === void 0 ? void 0 : _b.adaptiveFormats) || [];
21
- target.thumbnails = new common_1.Thumbnails().load(videoInfo.videoDetails.thumbnail.thumbnails);
21
+ target.formats = ((_b = videoInfo.streamingData) === null || _b === void 0 ? void 0 : _b.formats) || [];
22
+ target.adaptiveFormats = ((_c = videoInfo.streamingData) === null || _c === void 0 ? void 0 : _c.adaptiveFormats) || [];
23
+ target.thumbnails = new common_1.Thumbnails().load(((_d = videoInfo.videoDetails) === null || _d === void 0 ? void 0 : _d.thumbnail.thumbnails) || common_1.getThumbnailFromId(target.id));
22
24
  // Channel
23
25
  const { title, thumbnail, subscriberCountText } = videoInfo.owner.videoOwnerRenderer;
24
26
  if (title) {
@@ -55,13 +57,13 @@ class BaseVideoParser {
55
57
  : null;
56
58
  // Tags and description
57
59
  target.tags =
58
- ((_d = (_c = videoInfo.superTitleLink) === null || _c === void 0 ? void 0 : _c.runs) === null || _d === void 0 ? void 0 : _d.map((r) => r.text.trim()).filter((t) => t)) || [];
59
- target.description = videoInfo.videoDetails.shortDescription || "";
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 = videoInfo.attributedDescription.content || ""; // TODO
60
62
  // related videos
61
- let secondaryContents = (_e = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _e === void 0 ? void 0 : _e.secondaryResults.results;
62
- const itemSectionRenderer = (_f = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find((c) => {
63
+ let secondaryContents = (_g = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _g === void 0 ? void 0 : _g.secondaryResults.results;
64
+ const itemSectionRenderer = (_h = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find((c) => {
63
65
  return c.itemSectionRenderer;
64
- })) === null || _f === void 0 ? void 0 : _f.itemSectionRenderer;
66
+ })) === null || _h === void 0 ? void 0 : _h.itemSectionRenderer;
65
67
  if (itemSectionRenderer)
66
68
  secondaryContents = itemSectionRenderer.contents;
67
69
  if (secondaryContents) {
@@ -88,7 +90,9 @@ class BaseVideoParser {
88
90
  .videoPrimaryInfoRenderer;
89
91
  const secondaryInfo = contents.find((c) => "videoSecondaryInfoRenderer" in c).videoSecondaryInfoRenderer;
90
92
  const { videoDetails, captions, streamingData } = data.playerResponse;
91
- return Object.assign(Object.assign(Object.assign({}, secondaryInfo), primaryInfo), { videoDetails, captions, streamingData });
93
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, data.response), secondaryInfo), primaryInfo), { videoDetails,
94
+ captions,
95
+ streamingData });
92
96
  }
93
97
  static parseCompactRenderer(data, client) {
94
98
  if ("compactVideoRenderer" in data) {
@@ -6,21 +6,25 @@ const BaseVideo_1 = require("../BaseVideo");
6
6
  const Comment_1 = require("../Comment");
7
7
  class VideoParser {
8
8
  static loadVideo(target, data) {
9
- var _a, _b, _c, _d, _e, _f;
9
+ var _a, _b, _c, _d, _e, _f, _g, _h;
10
10
  const videoInfo = BaseVideo_1.BaseVideoParser.parseRawData(data);
11
- target.duration = +videoInfo.videoDetails.lengthSeconds;
12
- const itemSectionRenderer = (_a = data.response.contents.twoColumnWatchNextResults.results.results.contents
11
+ const mutations = videoInfo.frameworkUpdates.entityBatchUpdate.mutations;
12
+ const lastMarkers = (_a = mutations.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;
13
+ target.duration =
14
+ +((_b = videoInfo.videoDetails) === null || _b === void 0 ? void 0 : _b.lengthSeconds) ||
15
+ (lastMarkers ? (+lastMarkers.startMillis + +lastMarkers.durationMillis) / 1000 : 0);
16
+ const itemSectionRenderer = (_c = data.response.contents.twoColumnWatchNextResults.results.results.contents
13
17
  .reverse()
14
- .find((c) => c.itemSectionRenderer)) === null || _a === void 0 ? void 0 : _a.itemSectionRenderer;
18
+ .find((c) => c.itemSectionRenderer)) === null || _c === void 0 ? void 0 : _c.itemSectionRenderer;
15
19
  target.comments.continuation = common_1.getContinuationFromItems((itemSectionRenderer === null || itemSectionRenderer === void 0 ? void 0 : itemSectionRenderer.contents) || []);
16
- const chapters = (_d = (_c = (_b = data.response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer) === null || _b === void 0 ? void 0 : _b.decoratedPlayerBarRenderer.playerBar) === null || _c === void 0 ? void 0 : _c.multiMarkersPlayerBarRenderer.markersMap) === null || _d === void 0 ? void 0 : _d[0].value.chapters;
20
+ const chapters = (_f = (_e = (_d = data.response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer) === null || _d === void 0 ? void 0 : _d.decoratedPlayerBarRenderer.playerBar) === null || _e === void 0 ? void 0 : _e.multiMarkersPlayerBarRenderer.markersMap) === null || _f === void 0 ? void 0 : _f[0].value.chapters;
17
21
  target.chapters =
18
22
  (chapters === null || chapters === void 0 ? void 0 : chapters.map(({ chapterRenderer: c }) => ({
19
23
  title: c.title.simpleText,
20
24
  start: c.timeRangeStartMillis,
21
25
  thumbnails: new common_1.Thumbnails().load(c.thumbnail.thumbnails),
22
26
  }))) || [];
23
- const musicPanel = (_e = data.response.engagementPanels) === null || _e === void 0 ? void 0 : _e.find((e) => { var _a, _b; return (_b = (_a = e.engagementPanelSectionListRenderer.content) === null || _a === void 0 ? void 0 : _a.structuredDescriptionContentRenderer) === null || _b === void 0 ? void 0 : _b.items.find((i) => { var _a, _b; return ((_b = (_a = i.horizontalCardListRenderer) === null || _a === void 0 ? void 0 : _a.footerButton) === null || _b === void 0 ? void 0 : _b.buttonViewModel.iconName) === "MUSIC"; }); });
27
+ const musicPanel = (_g = data.response.engagementPanels) === null || _g === void 0 ? void 0 : _g.find((e) => { var _a, _b; return (_b = (_a = e.engagementPanelSectionListRenderer.content) === null || _a === void 0 ? void 0 : _a.structuredDescriptionContentRenderer) === null || _b === void 0 ? void 0 : _b.items.find((i) => { var _a, _b; return ((_b = (_a = i.horizontalCardListRenderer) === null || _a === void 0 ? void 0 : _a.footerButton) === null || _b === void 0 ? void 0 : _b.buttonViewModel.iconName) === "MUSIC"; }); });
24
28
  if (!musicPanel) {
25
29
  target.music = null;
26
30
  }
@@ -32,7 +36,7 @@ class VideoParser {
32
36
  imageUrl: music.image.sources[0].url,
33
37
  title: music.title,
34
38
  artist: music.subtitle,
35
- album: ((_f = music.secondarySubtitle) === null || _f === void 0 ? void 0 : _f.content) || null,
39
+ album: ((_h = music.secondarySubtitle) === null || _h === void 0 ? void 0 : _h.content) || null,
36
40
  };
37
41
  }
38
42
  // target.music =
@@ -63,3 +63,22 @@ export var mapFilter = function (items, key) {
63
63
  .filter(function (item) { return item[key]; })
64
64
  .map(function (item) { return item[key]; });
65
65
  };
66
+ export var getThumbnailFromId = function (id) {
67
+ return [
68
+ {
69
+ url: "https://i.ytimg.com/vi/" + id + "/default.jpg",
70
+ width: 120,
71
+ height: 90,
72
+ },
73
+ {
74
+ url: "https://i.ytimg.com/vi/" + id + "/mqdefault.jpg",
75
+ width: 320,
76
+ height: 180,
77
+ },
78
+ {
79
+ url: "https://i.ytimg.com/vi/" + id + "/hqdefault.jpg",
80
+ width: 480,
81
+ height: 360,
82
+ },
83
+ ];
84
+ };
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { getContinuationFromItems, stripToInt, Thumbnails } from "../../common";
12
+ import { getContinuationFromItems, getThumbnailFromId, stripToInt, Thumbnails, } from "../../common";
13
13
  import { BaseChannel } from "../BaseChannel";
14
14
  import { PlaylistCompact } from "../PlaylistCompact";
15
15
  import { VideoCompact } from "../VideoCompact";
@@ -18,19 +18,21 @@ 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;
21
+ var _a, _b, _c, _d, _e, _f, _g, _h;
22
22
  var videoInfo = BaseVideoParser.parseRawData(data);
23
23
  // Basic information
24
- target.id = videoInfo.videoDetails.videoId;
25
- target.title = videoInfo.videoDetails.title;
24
+ target.id = videoInfo.currentVideoEndpoint.watchEndpoint.videoId;
25
+ target.title =
26
+ videoInfo.playerOverlays.playerOverlayRenderer.videoDetails.playerOverlayVideoDetailsRenderer.title.simpleText;
27
+ target.viewCount =
28
+ stripToInt(videoInfo.viewCount.videoViewCountRenderer.viewCount.simpleText) || null;
29
+ target.isLiveContent = !!((_a = videoInfo.videoDetails) === null || _a === void 0 ? void 0 : _a.isLiveContent); // TODO remove dependence on player data
26
30
  target.uploadDate = videoInfo.dateText.simpleText;
27
- target.viewCount = +videoInfo.videoDetails.viewCount || null;
28
- target.isLiveContent = videoInfo.videoDetails.isLiveContent;
29
- target.formats = ((_a = videoInfo.streamingData) === null || _a === void 0 ? void 0 : _a.formats) || [];
30
- target.adaptiveFormats = ((_b = videoInfo.streamingData) === null || _b === void 0 ? void 0 : _b.adaptiveFormats) || [];
31
- target.thumbnails = new Thumbnails().load(videoInfo.videoDetails.thumbnail.thumbnails);
31
+ target.formats = ((_b = videoInfo.streamingData) === null || _b === void 0 ? void 0 : _b.formats) || [];
32
+ target.adaptiveFormats = ((_c = videoInfo.streamingData) === null || _c === void 0 ? void 0 : _c.adaptiveFormats) || [];
33
+ target.thumbnails = new Thumbnails().load(((_d = videoInfo.videoDetails) === null || _d === void 0 ? void 0 : _d.thumbnail.thumbnails) || getThumbnailFromId(target.id));
32
34
  // Channel
33
- var _g = videoInfo.owner.videoOwnerRenderer, title = _g.title, thumbnail = _g.thumbnail, subscriberCountText = _g.subscriberCountText;
35
+ var _j = videoInfo.owner.videoOwnerRenderer, title = _j.title, thumbnail = _j.thumbnail, subscriberCountText = _j.subscriberCountText;
34
36
  if (title) {
35
37
  target.channel = new BaseChannel({
36
38
  client: target.client,
@@ -65,13 +67,13 @@ var BaseVideoParser = /** @class */ (function () {
65
67
  : null;
66
68
  // Tags and description
67
69
  target.tags =
68
- ((_d = (_c = videoInfo.superTitleLink) === null || _c === void 0 ? void 0 : _c.runs) === null || _d === void 0 ? void 0 : _d.map(function (r) { return r.text.trim(); }).filter(function (t) { return t; })) || [];
69
- target.description = videoInfo.videoDetails.shortDescription || "";
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 = videoInfo.attributedDescription.content || ""; // TODO
70
72
  // related videos
71
- var secondaryContents = (_e = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _e === void 0 ? void 0 : _e.secondaryResults.results;
72
- var itemSectionRenderer = (_f = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find(function (c) {
73
+ var secondaryContents = (_g = data.response.contents.twoColumnWatchNextResults.secondaryResults) === null || _g === void 0 ? void 0 : _g.secondaryResults.results;
74
+ var itemSectionRenderer = (_h = secondaryContents === null || secondaryContents === void 0 ? void 0 : secondaryContents.find(function (c) {
73
75
  return c.itemSectionRenderer;
74
- })) === null || _f === void 0 ? void 0 : _f.itemSectionRenderer;
76
+ })) === null || _h === void 0 ? void 0 : _h.itemSectionRenderer;
75
77
  if (itemSectionRenderer)
76
78
  secondaryContents = itemSectionRenderer.contents;
77
79
  if (secondaryContents) {
@@ -98,7 +100,9 @@ var BaseVideoParser = /** @class */ (function () {
98
100
  .videoPrimaryInfoRenderer;
99
101
  var secondaryInfo = contents.find(function (c) { return "videoSecondaryInfoRenderer" in c; }).videoSecondaryInfoRenderer;
100
102
  var _a = data.playerResponse, videoDetails = _a.videoDetails, captions = _a.captions, streamingData = _a.streamingData;
101
- return __assign(__assign(__assign({}, secondaryInfo), primaryInfo), { videoDetails: videoDetails, captions: captions, streamingData: streamingData });
103
+ return __assign(__assign(__assign(__assign({}, data.response), secondaryInfo), primaryInfo), { videoDetails: videoDetails,
104
+ captions: captions,
105
+ streamingData: streamingData });
102
106
  };
103
107
  BaseVideoParser.parseCompactRenderer = function (data, client) {
104
108
  if ("compactVideoRenderer" in data) {
@@ -16,14 +16,18 @@ var VideoParser = /** @class */ (function () {
16
16
  function VideoParser() {
17
17
  }
18
18
  VideoParser.loadVideo = function (target, data) {
19
- var _a, _b, _c, _d, _e, _f;
19
+ var _a, _b, _c, _d, _e, _f, _g, _h;
20
20
  var videoInfo = BaseVideoParser.parseRawData(data);
21
- target.duration = +videoInfo.videoDetails.lengthSeconds;
22
- var itemSectionRenderer = (_a = data.response.contents.twoColumnWatchNextResults.results.results.contents
21
+ var mutations = videoInfo.frameworkUpdates.entityBatchUpdate.mutations;
22
+ var lastMarkers = (_a = mutations.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;
23
+ target.duration =
24
+ +((_b = videoInfo.videoDetails) === null || _b === void 0 ? void 0 : _b.lengthSeconds) ||
25
+ (lastMarkers ? (+lastMarkers.startMillis + +lastMarkers.durationMillis) / 1000 : 0);
26
+ var itemSectionRenderer = (_c = data.response.contents.twoColumnWatchNextResults.results.results.contents
23
27
  .reverse()
24
- .find(function (c) { return c.itemSectionRenderer; })) === null || _a === void 0 ? void 0 : _a.itemSectionRenderer;
28
+ .find(function (c) { return c.itemSectionRenderer; })) === null || _c === void 0 ? void 0 : _c.itemSectionRenderer;
25
29
  target.comments.continuation = getContinuationFromItems((itemSectionRenderer === null || itemSectionRenderer === void 0 ? void 0 : itemSectionRenderer.contents) || []);
26
- var chapters = (_d = (_c = (_b = data.response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer) === null || _b === void 0 ? void 0 : _b.decoratedPlayerBarRenderer.playerBar) === null || _c === void 0 ? void 0 : _c.multiMarkersPlayerBarRenderer.markersMap) === null || _d === void 0 ? void 0 : _d[0].value.chapters;
30
+ var chapters = (_f = (_e = (_d = data.response.playerOverlays.playerOverlayRenderer.decoratedPlayerBarRenderer) === null || _d === void 0 ? void 0 : _d.decoratedPlayerBarRenderer.playerBar) === null || _e === void 0 ? void 0 : _e.multiMarkersPlayerBarRenderer.markersMap) === null || _f === void 0 ? void 0 : _f[0].value.chapters;
27
31
  target.chapters =
28
32
  (chapters === null || chapters === void 0 ? void 0 : chapters.map(function (_a) {
29
33
  var c = _a.chapterRenderer;
@@ -33,7 +37,7 @@ var VideoParser = /** @class */ (function () {
33
37
  thumbnails: new Thumbnails().load(c.thumbnail.thumbnails),
34
38
  });
35
39
  })) || [];
36
- var musicPanel = (_e = data.response.engagementPanels) === null || _e === void 0 ? void 0 : _e.find(function (e) { var _a, _b; return (_b = (_a = e.engagementPanelSectionListRenderer.content) === null || _a === void 0 ? void 0 : _a.structuredDescriptionContentRenderer) === null || _b === void 0 ? void 0 : _b.items.find(function (i) { var _a, _b; return ((_b = (_a = i.horizontalCardListRenderer) === null || _a === void 0 ? void 0 : _a.footerButton) === null || _b === void 0 ? void 0 : _b.buttonViewModel.iconName) === "MUSIC"; }); });
40
+ var musicPanel = (_g = data.response.engagementPanels) === null || _g === void 0 ? void 0 : _g.find(function (e) { var _a, _b; return (_b = (_a = e.engagementPanelSectionListRenderer.content) === null || _a === void 0 ? void 0 : _a.structuredDescriptionContentRenderer) === null || _b === void 0 ? void 0 : _b.items.find(function (i) { var _a, _b; return ((_b = (_a = i.horizontalCardListRenderer) === null || _a === void 0 ? void 0 : _a.footerButton) === null || _b === void 0 ? void 0 : _b.buttonViewModel.iconName) === "MUSIC"; }); });
37
41
  if (!musicPanel) {
38
42
  target.music = null;
39
43
  }
@@ -45,7 +49,7 @@ var VideoParser = /** @class */ (function () {
45
49
  imageUrl: music.image.sources[0].url,
46
50
  title: music.title,
47
51
  artist: music.subtitle,
48
- album: ((_f = music.secondarySubtitle) === null || _f === void 0 ? void 0 : _f.content) || null,
52
+ album: ((_h = music.secondarySubtitle) === null || _h === void 0 ? void 0 : _h.content) || null,
49
53
  };
50
54
  }
51
55
  // target.music =
@@ -1,5 +1,7 @@
1
+ import { Thumbnail } from "../shared";
1
2
  import { YoutubeRawData } from "./types";
2
3
  export declare const getDuration: (s: string) => number;
3
4
  export declare const stripToInt: (string: string) => number | null;
4
5
  export declare const getContinuationFromItems: (items: YoutubeRawData, accessors?: string[]) => string | undefined;
5
6
  export declare const mapFilter: (items: YoutubeRawData, key: string) => YoutubeRawData;
7
+ export declare const getThumbnailFromId: (id: string) => Thumbnail[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "youtubei",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
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",