mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-28 09:06:51 +00:00
refactor(ytmusic)!: rewrite Album to TypeScript
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
import Parser from '../index';
|
||||
|
||||
class Album {
|
||||
#page;
|
||||
#actions;
|
||||
|
||||
/**
|
||||
* @param {object} response - API response.
|
||||
* @param {import('../../core/Actions').default} actions
|
||||
*/
|
||||
constructor(response, actions) {
|
||||
this.#page = Parser.parseResponse(response.data);
|
||||
this.#actions = actions;
|
||||
|
||||
/** @type {import('../classes/MusicDetailHeader')[]} */
|
||||
this.header = this.#page.header;
|
||||
|
||||
/** @type {string} */
|
||||
this.url = this.#page.microformat.url_canonical;
|
||||
|
||||
/** @type {import('../classes/MusicResponsiveListItem')[]} */
|
||||
this.contents = this.#page.contents_memo.get('MusicShelf')?.[0].contents;
|
||||
|
||||
this.sections = this.#page.contents_memo.get('MusicCarouselShelf') || [];
|
||||
}
|
||||
|
||||
get page() {
|
||||
return this.#page;
|
||||
}
|
||||
}
|
||||
|
||||
export default Album;
|
||||
36
src/parser/ytmusic/Album.ts
Normal file
36
src/parser/ytmusic/Album.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import Parser, { ParsedResponse } from '../index';
|
||||
import Actions, { AxioslikeResponse } from '../../core/Actions';
|
||||
|
||||
import MusicDetailHeader from '../classes/MusicDetailHeader';
|
||||
import MicroformatData from '../classes/MicroformatData';
|
||||
import MusicCarouselShelf from '../classes/MusicCarouselShelf';
|
||||
import MusicResponsiveListItem from '../classes/MusicResponsiveListItem';
|
||||
import MusicShelf from '../classes/MusicShelf';
|
||||
|
||||
class Album {
|
||||
#page;
|
||||
#actions;
|
||||
|
||||
header;
|
||||
contents;
|
||||
sections;
|
||||
|
||||
url: string | null;
|
||||
|
||||
constructor(response: AxioslikeResponse, actions: Actions) {
|
||||
this.#page = Parser.parseResponse(response.data);
|
||||
this.#actions = actions;
|
||||
|
||||
this.header = this.#page.header.item().as(MusicDetailHeader);
|
||||
this.url = this.#page.microformat?.as(MicroformatData).url_canonical || null;
|
||||
|
||||
this.contents = this.#page.contents_memo.get('MusicShelf')?.[0].as(MusicShelf).contents.array().as(MusicResponsiveListItem);
|
||||
this.sections = this.#page.contents_memo.get('MusicCarouselShelf') as MusicCarouselShelf[] || ([] as MusicCarouselShelf[]);
|
||||
}
|
||||
|
||||
get page(): ParsedResponse {
|
||||
return this.#page;
|
||||
}
|
||||
}
|
||||
|
||||
export default Album;
|
||||
Reference in New Issue
Block a user