youtubei 1.4.4 → 1.5.0
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/MusicClient/MusicClient.js +16 -0
- package/dist/cjs/music/MusicSearchResult/MusicAllSearchResultParser.js +105 -28
- package/dist/cjs/youtube/Client/Client.js +3 -2
- package/dist/esm/music/MusicClient/MusicClient.js +23 -0
- package/dist/esm/music/MusicSearchResult/MusicAllSearchResultParser.js +105 -28
- package/dist/esm/youtube/Client/Client.js +6 -5
- package/dist/typings/music/MusicClient/MusicClient.d.ts +14 -1
- package/dist/typings/music/MusicSearchResult/MusicAllSearchResultParser.d.ts +3 -2
- package/package.json +1 -1
|
@@ -35,6 +35,22 @@ class MusicClient {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Searches for all video, song, album, playlist, or artist
|
|
40
|
+
*
|
|
41
|
+
* @param query The search query
|
|
42
|
+
*/
|
|
43
|
+
searchAll(query) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const response = yield this.http.post(`${constants_1.I_END_POINT}/search`, {
|
|
46
|
+
data: { query },
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
top: MusicSearchResult_1.MusicAllSearchResultParser.parseTopResult(response.data, this),
|
|
50
|
+
shelves: MusicSearchResult_1.MusicAllSearchResultParser.parseSearchResult(response.data, this),
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
38
54
|
/**
|
|
39
55
|
* Get lyrics of a song
|
|
40
56
|
*
|
|
@@ -10,6 +10,75 @@ const MusicPlaylistCompact_1 = require("../MusicPlaylistCompact");
|
|
|
10
10
|
const MusicSongCompact_1 = require("../MusicSongCompact");
|
|
11
11
|
const MusicVideoCompact_1 = require("../MusicVideoCompact");
|
|
12
12
|
class MusicAllSearchResultParser {
|
|
13
|
+
static parseTopResult(data, client) {
|
|
14
|
+
var _a;
|
|
15
|
+
const sectionListContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
16
|
+
.sectionListRenderer.contents;
|
|
17
|
+
const top = (_a = sectionListContents.find((f) => f.musicCardShelfRenderer)) === null || _a === void 0 ? void 0 : _a.musicCardShelfRenderer;
|
|
18
|
+
if (!top)
|
|
19
|
+
return;
|
|
20
|
+
const { browseEndpoint, watchEndpoint } = top.title.runs[0].navigationEndpoint;
|
|
21
|
+
const id = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.videoId) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseId);
|
|
22
|
+
const type = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.watchEndpointMusicSupportedConfigs.watchEndpointMusicConfig.musicVideoType) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType);
|
|
23
|
+
const title = top.title.runs[0].text;
|
|
24
|
+
const thumbnail = top.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails;
|
|
25
|
+
let topResult;
|
|
26
|
+
if (type === "MUSIC_VIDEO_TYPE_ATV") {
|
|
27
|
+
topResult = new MusicSongCompact_1.MusicSongCompact({
|
|
28
|
+
client,
|
|
29
|
+
id,
|
|
30
|
+
title,
|
|
31
|
+
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
32
|
+
album: MusicAllSearchResultParser.parseAlbum(top.subtitle.runs, client),
|
|
33
|
+
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else if (type === "MUSIC_VIDEO_TYPE_UGC" || type === "MUSIC_VIDEO_TYPE_OMV") {
|
|
37
|
+
topResult = new MusicVideoCompact_1.MusicVideoCompact({
|
|
38
|
+
client,
|
|
39
|
+
id,
|
|
40
|
+
title,
|
|
41
|
+
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
42
|
+
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else if (type === "MUSIC_PAGE_TYPE_ALBUM") {
|
|
46
|
+
topResult = new MusicAlbumCompact_1.MusicAlbumCompact({
|
|
47
|
+
client,
|
|
48
|
+
id,
|
|
49
|
+
title,
|
|
50
|
+
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
51
|
+
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (type === "MUSIC_PAGE_TYPE_ARTIST") {
|
|
55
|
+
topResult = new MusicArtistCompact_1.MusicArtistCompact({
|
|
56
|
+
client,
|
|
57
|
+
id,
|
|
58
|
+
name: title,
|
|
59
|
+
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else if (type === "MUSIC_PAGE_TYPE_PLAYLIST") {
|
|
63
|
+
topResult = new MusicPlaylistCompact_1.MusicPlaylistCompact({
|
|
64
|
+
client,
|
|
65
|
+
id,
|
|
66
|
+
title,
|
|
67
|
+
channel: MusicAllSearchResultParser.parseChannel(top.subtitle.run, client),
|
|
68
|
+
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
let more;
|
|
72
|
+
if (top.contents) {
|
|
73
|
+
more = top.contents
|
|
74
|
+
.filter((c) => c.musicResponsiveListItemRenderer)
|
|
75
|
+
.map((c) => MusicAllSearchResultParser.parseSearchItem(c, client));
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
item: topResult,
|
|
79
|
+
more,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
13
82
|
static parseSearchResult(data, client) {
|
|
14
83
|
const sectionListContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
15
84
|
.sectionListRenderer.contents;
|
|
@@ -50,28 +119,17 @@ class MusicAllSearchResultParser {
|
|
|
50
119
|
const thumbnails = new common_1.Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
51
120
|
const artists = MusicAllSearchResultParser.parseArtists(bottomColumn, client);
|
|
52
121
|
if (pageType === "MUSIC_VIDEO_TYPE_ATV") {
|
|
53
|
-
const rawAlbum = bottomColumn.find((r) => {
|
|
54
|
-
var _a;
|
|
55
|
-
return ((_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType) === "MUSIC_PAGE_TYPE_ALBUM";
|
|
56
|
-
});
|
|
57
|
-
const album = rawAlbum
|
|
58
|
-
? new MusicAlbumCompact_1.MusicAlbumCompact({
|
|
59
|
-
client,
|
|
60
|
-
id: rawAlbum.navigationEndpoint.browseEndpoint.browseId,
|
|
61
|
-
title: rawAlbum.text,
|
|
62
|
-
})
|
|
63
|
-
: undefined;
|
|
64
122
|
return new MusicSongCompact_1.MusicSongCompact({
|
|
65
123
|
client,
|
|
66
124
|
id,
|
|
67
|
-
album,
|
|
125
|
+
album: MusicAllSearchResultParser.parseAlbum(bottomColumn, client),
|
|
68
126
|
title,
|
|
69
127
|
artists,
|
|
70
128
|
thumbnails,
|
|
71
129
|
duration,
|
|
72
130
|
});
|
|
73
131
|
}
|
|
74
|
-
else if (pageType === "MUSIC_VIDEO_TYPE_UGC") {
|
|
132
|
+
else if (pageType === "MUSIC_VIDEO_TYPE_UGC" || pageType === "MUSIC_VIDEO_TYPE_OMV") {
|
|
75
133
|
return new MusicVideoCompact_1.MusicVideoCompact({ client, id, title, artists, thumbnails, duration });
|
|
76
134
|
}
|
|
77
135
|
}
|
|
@@ -102,34 +160,53 @@ class MusicAllSearchResultParser {
|
|
|
102
160
|
const thumbnails = new common_1.Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
103
161
|
return new MusicArtistCompact_1.MusicArtistCompact({ client, id, name, thumbnails });
|
|
104
162
|
}
|
|
105
|
-
static
|
|
106
|
-
|
|
163
|
+
static parseAlbum(items, client) {
|
|
164
|
+
var _a;
|
|
165
|
+
const albumRaw = items.find((r) => {
|
|
107
166
|
var _a;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
167
|
+
const pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
168
|
+
return pageType === "MUSIC_PAGE_TYPE_ALBUM";
|
|
169
|
+
});
|
|
170
|
+
if (!albumRaw)
|
|
171
|
+
return;
|
|
172
|
+
const album = new MusicAlbumCompact_1.MusicAlbumCompact({
|
|
173
|
+
client,
|
|
174
|
+
title: albumRaw.text,
|
|
175
|
+
id: (_a = albumRaw.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
113
176
|
});
|
|
177
|
+
return album;
|
|
114
178
|
}
|
|
115
|
-
static
|
|
116
|
-
|
|
179
|
+
static parseArtists(items, client) {
|
|
180
|
+
return items
|
|
181
|
+
.filter((r) => {
|
|
182
|
+
var _a;
|
|
183
|
+
const pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
184
|
+
return pageType === "MUSIC_PAGE_TYPE_ARTIST";
|
|
185
|
+
})
|
|
186
|
+
.map((r) => {
|
|
117
187
|
var _a;
|
|
118
|
-
return new
|
|
188
|
+
return new MusicBaseArtist_1.MusicBaseArtist({
|
|
119
189
|
client,
|
|
120
190
|
name: r.text,
|
|
121
191
|
id: (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
122
192
|
});
|
|
123
193
|
});
|
|
124
|
-
return channel;
|
|
125
194
|
}
|
|
126
|
-
static
|
|
127
|
-
|
|
195
|
+
static parseChannel(items, client) {
|
|
196
|
+
var _a;
|
|
197
|
+
const channelRaw = items.find((r) => {
|
|
128
198
|
var _a;
|
|
129
199
|
const pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
130
|
-
return
|
|
200
|
+
return pageType === "MUSIC_PAGE_TYPE_USER_CHANNEL";
|
|
201
|
+
});
|
|
202
|
+
if (!channelRaw)
|
|
203
|
+
return;
|
|
204
|
+
const channel = new MusicBaseChannel_1.MusicBaseChannel({
|
|
205
|
+
client,
|
|
206
|
+
name: channelRaw.text,
|
|
207
|
+
id: (_a = channelRaw.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
131
208
|
});
|
|
132
|
-
return
|
|
209
|
+
return channel;
|
|
133
210
|
}
|
|
134
211
|
}
|
|
135
212
|
exports.MusicAllSearchResultParser = MusicAllSearchResultParser;
|
|
@@ -73,7 +73,7 @@ class Client {
|
|
|
73
73
|
}
|
|
74
74
|
/** Get video information by video id or URL */
|
|
75
75
|
getVideo(videoId) {
|
|
76
|
-
var _a;
|
|
76
|
+
var _a, _b;
|
|
77
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
78
|
const response = yield this.http.get(`${constants_1.WATCH_END_POINT}`, {
|
|
79
79
|
params: { v: videoId, pbj: "1" },
|
|
@@ -81,7 +81,8 @@ class Client {
|
|
|
81
81
|
const data = Array.isArray(response.data)
|
|
82
82
|
? response.data.reduce((prev, curr) => (Object.assign(Object.assign({}, prev), curr)), {})
|
|
83
83
|
: response.data;
|
|
84
|
-
if (!((_a = data.response) === null || _a === void 0 ? void 0 : _a.contents) ||
|
|
84
|
+
if (!((_b = (_a = data.response) === null || _a === void 0 ? void 0 : _a.contents) === null || _b === void 0 ? void 0 : _b.twoColumnWatchNextResults.results.results.contents) ||
|
|
85
|
+
data.playerResponse.playabilityStatus.status === "ERROR") {
|
|
85
86
|
return undefined;
|
|
86
87
|
}
|
|
87
88
|
return (!data.playerResponse.playabilityStatus.liveStreamability
|
|
@@ -79,6 +79,29 @@ var MusicClient = /** @class */ (function () {
|
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* Searches for all video, song, album, playlist, or artist
|
|
84
|
+
*
|
|
85
|
+
* @param query The search query
|
|
86
|
+
*/
|
|
87
|
+
MusicClient.prototype.searchAll = function (query) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
+
var response;
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0: return [4 /*yield*/, this.http.post(I_END_POINT + "/search", {
|
|
93
|
+
data: { query: query },
|
|
94
|
+
})];
|
|
95
|
+
case 1:
|
|
96
|
+
response = _a.sent();
|
|
97
|
+
return [2 /*return*/, {
|
|
98
|
+
top: MusicAllSearchResultParser.parseTopResult(response.data, this),
|
|
99
|
+
shelves: MusicAllSearchResultParser.parseSearchResult(response.data, this),
|
|
100
|
+
}];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
};
|
|
82
105
|
/**
|
|
83
106
|
* Get lyrics of a song
|
|
84
107
|
*
|
|
@@ -25,6 +25,75 @@ import { MusicVideoCompact } from "../MusicVideoCompact";
|
|
|
25
25
|
var MusicAllSearchResultParser = /** @class */ (function () {
|
|
26
26
|
function MusicAllSearchResultParser() {
|
|
27
27
|
}
|
|
28
|
+
MusicAllSearchResultParser.parseTopResult = function (data, client) {
|
|
29
|
+
var _a;
|
|
30
|
+
var sectionListContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
31
|
+
.sectionListRenderer.contents;
|
|
32
|
+
var top = (_a = sectionListContents.find(function (f) { return f.musicCardShelfRenderer; })) === null || _a === void 0 ? void 0 : _a.musicCardShelfRenderer;
|
|
33
|
+
if (!top)
|
|
34
|
+
return;
|
|
35
|
+
var _b = top.title.runs[0].navigationEndpoint, browseEndpoint = _b.browseEndpoint, watchEndpoint = _b.watchEndpoint;
|
|
36
|
+
var id = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.videoId) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseId);
|
|
37
|
+
var type = (watchEndpoint === null || watchEndpoint === void 0 ? void 0 : watchEndpoint.watchEndpointMusicSupportedConfigs.watchEndpointMusicConfig.musicVideoType) || (browseEndpoint === null || browseEndpoint === void 0 ? void 0 : browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType);
|
|
38
|
+
var title = top.title.runs[0].text;
|
|
39
|
+
var thumbnail = top.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails;
|
|
40
|
+
var topResult;
|
|
41
|
+
if (type === "MUSIC_VIDEO_TYPE_ATV") {
|
|
42
|
+
topResult = new MusicSongCompact({
|
|
43
|
+
client: client,
|
|
44
|
+
id: id,
|
|
45
|
+
title: title,
|
|
46
|
+
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
47
|
+
album: MusicAllSearchResultParser.parseAlbum(top.subtitle.runs, client),
|
|
48
|
+
thumbnails: new Thumbnails().load(thumbnail),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (type === "MUSIC_VIDEO_TYPE_UGC" || type === "MUSIC_VIDEO_TYPE_OMV") {
|
|
52
|
+
topResult = new MusicVideoCompact({
|
|
53
|
+
client: client,
|
|
54
|
+
id: id,
|
|
55
|
+
title: title,
|
|
56
|
+
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
57
|
+
thumbnails: new Thumbnails().load(thumbnail),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else if (type === "MUSIC_PAGE_TYPE_ALBUM") {
|
|
61
|
+
topResult = new MusicAlbumCompact({
|
|
62
|
+
client: client,
|
|
63
|
+
id: id,
|
|
64
|
+
title: title,
|
|
65
|
+
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
66
|
+
thumbnails: new Thumbnails().load(thumbnail),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else if (type === "MUSIC_PAGE_TYPE_ARTIST") {
|
|
70
|
+
topResult = new MusicArtistCompact({
|
|
71
|
+
client: client,
|
|
72
|
+
id: id,
|
|
73
|
+
name: title,
|
|
74
|
+
thumbnails: new Thumbnails().load(thumbnail),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (type === "MUSIC_PAGE_TYPE_PLAYLIST") {
|
|
78
|
+
topResult = new MusicPlaylistCompact({
|
|
79
|
+
client: client,
|
|
80
|
+
id: id,
|
|
81
|
+
title: title,
|
|
82
|
+
channel: MusicAllSearchResultParser.parseChannel(top.subtitle.run, client),
|
|
83
|
+
thumbnails: new Thumbnails().load(thumbnail),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
var more;
|
|
87
|
+
if (top.contents) {
|
|
88
|
+
more = top.contents
|
|
89
|
+
.filter(function (c) { return c.musicResponsiveListItemRenderer; })
|
|
90
|
+
.map(function (c) { return MusicAllSearchResultParser.parseSearchItem(c, client); });
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
item: topResult,
|
|
94
|
+
more: more,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
28
97
|
MusicAllSearchResultParser.parseSearchResult = function (data, client) {
|
|
29
98
|
var sectionListContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
30
99
|
.sectionListRenderer.contents;
|
|
@@ -67,28 +136,17 @@ var MusicAllSearchResultParser = /** @class */ (function () {
|
|
|
67
136
|
var thumbnails = new Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
68
137
|
var artists = MusicAllSearchResultParser.parseArtists(bottomColumn, client);
|
|
69
138
|
if (pageType === "MUSIC_VIDEO_TYPE_ATV") {
|
|
70
|
-
var rawAlbum = bottomColumn.find(function (r) {
|
|
71
|
-
var _a;
|
|
72
|
-
return ((_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType) === "MUSIC_PAGE_TYPE_ALBUM";
|
|
73
|
-
});
|
|
74
|
-
var album = rawAlbum
|
|
75
|
-
? new MusicAlbumCompact({
|
|
76
|
-
client: client,
|
|
77
|
-
id: rawAlbum.navigationEndpoint.browseEndpoint.browseId,
|
|
78
|
-
title: rawAlbum.text,
|
|
79
|
-
})
|
|
80
|
-
: undefined;
|
|
81
139
|
return new MusicSongCompact({
|
|
82
140
|
client: client,
|
|
83
141
|
id: id,
|
|
84
|
-
album:
|
|
142
|
+
album: MusicAllSearchResultParser.parseAlbum(bottomColumn, client),
|
|
85
143
|
title: title,
|
|
86
144
|
artists: artists,
|
|
87
145
|
thumbnails: thumbnails,
|
|
88
146
|
duration: duration,
|
|
89
147
|
});
|
|
90
148
|
}
|
|
91
|
-
else if (pageType === "MUSIC_VIDEO_TYPE_UGC") {
|
|
149
|
+
else if (pageType === "MUSIC_VIDEO_TYPE_UGC" || pageType === "MUSIC_VIDEO_TYPE_OMV") {
|
|
92
150
|
return new MusicVideoCompact({ client: client, id: id, title: title, artists: artists, thumbnails: thumbnails, duration: duration });
|
|
93
151
|
}
|
|
94
152
|
};
|
|
@@ -119,8 +177,30 @@ var MusicAllSearchResultParser = /** @class */ (function () {
|
|
|
119
177
|
var thumbnails = new Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
120
178
|
return new MusicArtistCompact({ client: client, id: id, name: name, thumbnails: thumbnails });
|
|
121
179
|
};
|
|
180
|
+
MusicAllSearchResultParser.parseAlbum = function (items, client) {
|
|
181
|
+
var _a;
|
|
182
|
+
var albumRaw = items.find(function (r) {
|
|
183
|
+
var _a;
|
|
184
|
+
var pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
185
|
+
return pageType === "MUSIC_PAGE_TYPE_ALBUM";
|
|
186
|
+
});
|
|
187
|
+
if (!albumRaw)
|
|
188
|
+
return;
|
|
189
|
+
var album = new MusicAlbumCompact({
|
|
190
|
+
client: client,
|
|
191
|
+
title: albumRaw.text,
|
|
192
|
+
id: (_a = albumRaw.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
193
|
+
});
|
|
194
|
+
return album;
|
|
195
|
+
};
|
|
122
196
|
MusicAllSearchResultParser.parseArtists = function (items, client) {
|
|
123
|
-
return
|
|
197
|
+
return items
|
|
198
|
+
.filter(function (r) {
|
|
199
|
+
var _a;
|
|
200
|
+
var pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
201
|
+
return pageType === "MUSIC_PAGE_TYPE_ARTIST";
|
|
202
|
+
})
|
|
203
|
+
.map(function (r) {
|
|
124
204
|
var _a;
|
|
125
205
|
return new MusicBaseArtist({
|
|
126
206
|
client: client,
|
|
@@ -130,23 +210,20 @@ var MusicAllSearchResultParser = /** @class */ (function () {
|
|
|
130
210
|
});
|
|
131
211
|
};
|
|
132
212
|
MusicAllSearchResultParser.parseChannel = function (items, client) {
|
|
133
|
-
var _a
|
|
134
|
-
|
|
135
|
-
return new MusicBaseChannel({
|
|
136
|
-
client: client,
|
|
137
|
-
name: r.text,
|
|
138
|
-
id: (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
139
|
-
});
|
|
140
|
-
}), 1), channel = _a[0];
|
|
141
|
-
return channel;
|
|
142
|
-
};
|
|
143
|
-
MusicAllSearchResultParser.parseArtistOrChannel = function (items) {
|
|
144
|
-
var contents = items.filter(function (r) {
|
|
213
|
+
var _a;
|
|
214
|
+
var channelRaw = items.find(function (r) {
|
|
145
215
|
var _a;
|
|
146
216
|
var pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
147
|
-
return
|
|
217
|
+
return pageType === "MUSIC_PAGE_TYPE_USER_CHANNEL";
|
|
218
|
+
});
|
|
219
|
+
if (!channelRaw)
|
|
220
|
+
return;
|
|
221
|
+
var channel = new MusicBaseChannel({
|
|
222
|
+
client: client,
|
|
223
|
+
name: channelRaw.text,
|
|
224
|
+
id: (_a = channelRaw.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
148
225
|
});
|
|
149
|
-
return
|
|
226
|
+
return channel;
|
|
150
227
|
};
|
|
151
228
|
return MusicAllSearchResultParser;
|
|
152
229
|
}());
|
|
@@ -133,20 +133,21 @@ var Client = /** @class */ (function () {
|
|
|
133
133
|
};
|
|
134
134
|
/** Get video information by video id or URL */
|
|
135
135
|
Client.prototype.getVideo = function (videoId) {
|
|
136
|
-
var _a;
|
|
136
|
+
var _a, _b;
|
|
137
137
|
return __awaiter(this, void 0, void 0, function () {
|
|
138
138
|
var response, data;
|
|
139
|
-
return __generator(this, function (
|
|
140
|
-
switch (
|
|
139
|
+
return __generator(this, function (_c) {
|
|
140
|
+
switch (_c.label) {
|
|
141
141
|
case 0: return [4 /*yield*/, this.http.get("" + WATCH_END_POINT, {
|
|
142
142
|
params: { v: videoId, pbj: "1" },
|
|
143
143
|
})];
|
|
144
144
|
case 1:
|
|
145
|
-
response =
|
|
145
|
+
response = _c.sent();
|
|
146
146
|
data = Array.isArray(response.data)
|
|
147
147
|
? response.data.reduce(function (prev, curr) { return (__assign(__assign({}, prev), curr)); }, {})
|
|
148
148
|
: response.data;
|
|
149
|
-
if (!((_a = data.response) === null || _a === void 0 ? void 0 : _a.contents) ||
|
|
149
|
+
if (!((_b = (_a = data.response) === null || _a === void 0 ? void 0 : _a.contents) === null || _b === void 0 ? void 0 : _b.twoColumnWatchNextResults.results.results.contents) ||
|
|
150
|
+
data.playerResponse.playabilityStatus.status === "ERROR") {
|
|
150
151
|
return [2 /*return*/, undefined];
|
|
151
152
|
}
|
|
152
153
|
return [2 /*return*/, (!data.playerResponse.playabilityStatus.liveStreamability
|
|
@@ -6,6 +6,10 @@ import { MusicLyrics } from "../MusicLyrics";
|
|
|
6
6
|
import { MusicPlaylistCompact } from "../MusicPlaylistCompact";
|
|
7
7
|
import { MusicSearchResult, MusicSearchType } from "../MusicSearchResult";
|
|
8
8
|
import { MusicVideoCompact } from "../MusicVideoCompact";
|
|
9
|
+
export declare type MusicTopShelf = {
|
|
10
|
+
item: MusicVideoCompact | MusicAlbumCompact | MusicPlaylistCompact | MusicArtistCompact;
|
|
11
|
+
more?: (MusicVideoCompact | MusicAlbumCompact | MusicPlaylistCompact | MusicArtistCompact)[];
|
|
12
|
+
};
|
|
9
13
|
export declare type MusicClientOptions = {
|
|
10
14
|
initialCookie: string;
|
|
11
15
|
/** Optional options for http client */
|
|
@@ -22,11 +26,20 @@ export declare class MusicClient {
|
|
|
22
26
|
* Searches for video, song, album, playlist, or artist
|
|
23
27
|
*
|
|
24
28
|
* @param query The search query
|
|
25
|
-
* @param
|
|
29
|
+
* @param type Search type
|
|
26
30
|
*
|
|
27
31
|
*/
|
|
28
32
|
search(query: string): Promise<Shelf<MusicVideoCompact[] | MusicAlbumCompact[] | MusicPlaylistCompact[] | MusicArtistCompact[]>[]>;
|
|
29
33
|
search<T extends MusicSearchType>(query: string, type: T): Promise<MusicSearchResult<T>>;
|
|
34
|
+
/**
|
|
35
|
+
* Searches for all video, song, album, playlist, or artist
|
|
36
|
+
*
|
|
37
|
+
* @param query The search query
|
|
38
|
+
*/
|
|
39
|
+
searchAll(query: string): Promise<{
|
|
40
|
+
top?: MusicTopShelf;
|
|
41
|
+
shelves: Shelf<MusicVideoCompact[] | MusicAlbumCompact[] | MusicPlaylistCompact[] | MusicArtistCompact[]>[];
|
|
42
|
+
}>;
|
|
30
43
|
/**
|
|
31
44
|
* Get lyrics of a song
|
|
32
45
|
*
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { Shelf, YoutubeRawData } from "../../common";
|
|
2
2
|
import { MusicAlbumCompact } from "../MusicAlbumCompact";
|
|
3
|
-
import { MusicClient } from "../MusicClient";
|
|
3
|
+
import { MusicClient, MusicTopShelf } from "../MusicClient";
|
|
4
4
|
import { MusicPlaylistCompact } from "../MusicPlaylistCompact";
|
|
5
5
|
import { MusicSongCompact } from "../MusicSongCompact";
|
|
6
6
|
import { MusicVideoCompact } from "../MusicVideoCompact";
|
|
7
7
|
export declare class MusicAllSearchResultParser {
|
|
8
|
+
static parseTopResult(data: YoutubeRawData, client: MusicClient): MusicTopShelf | undefined;
|
|
8
9
|
static parseSearchResult(data: YoutubeRawData, client: MusicClient): Shelf<MusicVideoCompact[] | MusicAlbumCompact[] | MusicPlaylistCompact[]>[];
|
|
9
10
|
private static parseSearchItem;
|
|
10
11
|
static parseVideoItem(item: YoutubeRawData, pageType: string, client: MusicClient): MusicSongCompact | MusicVideoCompact | undefined;
|
|
11
12
|
private static parsePlaylistItem;
|
|
12
13
|
private static parseAlbumItem;
|
|
13
14
|
private static parseArtistItem;
|
|
15
|
+
private static parseAlbum;
|
|
14
16
|
private static parseArtists;
|
|
15
17
|
private static parseChannel;
|
|
16
|
-
private static parseArtistOrChannel;
|
|
17
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "youtubei",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
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",
|