youtubei 1.8.0 → 1.8.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.
- package/dist/cjs/music/MusicSearchResult/MusicSearchResult.js +2 -0
- package/dist/cjs/music/MusicSearchResult/MusicSearchResultParser.js +18 -8
- package/dist/cjs/youtube/Video/VideoParser.js +17 -1
- package/dist/esm/music/MusicSearchResult/MusicSearchResult.js +2 -0
- package/dist/esm/music/MusicSearchResult/MusicSearchResultParser.js +19 -8
- package/dist/esm/youtube/Video/VideoParser.js +17 -1
- package/dist/typings/music/MusicSearchResult/MusicSearchResult.d.ts +4 -0
- package/dist/typings/music/MusicSearchResult/MusicSearchResultParser.d.ts +4 -1
- package/dist/typings/youtube/Video/Video.d.ts +8 -0
- package/package.json +1 -1
|
@@ -45,6 +45,7 @@ class MusicSearchResult extends MusicContinuable_1.MusicContinuable {
|
|
|
45
45
|
/** @hidden */
|
|
46
46
|
constructor({ client, type }) {
|
|
47
47
|
super({ client });
|
|
48
|
+
this.top = null;
|
|
48
49
|
if (type)
|
|
49
50
|
this.type = type;
|
|
50
51
|
}
|
|
@@ -70,6 +71,7 @@ class MusicSearchResult extends MusicContinuable_1.MusicContinuable {
|
|
|
70
71
|
},
|
|
71
72
|
});
|
|
72
73
|
const { data, continuation } = MusicSearchResultParser_1.MusicSearchResultParser.parseInitialSearchResult(response.data, this.client);
|
|
74
|
+
this.top = MusicSearchResultParser_1.MusicSearchResultParser.parseTopResult(response.data, this.client) || null;
|
|
73
75
|
this.items.push(...data);
|
|
74
76
|
this.continuation = continuation;
|
|
75
77
|
return this;
|
|
@@ -14,20 +14,16 @@ class MusicSearchResultParser {
|
|
|
14
14
|
var _a, _b;
|
|
15
15
|
const sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
16
16
|
.sectionListRenderer.contents;
|
|
17
|
-
const topContent = sectionContents.find((c) => "musicCardShelfRenderer" in c);
|
|
18
17
|
const resultContents = sectionContents.find((c) => "musicShelfRenderer" in c);
|
|
19
|
-
const topResult = this.parseTopResult(topContent, client);
|
|
20
18
|
if (!resultContents) {
|
|
21
19
|
// no results
|
|
22
20
|
return {
|
|
23
|
-
data:
|
|
21
|
+
data: [],
|
|
24
22
|
continuation: undefined,
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
const { contents, continuations } = resultContents.musicShelfRenderer;
|
|
28
26
|
const result = MusicSearchResultParser.parseSearchResult(contents, client);
|
|
29
|
-
if (topResult)
|
|
30
|
-
result.unshift(topResult);
|
|
31
27
|
return {
|
|
32
28
|
data: result,
|
|
33
29
|
continuation: (_b = (_a = continuations === null || continuations === void 0 ? void 0 : continuations[0]) === null || _a === void 0 ? void 0 : _a.nextContinuationData) === null || _b === void 0 ? void 0 : _b.continuation,
|
|
@@ -41,9 +37,12 @@ class MusicSearchResultParser {
|
|
|
41
37
|
};
|
|
42
38
|
}
|
|
43
39
|
static parseTopResult(data, client) {
|
|
44
|
-
const
|
|
40
|
+
const sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
41
|
+
.sectionListRenderer.contents;
|
|
42
|
+
const topContent = sectionContents.find((c) => "musicCardShelfRenderer" in c);
|
|
43
|
+
const top = topContent === null || topContent === void 0 ? void 0 : topContent.musicCardShelfRenderer;
|
|
45
44
|
if (!top)
|
|
46
|
-
return;
|
|
45
|
+
return null;
|
|
47
46
|
const { browseEndpoint, watchEndpoint } = top.title.runs[0].navigationEndpoint;
|
|
48
47
|
const id = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.videoId) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseId);
|
|
49
48
|
const type = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.watchEndpointMusicSupportedConfigs.watchEndpointMusicConfig.musicVideoType) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType);
|
|
@@ -97,7 +96,18 @@ class MusicSearchResultParser {
|
|
|
97
96
|
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
98
97
|
});
|
|
99
98
|
}
|
|
100
|
-
|
|
99
|
+
if (!topResult)
|
|
100
|
+
return null;
|
|
101
|
+
let more = [];
|
|
102
|
+
if (top.contents) {
|
|
103
|
+
more = top.contents
|
|
104
|
+
.filter((c) => c.musicResponsiveListItemRenderer)
|
|
105
|
+
.map((c) => this.parseSearchItem(c, client));
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
item: topResult,
|
|
109
|
+
more,
|
|
110
|
+
};
|
|
101
111
|
}
|
|
102
112
|
static parseSearchResult(shelfContents, client) {
|
|
103
113
|
const rawContents = shelfContents.filter((c) => "musicResponsiveListItemRenderer" in c);
|
|
@@ -6,7 +6,7 @@ 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;
|
|
9
|
+
var _a, _b, _c, _d, _e;
|
|
10
10
|
const videoInfo = BaseVideo_1.BaseVideoParser.parseRawData(data);
|
|
11
11
|
target.duration = +videoInfo.videoDetails.lengthSeconds;
|
|
12
12
|
const itemSectionRenderer = (_a = data.response.contents.twoColumnWatchNextResults.results.results.contents
|
|
@@ -20,6 +20,22 @@ class VideoParser {
|
|
|
20
20
|
start: c.timeRangeStartMillis,
|
|
21
21
|
thumbnails: new common_1.Thumbnails().load(c.thumbnail.thumbnails),
|
|
22
22
|
}))) || [];
|
|
23
|
+
const musicPanel = (_d = data.response.engagementPanels) === null || _d === void 0 ? void 0 : _d.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
|
+
if (!musicPanel) {
|
|
25
|
+
target.music = null;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const cards = musicPanel.engagementPanelSectionListRenderer.content.structuredDescriptionContentRenderer.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"; }).horizontalCardListRenderer.cards;
|
|
29
|
+
const music = cards.find((i) => i.videoAttributeViewModel)
|
|
30
|
+
.videoAttributeViewModel;
|
|
31
|
+
target.music = {
|
|
32
|
+
imageUrl: music.image.sources[0].url,
|
|
33
|
+
title: music.title,
|
|
34
|
+
artist: music.subtitle,
|
|
35
|
+
album: ((_e = music.secondarySubtitle) === null || _e === void 0 ? void 0 : _e.content) || null,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// target.music =
|
|
23
39
|
return target;
|
|
24
40
|
}
|
|
25
41
|
static parseComments(data, video) {
|
|
@@ -104,6 +104,7 @@ var MusicSearchResult = /** @class */ (function (_super) {
|
|
|
104
104
|
function MusicSearchResult(_a) {
|
|
105
105
|
var client = _a.client, type = _a.type;
|
|
106
106
|
var _this = _super.call(this, { client: client }) || this;
|
|
107
|
+
_this.top = null;
|
|
107
108
|
if (type)
|
|
108
109
|
_this.type = type;
|
|
109
110
|
return _this;
|
|
@@ -136,6 +137,7 @@ var MusicSearchResult = /** @class */ (function (_super) {
|
|
|
136
137
|
case 1:
|
|
137
138
|
response = _c.sent();
|
|
138
139
|
_a = MusicSearchResultParser.parseInitialSearchResult(response.data, this.client), data = _a.data, continuation = _a.continuation;
|
|
140
|
+
this.top = MusicSearchResultParser.parseTopResult(response.data, this.client) || null;
|
|
139
141
|
(_b = this.items).push.apply(_b, __spread(data));
|
|
140
142
|
this.continuation = continuation;
|
|
141
143
|
return [2 /*return*/, this];
|
|
@@ -40,20 +40,16 @@ var MusicSearchResultParser = /** @class */ (function () {
|
|
|
40
40
|
var _a, _b;
|
|
41
41
|
var sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
42
42
|
.sectionListRenderer.contents;
|
|
43
|
-
var topContent = sectionContents.find(function (c) { return "musicCardShelfRenderer" in c; });
|
|
44
43
|
var resultContents = sectionContents.find(function (c) { return "musicShelfRenderer" in c; });
|
|
45
|
-
var topResult = this.parseTopResult(topContent, client);
|
|
46
44
|
if (!resultContents) {
|
|
47
45
|
// no results
|
|
48
46
|
return {
|
|
49
|
-
data:
|
|
47
|
+
data: [],
|
|
50
48
|
continuation: undefined,
|
|
51
49
|
};
|
|
52
50
|
}
|
|
53
51
|
var _c = resultContents.musicShelfRenderer, contents = _c.contents, continuations = _c.continuations;
|
|
54
52
|
var result = MusicSearchResultParser.parseSearchResult(contents, client);
|
|
55
|
-
if (topResult)
|
|
56
|
-
result.unshift(topResult);
|
|
57
53
|
return {
|
|
58
54
|
data: result,
|
|
59
55
|
continuation: (_b = (_a = continuations === null || continuations === void 0 ? void 0 : continuations[0]) === null || _a === void 0 ? void 0 : _a.nextContinuationData) === null || _b === void 0 ? void 0 : _b.continuation,
|
|
@@ -67,9 +63,13 @@ var MusicSearchResultParser = /** @class */ (function () {
|
|
|
67
63
|
};
|
|
68
64
|
};
|
|
69
65
|
MusicSearchResultParser.parseTopResult = function (data, client) {
|
|
70
|
-
var
|
|
66
|
+
var _this = this;
|
|
67
|
+
var sectionContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
68
|
+
.sectionListRenderer.contents;
|
|
69
|
+
var topContent = sectionContents.find(function (c) { return "musicCardShelfRenderer" in c; });
|
|
70
|
+
var top = topContent === null || topContent === void 0 ? void 0 : topContent.musicCardShelfRenderer;
|
|
71
71
|
if (!top)
|
|
72
|
-
return;
|
|
72
|
+
return null;
|
|
73
73
|
var _a = top.title.runs[0].navigationEndpoint, browseEndpoint = _a.browseEndpoint, watchEndpoint = _a.watchEndpoint;
|
|
74
74
|
var id = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.videoId) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseId);
|
|
75
75
|
var type = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.watchEndpointMusicSupportedConfigs.watchEndpointMusicConfig.musicVideoType) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType);
|
|
@@ -123,7 +123,18 @@ var MusicSearchResultParser = /** @class */ (function () {
|
|
|
123
123
|
thumbnails: new Thumbnails().load(thumbnail),
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
if (!topResult)
|
|
127
|
+
return null;
|
|
128
|
+
var more = [];
|
|
129
|
+
if (top.contents) {
|
|
130
|
+
more = top.contents
|
|
131
|
+
.filter(function (c) { return c.musicResponsiveListItemRenderer; })
|
|
132
|
+
.map(function (c) { return _this.parseSearchItem(c, client); });
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
item: topResult,
|
|
136
|
+
more: more,
|
|
137
|
+
};
|
|
127
138
|
};
|
|
128
139
|
MusicSearchResultParser.parseSearchResult = function (shelfContents, client) {
|
|
129
140
|
var e_1, _a;
|
|
@@ -16,7 +16,7 @@ var VideoParser = /** @class */ (function () {
|
|
|
16
16
|
function VideoParser() {
|
|
17
17
|
}
|
|
18
18
|
VideoParser.loadVideo = function (target, data) {
|
|
19
|
-
var _a, _b, _c;
|
|
19
|
+
var _a, _b, _c, _d, _e;
|
|
20
20
|
var videoInfo = BaseVideoParser.parseRawData(data);
|
|
21
21
|
target.duration = +videoInfo.videoDetails.lengthSeconds;
|
|
22
22
|
var itemSectionRenderer = (_a = data.response.contents.twoColumnWatchNextResults.results.results.contents
|
|
@@ -33,6 +33,22 @@ var VideoParser = /** @class */ (function () {
|
|
|
33
33
|
thumbnails: new Thumbnails().load(c.thumbnail.thumbnails),
|
|
34
34
|
});
|
|
35
35
|
})) || [];
|
|
36
|
+
var musicPanel = (_d = data.response.engagementPanels) === null || _d === void 0 ? void 0 : _d.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
|
+
if (!musicPanel) {
|
|
38
|
+
target.music = null;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
var cards = musicPanel.engagementPanelSectionListRenderer.content.structuredDescriptionContentRenderer.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"; }).horizontalCardListRenderer.cards;
|
|
42
|
+
var music = cards.find(function (i) { return i.videoAttributeViewModel; })
|
|
43
|
+
.videoAttributeViewModel;
|
|
44
|
+
target.music = {
|
|
45
|
+
imageUrl: music.image.sources[0].url,
|
|
46
|
+
title: music.title,
|
|
47
|
+
artist: music.subtitle,
|
|
48
|
+
album: ((_e = music.secondarySubtitle) === null || _e === void 0 ? void 0 : _e.content) || null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// target.music =
|
|
36
52
|
return target;
|
|
37
53
|
};
|
|
38
54
|
VideoParser.parseComments = function (data, video) {
|
|
@@ -36,6 +36,10 @@ declare type MusicLyricsProperties = MusicContinuableConstructorParams & {
|
|
|
36
36
|
* @noInheritDoc
|
|
37
37
|
*/
|
|
38
38
|
export declare class MusicSearchResult<T extends MusicSearchType = undefined> extends MusicContinuable<MusicSearchResultItem<T>> {
|
|
39
|
+
top: {
|
|
40
|
+
item: MusicSearchResultItem;
|
|
41
|
+
more: MusicSearchResultItem[];
|
|
42
|
+
} | null;
|
|
39
43
|
private type;
|
|
40
44
|
/** @hidden */
|
|
41
45
|
constructor({ client, type }: MusicLyricsProperties);
|
|
@@ -10,7 +10,10 @@ declare type ParseReturnType = {
|
|
|
10
10
|
export declare class MusicSearchResultParser {
|
|
11
11
|
static parseInitialSearchResult(data: YoutubeRawData, client: MusicClient): ParseReturnType;
|
|
12
12
|
static parseContinuationSearchResult(data: YoutubeRawData, client: MusicClient): ParseReturnType;
|
|
13
|
-
|
|
13
|
+
static parseTopResult(data: YoutubeRawData, client: MusicClient): {
|
|
14
|
+
item: MusicSearchResultItem;
|
|
15
|
+
more: MusicSearchResultItem[];
|
|
16
|
+
} | null;
|
|
14
17
|
private static parseSearchResult;
|
|
15
18
|
private static parseSearchItem;
|
|
16
19
|
static parseVideoItem(item: YoutubeRawData, pageType: string, client: MusicClient): MusicSongCompact | MusicVideoCompact | undefined;
|
|
@@ -13,6 +13,12 @@ interface VideoProperties extends BaseVideoProperties {
|
|
|
13
13
|
comments?: VideoComments;
|
|
14
14
|
chapters?: Chapter[];
|
|
15
15
|
}
|
|
16
|
+
interface MusicMetadata {
|
|
17
|
+
imageUrl: string;
|
|
18
|
+
title: string;
|
|
19
|
+
artist: string;
|
|
20
|
+
album?: string;
|
|
21
|
+
}
|
|
16
22
|
/** Represents a Video, usually returned from `client.getVideo()` */
|
|
17
23
|
export declare class Video extends BaseVideo implements VideoProperties {
|
|
18
24
|
/** The duration of this video in second */
|
|
@@ -21,6 +27,8 @@ export declare class Video extends BaseVideo implements VideoProperties {
|
|
|
21
27
|
chapters: Chapter[];
|
|
22
28
|
/** {@link Continuable} of videos inside a {@link Video} */
|
|
23
29
|
comments: VideoComments;
|
|
30
|
+
/** Music metadata (if exists) */
|
|
31
|
+
music: MusicMetadata | null;
|
|
24
32
|
/** @hidden */
|
|
25
33
|
constructor(attr: VideoProperties);
|
|
26
34
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "youtubei",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.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",
|