From 72c3af84b07c3b183f3bbed0ab1d86c83c79c779 Mon Sep 17 00:00:00 2001 From: LuanRT Date: Fri, 29 Jul 2022 06:58:28 -0300 Subject: [PATCH] refactor(ytmusic)!: rewrite `Album` to TypeScript --- src/parser/ytmusic/Album.js | 32 -------------------------------- src/parser/ytmusic/Album.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 32 deletions(-) delete mode 100644 src/parser/ytmusic/Album.js create mode 100644 src/parser/ytmusic/Album.ts diff --git a/src/parser/ytmusic/Album.js b/src/parser/ytmusic/Album.js deleted file mode 100644 index 4552dc72..00000000 --- a/src/parser/ytmusic/Album.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/src/parser/ytmusic/Album.ts b/src/parser/ytmusic/Album.ts new file mode 100644 index 00000000..fe3dbaf1 --- /dev/null +++ b/src/parser/ytmusic/Album.ts @@ -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; \ No newline at end of file