youtubei 1.7.0 → 1.8.1
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 +13 -18
- package/dist/cjs/music/MusicSearchResult/MusicSearchResult.js +8 -4
- package/dist/cjs/music/MusicSearchResult/MusicSearchResultParser.js +214 -13
- package/dist/cjs/music/MusicSearchResult/index.js +0 -1
- package/dist/cjs/youtube/BaseChannel/BaseChannel.js +2 -0
- package/dist/cjs/youtube/BaseChannel/BaseChannelParser.js +3 -2
- package/dist/cjs/youtube/BaseChannel/ChannelPlaylists.js +12 -2
- package/dist/cjs/youtube/BaseChannel/ChannelPosts.js +59 -0
- package/dist/cjs/youtube/BaseVideo/BaseVideoParser.js +1 -1
- package/dist/cjs/youtube/Channel/ChannelParser.js +10 -6
- package/dist/cjs/youtube/PlaylistCompact/PlaylistCompactParser.js +3 -3
- package/dist/cjs/youtube/Post/Post.js +23 -0
- package/dist/cjs/youtube/Post/PostParser.js +23 -0
- package/dist/cjs/youtube/Post/index.js +14 -0
- package/dist/esm/music/MusicClient/MusicClient.js +16 -20
- package/dist/esm/music/MusicSearchResult/MusicSearchResult.js +7 -4
- package/dist/esm/music/MusicSearchResult/MusicSearchResultParser.js +231 -13
- package/dist/esm/music/MusicSearchResult/index.js +0 -1
- package/dist/esm/youtube/BaseChannel/BaseChannel.js +2 -0
- package/dist/esm/youtube/BaseChannel/BaseChannelParser.js +3 -2
- package/dist/esm/youtube/BaseChannel/ChannelPlaylists.js +11 -3
- package/dist/esm/youtube/BaseChannel/ChannelPosts.js +111 -0
- package/dist/esm/youtube/BaseVideo/BaseVideoParser.js +1 -1
- package/dist/esm/youtube/Channel/ChannelParser.js +12 -8
- package/dist/esm/youtube/PlaylistCompact/PlaylistCompactParser.js +3 -3
- package/dist/esm/youtube/Post/Post.js +36 -0
- package/dist/esm/youtube/Post/PostParser.js +23 -0
- package/dist/esm/youtube/Post/index.js +2 -0
- package/dist/typings/music/MusicClient/MusicClient.d.ts +3 -7
- package/dist/typings/music/MusicSearchResult/MusicSearchResult.d.ts +11 -4
- package/dist/typings/music/MusicSearchResult/MusicSearchResultParser.d.ts +18 -3
- package/dist/typings/music/MusicSearchResult/index.d.ts +0 -1
- package/dist/typings/youtube/BaseChannel/BaseChannel.d.ts +4 -1
- package/dist/typings/youtube/BaseChannel/BaseChannelParser.d.ts +1 -0
- package/dist/typings/youtube/BaseChannel/ChannelPosts.d.ts +30 -0
- package/dist/typings/youtube/Post/Post.d.ts +32 -0
- package/dist/typings/youtube/Post/PostParser.d.ts +5 -0
- package/dist/typings/youtube/Post/index.d.ts +2 -0
- package/package.json +1 -1
- package/dist/cjs/music/MusicSearchResult/MusicAllSearchResultParser.js +0 -218
- package/dist/esm/music/MusicSearchResult/MusicAllSearchResultParser.js +0 -234
- package/dist/typings/music/MusicSearchResult/MusicAllSearchResultParser.d.ts +0 -19
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { Base } from "../Base";
|
|
15
|
+
import { PostParser } from "./PostParser";
|
|
16
|
+
/** Represents a chat in a live stream */
|
|
17
|
+
var Post = /** @class */ (function (_super) {
|
|
18
|
+
__extends(Post, _super);
|
|
19
|
+
/** @hidden */
|
|
20
|
+
function Post(attr) {
|
|
21
|
+
var _this = _super.call(this, attr.client) || this;
|
|
22
|
+
Object.assign(_this, attr);
|
|
23
|
+
return _this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Load this instance with raw data from Youtube
|
|
27
|
+
*
|
|
28
|
+
* @hidden
|
|
29
|
+
*/
|
|
30
|
+
Post.prototype.load = function (data) {
|
|
31
|
+
PostParser.loadPost(this, data);
|
|
32
|
+
return this;
|
|
33
|
+
};
|
|
34
|
+
return Post;
|
|
35
|
+
}(Base));
|
|
36
|
+
export { Post };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseChannel } from "../BaseChannel";
|
|
2
|
+
var PostParser = /** @class */ (function () {
|
|
3
|
+
function PostParser() {
|
|
4
|
+
}
|
|
5
|
+
PostParser.loadPost = function (target, data) {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
var postId = data.postId, authorText = data.authorText, authorThumbnail = data.authorThumbnail, authorEndpoint = data.authorEndpoint, contentText = data.contentText, publishedTimeText = data.publishedTimeText, voteCount = data.voteCount;
|
|
8
|
+
// Basic information
|
|
9
|
+
target.id = postId;
|
|
10
|
+
target.content = (_a = contentText === null || contentText === void 0 ? void 0 : contentText.runs) === null || _a === void 0 ? void 0 : _a.map(function (r) { return r.text; }).join("");
|
|
11
|
+
target.channel = new BaseChannel({
|
|
12
|
+
id: (_b = authorEndpoint === null || authorEndpoint === void 0 ? void 0 : authorEndpoint.browseEndpoint) === null || _b === void 0 ? void 0 : _b.browseId,
|
|
13
|
+
name: (_c = authorText.runs) === null || _c === void 0 ? void 0 : _c[0].text,
|
|
14
|
+
thumbnails: authorThumbnail.thumbnails,
|
|
15
|
+
client: target.client,
|
|
16
|
+
});
|
|
17
|
+
target.timestamp = (_d = publishedTimeText.runs[0]) === null || _d === void 0 ? void 0 : _d.text;
|
|
18
|
+
target.voteCount = voteCount.simpleText;
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
return PostParser;
|
|
22
|
+
}());
|
|
23
|
+
export { PostParser };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HTTP, HTTPOptions
|
|
1
|
+
import { HTTP, HTTPOptions } from "../../common";
|
|
2
2
|
import { MusicAlbumCompact } from "../MusicAlbumCompact";
|
|
3
3
|
import { MusicArtistCompact } from "../MusicArtistCompact";
|
|
4
4
|
import { MusicLyrics } from "../MusicLyrics";
|
|
@@ -22,17 +22,13 @@ export declare class MusicClient {
|
|
|
22
22
|
* @param type Search type
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
|
-
search(query: string): Promise<
|
|
26
|
-
search<T extends MusicSearchType>(query: string, type: T): Promise<MusicSearchResult<T>>;
|
|
25
|
+
search<T extends MusicSearchType>(query: string, type?: T): Promise<MusicSearchResult<T>>;
|
|
27
26
|
/**
|
|
28
27
|
* Searches for all video, song, album, playlist, or artist
|
|
29
28
|
*
|
|
30
29
|
* @param query The search query
|
|
31
30
|
*/
|
|
32
|
-
searchAll(query: string): Promise<
|
|
33
|
-
top?: MusicTopShelf;
|
|
34
|
-
shelves: Shelf<MusicVideoCompact[] | MusicAlbumCompact[] | MusicPlaylistCompact[] | MusicArtistCompact[]>[];
|
|
35
|
-
}>;
|
|
31
|
+
searchAll(query: string): Promise<MusicSearchResult>;
|
|
36
32
|
/**
|
|
37
33
|
* Get lyrics of a song
|
|
38
34
|
*
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { MusicAlbumCompact } from "../MusicAlbumCompact";
|
|
2
|
+
import { MusicArtistCompact } from "../MusicArtistCompact";
|
|
1
3
|
import { FetchResult, MusicContinuable, MusicContinuableConstructorParams } from "../MusicContinuable";
|
|
4
|
+
import { MusicPlaylistCompact } from "../MusicPlaylistCompact";
|
|
2
5
|
import { MusicSongCompact } from "../MusicSongCompact";
|
|
3
6
|
import { MusicVideoCompact } from "../MusicVideoCompact";
|
|
4
7
|
export declare enum MusicSearchTypeEnum {
|
|
5
8
|
Song = "song",
|
|
6
9
|
Video = "video"
|
|
7
10
|
}
|
|
8
|
-
export declare type MusicSearchType = "song" | "video" | MusicSearchTypeEnum;
|
|
9
|
-
export declare type MusicSearchResultItem<T =
|
|
11
|
+
export declare type MusicSearchType = "song" | "video" | MusicSearchTypeEnum | undefined;
|
|
12
|
+
export declare type MusicSearchResultItem<T = undefined> = T extends "song" ? MusicSongCompact : T extends "video" ? MusicVideoCompact : MusicVideoCompact | MusicAlbumCompact | MusicPlaylistCompact | MusicArtistCompact;
|
|
10
13
|
declare type MusicLyricsProperties = MusicContinuableConstructorParams & {
|
|
11
14
|
type?: MusicSearchType;
|
|
12
15
|
};
|
|
@@ -32,7 +35,11 @@ declare type MusicLyricsProperties = MusicContinuableConstructorParams & {
|
|
|
32
35
|
*
|
|
33
36
|
* @noInheritDoc
|
|
34
37
|
*/
|
|
35
|
-
export declare class MusicSearchResult<T extends MusicSearchType
|
|
38
|
+
export declare class MusicSearchResult<T extends MusicSearchType = undefined> extends MusicContinuable<MusicSearchResultItem<T>> {
|
|
39
|
+
top: {
|
|
40
|
+
item: MusicSearchResultItem;
|
|
41
|
+
more: MusicSearchResultItem[];
|
|
42
|
+
} | null;
|
|
36
43
|
private type;
|
|
37
44
|
/** @hidden */
|
|
38
45
|
constructor({ client, type }: MusicLyricsProperties);
|
|
@@ -44,7 +51,7 @@ export declare class MusicSearchResult<T extends MusicSearchType | undefined = "
|
|
|
44
51
|
*
|
|
45
52
|
* @hidden
|
|
46
53
|
*/
|
|
47
|
-
search(query: string, type
|
|
54
|
+
search(query: string, type?: MusicSearchType): Promise<MusicSearchResult<T>>;
|
|
48
55
|
protected fetch(): Promise<FetchResult<MusicSearchResultItem<T>>>;
|
|
49
56
|
}
|
|
50
57
|
export {};
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { YoutubeRawData } from "../../common";
|
|
2
2
|
import { MusicClient } from "../MusicClient";
|
|
3
|
-
import {
|
|
3
|
+
import { MusicSongCompact } from "../MusicSongCompact";
|
|
4
|
+
import { MusicVideoCompact } from "../MusicVideoCompact";
|
|
5
|
+
import { MusicSearchResultItem } from "./MusicSearchResult";
|
|
4
6
|
declare type ParseReturnType = {
|
|
5
7
|
data: MusicSearchResultItem[];
|
|
6
8
|
continuation: string | undefined;
|
|
7
9
|
};
|
|
8
10
|
export declare class MusicSearchResultParser {
|
|
9
|
-
static parseInitialSearchResult(data: YoutubeRawData,
|
|
10
|
-
static parseContinuationSearchResult(data: YoutubeRawData,
|
|
11
|
+
static parseInitialSearchResult(data: YoutubeRawData, client: MusicClient): ParseReturnType;
|
|
12
|
+
static parseContinuationSearchResult(data: YoutubeRawData, client: MusicClient): ParseReturnType;
|
|
13
|
+
static parseTopResult(data: YoutubeRawData, client: MusicClient): {
|
|
14
|
+
item: MusicSearchResultItem;
|
|
15
|
+
more: MusicSearchResultItem[];
|
|
16
|
+
} | null;
|
|
11
17
|
private static parseSearchResult;
|
|
18
|
+
private static parseSearchItem;
|
|
19
|
+
static parseVideoItem(item: YoutubeRawData, pageType: string, client: MusicClient): MusicSongCompact | MusicVideoCompact | undefined;
|
|
20
|
+
private static parsePlaylistItem;
|
|
21
|
+
private static parseAlbumItem;
|
|
22
|
+
private static parseArtistItem;
|
|
23
|
+
private static parseAlbum;
|
|
24
|
+
private static parseArtists;
|
|
25
|
+
private static parseChannel;
|
|
26
|
+
private static parseArtistsOrChannel;
|
|
12
27
|
}
|
|
13
28
|
export {};
|
|
@@ -2,6 +2,7 @@ import { Thumbnails, YoutubeRawData } from "../../common";
|
|
|
2
2
|
import { Base, BaseProperties } from "../Base";
|
|
3
3
|
import { ChannelLive } from "./ChannelLive";
|
|
4
4
|
import { ChannelPlaylists } from "./ChannelPlaylists";
|
|
5
|
+
import { ChannelPosts } from "./ChannelPosts";
|
|
5
6
|
import { ChannelShorts } from "./ChannelShorts";
|
|
6
7
|
import { ChannelVideos } from "./ChannelVideos";
|
|
7
8
|
/** @hidden */
|
|
@@ -17,7 +18,7 @@ export declare class BaseChannel extends Base implements BaseChannelProperties {
|
|
|
17
18
|
/** The channel's name */
|
|
18
19
|
name: string;
|
|
19
20
|
/** The channel's handle start with @ */
|
|
20
|
-
handle
|
|
21
|
+
handle?: string;
|
|
21
22
|
/** The channel's description */
|
|
22
23
|
description?: string;
|
|
23
24
|
/** Thumbnails of this Channel */
|
|
@@ -36,6 +37,8 @@ export declare class BaseChannel extends Base implements BaseChannelProperties {
|
|
|
36
37
|
live: ChannelLive;
|
|
37
38
|
/** Continuable of playlists */
|
|
38
39
|
playlists: ChannelPlaylists;
|
|
40
|
+
/** Continuable of posts */
|
|
41
|
+
posts: ChannelPosts;
|
|
39
42
|
/** @hidden */
|
|
40
43
|
constructor(attr: BaseChannelProperties);
|
|
41
44
|
/** The URL of the channel page */
|
|
@@ -7,6 +7,7 @@ export declare class BaseChannelParser {
|
|
|
7
7
|
readonly shorts: "EgZzaG9ydHPyBgUKA5oBAA%3D%3D";
|
|
8
8
|
readonly live: "EgdzdHJlYW1z8gYECgJ6AA%3D%3D";
|
|
9
9
|
readonly playlists: "EglwbGF5bGlzdHPyBgQKAkIA";
|
|
10
|
+
readonly posts: "EgVwb3N0c_IGBAoCSgA%3D";
|
|
10
11
|
};
|
|
11
12
|
static loadBaseChannel(target: BaseChannel, data: YoutubeRawData): BaseChannel;
|
|
12
13
|
/** Parse tab data from request, tab name is ignored if it's a continuation data */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Continuable, ContinuableConstructorParams, FetchResult } from "../Continuable";
|
|
2
|
+
import { Post } from "../Post";
|
|
3
|
+
import { BaseChannel } from "./BaseChannel";
|
|
4
|
+
declare type ConstructorParams = ContinuableConstructorParams & {
|
|
5
|
+
channel?: BaseChannel;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* {@link Continuable} of posts inside a {@link BaseChannel}
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```js
|
|
12
|
+
* const channel = await youtube.findOne(CHANNEL_NAME, {type: "channel"});
|
|
13
|
+
* await channel.posts.next();
|
|
14
|
+
* console.log(channel.posts.items) // first 30 posts
|
|
15
|
+
*
|
|
16
|
+
* let newPosts = await channel.posts.next();
|
|
17
|
+
* console.log(newPosts) // 30 loaded posts
|
|
18
|
+
* console.log(channel.posts.items) // first 60 posts
|
|
19
|
+
*
|
|
20
|
+
* await channel.posts.next(0); // load the rest of the posts in the channel
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class ChannelPosts extends Continuable<Post> {
|
|
24
|
+
/** The channel this posts belongs to */
|
|
25
|
+
channel?: BaseChannel;
|
|
26
|
+
/** @hidden */
|
|
27
|
+
constructor({ client, channel }: ConstructorParams);
|
|
28
|
+
protected fetch(): Promise<FetchResult<Post>>;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { YoutubeRawData } from "../../common";
|
|
2
|
+
import { Base, BaseProperties } from "../Base";
|
|
3
|
+
import { BaseChannel } from "../BaseChannel";
|
|
4
|
+
/** @hidden */
|
|
5
|
+
interface PostProperties extends BaseProperties {
|
|
6
|
+
id?: string;
|
|
7
|
+
channel?: BaseChannel;
|
|
8
|
+
content?: string;
|
|
9
|
+
timestamp?: string;
|
|
10
|
+
voteCount?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Represents a chat in a live stream */
|
|
13
|
+
export declare class Post extends Base implements PostProperties {
|
|
14
|
+
id?: string;
|
|
15
|
+
/** The channel who posted this post */
|
|
16
|
+
channel: BaseChannel;
|
|
17
|
+
/** The content of this post */
|
|
18
|
+
content: string;
|
|
19
|
+
/** Timestamp */
|
|
20
|
+
timestamp: string;
|
|
21
|
+
/** Vote count like '1.2K likes' */
|
|
22
|
+
voteCount: string;
|
|
23
|
+
/** @hidden */
|
|
24
|
+
constructor(attr: PostProperties);
|
|
25
|
+
/**
|
|
26
|
+
* Load this instance with raw data from Youtube
|
|
27
|
+
*
|
|
28
|
+
* @hidden
|
|
29
|
+
*/
|
|
30
|
+
load(data: YoutubeRawData): Post;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "youtubei",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
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",
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MusicAllSearchResultParser = void 0;
|
|
4
|
-
const common_1 = require("../../common");
|
|
5
|
-
const MusicAlbumCompact_1 = require("../MusicAlbumCompact");
|
|
6
|
-
const MusicArtistCompact_1 = require("../MusicArtistCompact");
|
|
7
|
-
const MusicBaseArtist_1 = require("../MusicBaseArtist");
|
|
8
|
-
const MusicBaseChannel_1 = require("../MusicBaseChannel");
|
|
9
|
-
const MusicPlaylistCompact_1 = require("../MusicPlaylistCompact");
|
|
10
|
-
const MusicSongCompact_1 = require("../MusicSongCompact");
|
|
11
|
-
const MusicVideoCompact_1 = require("../MusicVideoCompact");
|
|
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
|
-
duration: common_1.getDuration(top.subtitle.runs.at(-1).text),
|
|
32
|
-
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
33
|
-
album: MusicAllSearchResultParser.parseAlbum(top.subtitle.runs, client),
|
|
34
|
-
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
else if (type === "MUSIC_VIDEO_TYPE_UGC" || type === "MUSIC_VIDEO_TYPE_OMV") {
|
|
38
|
-
topResult = new MusicVideoCompact_1.MusicVideoCompact({
|
|
39
|
-
client,
|
|
40
|
-
id,
|
|
41
|
-
title,
|
|
42
|
-
duration: common_1.getDuration(top.subtitle.runs.at(-1).text),
|
|
43
|
-
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
44
|
-
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
else if (type === "MUSIC_PAGE_TYPE_ALBUM") {
|
|
48
|
-
topResult = new MusicAlbumCompact_1.MusicAlbumCompact({
|
|
49
|
-
client,
|
|
50
|
-
id,
|
|
51
|
-
title,
|
|
52
|
-
artists: MusicAllSearchResultParser.parseArtists(top.subtitle.runs, client),
|
|
53
|
-
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
else if (type === "MUSIC_PAGE_TYPE_ARTIST") {
|
|
57
|
-
topResult = new MusicArtistCompact_1.MusicArtistCompact({
|
|
58
|
-
client,
|
|
59
|
-
id,
|
|
60
|
-
name: title,
|
|
61
|
-
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else if (type === "MUSIC_PAGE_TYPE_PLAYLIST") {
|
|
65
|
-
topResult = new MusicPlaylistCompact_1.MusicPlaylistCompact({
|
|
66
|
-
client,
|
|
67
|
-
id,
|
|
68
|
-
title,
|
|
69
|
-
channel: MusicAllSearchResultParser.parseChannel(top.subtitle.runs, client),
|
|
70
|
-
thumbnails: new common_1.Thumbnails().load(thumbnail),
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
let more;
|
|
74
|
-
if (top.contents) {
|
|
75
|
-
more = top.contents
|
|
76
|
-
.filter((c) => c.musicResponsiveListItemRenderer)
|
|
77
|
-
.map((c) => MusicAllSearchResultParser.parseSearchItem(c, client));
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
item: topResult,
|
|
81
|
-
more,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
static parseSearchResult(data, client) {
|
|
85
|
-
const sectionListContents = data.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content
|
|
86
|
-
.sectionListRenderer.contents;
|
|
87
|
-
const shelves = sectionListContents
|
|
88
|
-
.filter((f) => f.musicShelfRenderer)
|
|
89
|
-
.map((m) => m.musicShelfRenderer);
|
|
90
|
-
return shelves.map((m) => ({
|
|
91
|
-
title: m.title.runs.map((r) => r.text).join(),
|
|
92
|
-
items: m.contents
|
|
93
|
-
.map((c) => MusicAllSearchResultParser.parseSearchItem(c, client))
|
|
94
|
-
.filter((i) => i),
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
static parseSearchItem(content, client) {
|
|
98
|
-
var _a;
|
|
99
|
-
const item = content.musicResponsiveListItemRenderer;
|
|
100
|
-
const playEndpoint = (_a = item.overlay) === null || _a === void 0 ? void 0 : _a.musicItemThumbnailOverlayRenderer.content.musicPlayButtonRenderer.playNavigationEndpoint;
|
|
101
|
-
if (playEndpoint === null || playEndpoint === void 0 ? void 0 : playEndpoint.watchEndpoint) {
|
|
102
|
-
const pageType = playEndpoint.watchEndpoint.watchEndpointMusicSupportedConfigs
|
|
103
|
-
.watchEndpointMusicConfig.musicVideoType;
|
|
104
|
-
return MusicAllSearchResultParser.parseVideoItem(item, pageType, client);
|
|
105
|
-
}
|
|
106
|
-
else if (playEndpoint === null || playEndpoint === void 0 ? void 0 : playEndpoint.watchPlaylistEndpoint.params) {
|
|
107
|
-
return MusicAllSearchResultParser.parsePlaylistItem(item, client);
|
|
108
|
-
}
|
|
109
|
-
else if (playEndpoint === null || playEndpoint === void 0 ? void 0 : playEndpoint.watchPlaylistEndpoint) {
|
|
110
|
-
// TODO add podcast support, id starts with PL
|
|
111
|
-
if (playEndpoint.watchPlaylistEndpoint.playlistId.startsWith("OL")) {
|
|
112
|
-
return MusicAllSearchResultParser.parseAlbumItem(item, client);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
return MusicAllSearchResultParser.parseArtistItem(item, client);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
static parseVideoItem(item, pageType, client) {
|
|
120
|
-
// TODO support other types
|
|
121
|
-
if (!["MUSIC_VIDEO_TYPE_ATV", "MUSIC_VIDEO_TYPE_UGC", "MUSIC_VIDEO_TYPE_OMV"].includes(pageType)) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const [topColumn, bottomColumn] = item.flexColumns.map((c) => c.musicResponsiveListItemFlexColumnRenderer.text.runs);
|
|
125
|
-
const id = topColumn[0].navigationEndpoint.watchEndpoint.videoId;
|
|
126
|
-
const title = topColumn[0].text;
|
|
127
|
-
const duration = common_1.getDuration(bottomColumn.at(-1).text) || undefined;
|
|
128
|
-
const thumbnails = new common_1.Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
129
|
-
const artists = MusicAllSearchResultParser.parseArtists(bottomColumn, client);
|
|
130
|
-
if (pageType === "MUSIC_VIDEO_TYPE_ATV") {
|
|
131
|
-
return new MusicSongCompact_1.MusicSongCompact({
|
|
132
|
-
client,
|
|
133
|
-
id,
|
|
134
|
-
album: MusicAllSearchResultParser.parseAlbum(bottomColumn, client),
|
|
135
|
-
title,
|
|
136
|
-
artists,
|
|
137
|
-
thumbnails,
|
|
138
|
-
duration,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
else if (pageType === "MUSIC_VIDEO_TYPE_UGC" || pageType === "MUSIC_VIDEO_TYPE_OMV") {
|
|
142
|
-
return new MusicVideoCompact_1.MusicVideoCompact({ client, id, title, artists, thumbnails, duration });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
static parsePlaylistItem(item, client) {
|
|
146
|
-
const [topColumn, bottomColumn] = item.flexColumns.map((c) => c.musicResponsiveListItemFlexColumnRenderer.text.runs);
|
|
147
|
-
const id = item.overlay.musicItemThumbnailOverlayRenderer.content.musicPlayButtonRenderer
|
|
148
|
-
.playNavigationEndpoint.watchPlaylistEndpoint.playlistId;
|
|
149
|
-
const title = topColumn[0].text;
|
|
150
|
-
const songCount = common_1.stripToInt(bottomColumn.at(-1).text) || undefined;
|
|
151
|
-
const thumbnails = new common_1.Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
152
|
-
const channel = MusicAllSearchResultParser.parseChannel(bottomColumn, client);
|
|
153
|
-
return new MusicPlaylistCompact_1.MusicPlaylistCompact({ client, id, title, thumbnails, songCount, channel });
|
|
154
|
-
}
|
|
155
|
-
static parseAlbumItem(item, client) {
|
|
156
|
-
const [topColumn, bottomColumn] = item.flexColumns.map((c) => c.musicResponsiveListItemFlexColumnRenderer.text.runs);
|
|
157
|
-
const id = item.overlay.musicItemThumbnailOverlayRenderer.content.musicPlayButtonRenderer
|
|
158
|
-
.playNavigationEndpoint.watchPlaylistEndpoint.playlistId;
|
|
159
|
-
const title = topColumn[0].text;
|
|
160
|
-
const year = common_1.stripToInt(bottomColumn.at(-1).text) || undefined;
|
|
161
|
-
const thumbnails = new common_1.Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
162
|
-
const artists = MusicAllSearchResultParser.parseArtists(bottomColumn, client);
|
|
163
|
-
return new MusicAlbumCompact_1.MusicAlbumCompact({ client, id, title, thumbnails, artists, year });
|
|
164
|
-
}
|
|
165
|
-
static parseArtistItem(item, client) {
|
|
166
|
-
const [topColumn] = item.flexColumns.map((c) => c.musicResponsiveListItemFlexColumnRenderer.text.runs);
|
|
167
|
-
const id = item.navigationEndpoint.browseEndpoint.browseId;
|
|
168
|
-
const name = topColumn[0].text;
|
|
169
|
-
const thumbnails = new common_1.Thumbnails().load(item.thumbnail.musicThumbnailRenderer.thumbnail.thumbnails);
|
|
170
|
-
return new MusicArtistCompact_1.MusicArtistCompact({ client, id, name, thumbnails });
|
|
171
|
-
}
|
|
172
|
-
static parseAlbum(items, client) {
|
|
173
|
-
var _a;
|
|
174
|
-
const albumRaw = items.find((r) => {
|
|
175
|
-
var _a;
|
|
176
|
-
const pageType = (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
177
|
-
return pageType === "MUSIC_PAGE_TYPE_ALBUM";
|
|
178
|
-
});
|
|
179
|
-
if (!albumRaw)
|
|
180
|
-
return;
|
|
181
|
-
const album = new MusicAlbumCompact_1.MusicAlbumCompact({
|
|
182
|
-
client,
|
|
183
|
-
title: albumRaw.text,
|
|
184
|
-
id: (_a = albumRaw.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
185
|
-
});
|
|
186
|
-
return album;
|
|
187
|
-
}
|
|
188
|
-
static parseArtists(items, client) {
|
|
189
|
-
return this.parseArtistsOrChannel(items).map((r) => {
|
|
190
|
-
var _a;
|
|
191
|
-
return new MusicBaseArtist_1.MusicBaseArtist({
|
|
192
|
-
client,
|
|
193
|
-
name: r.text,
|
|
194
|
-
id: (_a = r.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
static parseChannel(items, client) {
|
|
199
|
-
var _a;
|
|
200
|
-
const [channelRaw] = this.parseArtistsOrChannel(items);
|
|
201
|
-
if (!channelRaw)
|
|
202
|
-
return;
|
|
203
|
-
const channel = new MusicBaseChannel_1.MusicBaseChannel({
|
|
204
|
-
client,
|
|
205
|
-
name: channelRaw.text,
|
|
206
|
-
id: (_a = channelRaw.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseId,
|
|
207
|
-
});
|
|
208
|
-
return channel;
|
|
209
|
-
}
|
|
210
|
-
static parseArtistsOrChannel(items) {
|
|
211
|
-
return items.filter((i) => {
|
|
212
|
-
var _a;
|
|
213
|
-
const pageType = (_a = i.navigationEndpoint) === null || _a === void 0 ? void 0 : _a.browseEndpoint.browseEndpointContextSupportedConfigs.browseEndpointContextMusicConfig.pageType;
|
|
214
|
-
return (pageType === "MUSIC_PAGE_TYPE_ARTIST" || pageType == "MUSIC_PAGE_TYPE_USER_CHANNEL");
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
exports.MusicAllSearchResultParser = MusicAllSearchResultParser;
|