UNPKG

youtube-moosick

Version:

Unofficial Youtube music API, fully written in TypeScript

57 lines 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetAlbumParser = void 0; const objectScan_utility_js_1 = require("../resources/utilities/objectScan.utility.js"); const albumURL_js_1 = require("../resources/resultTypes/albumURL.js"); const enums_js_1 = require("../enums.js"); const parsersExtended_js_1 = require("./parsersExtended.js"); const utils_js_1 = require("../utils.js"); /** * Parser to deal with the output generated by the Moosick#getAlbum * * @remarks * Do not use this class directly, unless for tests purposes * @internal */ class GetAlbumParser { /** * Parses the object provided by Moosick#getAlbum * @param context - The return results from axios */ static parseAlbumURLPage(context) { // Unprocessed Header const unprocessedHeader = (0, objectScan_utility_js_1.$$)('.musicDetailHeaderRenderer')(context); // Gets the tracks const shelfContent = (0, objectScan_utility_js_1.$$)('.musicResponsiveListItemRenderer')(context); const tracks = []; for (const trackUnprocessed of shelfContent) { const flexColumn = (0, objectScan_utility_js_1.$)('.flexColumns')(trackUnprocessed); const fixedColumn = (0, objectScan_utility_js_1.$)('.fixedColumns')(trackUnprocessed); tracks.push(albumURL_js_1.Track.from({ lengthMs: utils_js_1.utils.hms2ms((0, objectScan_utility_js_1.$)('.text')(fixedColumn)), title: (0, objectScan_utility_js_1.$)('.text')(flexColumn), videoId: (0, objectScan_utility_js_1.$)('.videoId')(flexColumn), playlistId: (0, objectScan_utility_js_1.$)('.playlistId')(flexColumn), url: `${enums_js_1.ConstantURLs.VIDEOLINK}${(0, objectScan_utility_js_1.$)('.videoId')(flexColumn)}`, })); } return albumURL_js_1.AlbumURL.from({ AlbumURLHeader: this.playlistURLHeaderParser(unprocessedHeader), tracks, }); } static playlistURLHeaderParser(header) { const artist = parsersExtended_js_1.ParsersExtended.artistParser(header[0].subtitle.runs); return albumURL_js_1.AlbumURLHeader.from({ title: header[0].title.runs[enums_js_1.FlexColumnOffset.ONLYRUN].text, description: header[0].description?.runs[enums_js_1.FlexColumnOffset.ONLYRUN].text ?? '', date: header[0].subtitle.runs[header[0].subtitle.runs.length - 1].text, thumbnails: header[0].thumbnail.croppedSquareThumbnailRenderer.thumbnail.thumbnails, trackCount: parseInt(header[0].secondSubtitle.runs[enums_js_1.FlexColumnOffset.ONLYRUN].text, 10), totalRuntime: header[0].secondSubtitle.runs[2].text, artist, }); } } exports.GetAlbumParser = GetAlbumParser; //# sourceMappingURL=getAlbumParser.js.map