From a80393b3f58d5c7abc7cbf2a85f465d4e1c26303 Mon Sep 17 00:00:00 2001 From: Miraculous Owonubi Date: Sun, 18 Dec 2022 01:34:25 +0400 Subject: [PATCH] feat: Introduce artist albums pagination (#400) --- cli.js | 21 ++++++++++++++++++--- src/services/apple_music.js | 11 ++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/cli.js b/cli.js index 159ac7fa..51fb41da 100755 --- a/cli.js +++ b/cli.js @@ -1,6 +1,7 @@ #!/usr/bin/env node /* eslint-disable consistent-return, camelcase, prefer-promise-reject-errors */ import xurl from 'url'; +import util from 'util'; import xpath from 'path'; import crypto from 'crypto'; import {spawn, spawnSync} from 'child_process'; @@ -250,7 +251,11 @@ async function processPromise(promise, logger, messageHandlers) { if (messageHandlers.onErr !== false) handleResultOf(result.reason(), messageHandlers.onErr, reason => [ '(failed%s)', - reason ? `: [${reason['SHOW_DEBUG_STACK' in process.env ? 'stack' : 'message'] || reason}]` : '', + reason + ? `: [${ + 'SHOW_DEBUG_STACK' in process.env ? util.formatWithOptions({colors: true}, reason) : reason['message'] || reason + }]` + : '', '\n', ]); return null; @@ -1602,7 +1607,13 @@ async function init(packageJson, queries, options) { `\u2022 [\u2715] ${trackStat.meta && trackStat.meta.trackName ? `${trackStat.meta.trackName}` : ''}${ trackStat.meta && trackStat.meta.track.uri ? ` [${trackStat.meta.track.uri}]` : '' } (failed:${reason ? ` ${reason}` : ''}${ - trackStat.err ? ` [${trackStat.err['SHOW_DEBUG_STACK' in process.env ? 'stack' : 'message'] || trackStat.err}]` : '' + trackStat.err + ? ` [${ + 'SHOW_DEBUG_STACK' in process.env + ? util.formatWithOptions({colors: true}, trackStat.err) + : trackStat.err['message'] || trackStat.err + }]` + : '' })`, ); } else if (trackStat[symbols.errorCode] === 0) @@ -2168,7 +2179,11 @@ async function main(argv) { } catch (err) { console.error( `\x1b[31m[!] Fatal Error\x1b[0m: ${ - typeof err === 'undefined' ? '[uncaught]' : err ? err['SHOW_DEBUG_STACK' in process.env ? 'stack' : 'message'] : err + typeof err === 'undefined' + ? '[uncaught]' + : 'SHOW_DEBUG_STACK' in err + ? util.formatWithOptions({colors: true}, err) + : err['message'] }`, ); } diff --git a/src/services/apple_music.js b/src/services/apple_music.js index 9f271a55..f2dadc8f 100644 --- a/src/services/apple_music.js +++ b/src/services/apple_music.js @@ -295,12 +295,9 @@ export default class AppleMusic { Promise.mapSeries( (await this.#store.core.artists.get(`?ids=${items.map(item => item.refID).join(',')}`, {storefront})).data, async artist => { - artist.albums = await this.depaginate(artist.relationships.albums, nextUrl => { - let err = new Error('Unimplemented: artist albums pagination'); - [err.artistId, err.artistHref, err.nextUrl] = [artist.id, artist.href, nextUrl]; - throw err; - // this.#store.core.artists.get(`${artist.id}/${nextUrl.split(artist.href)[1]}`, {storefront}); - }); + artist.albums = await this.depaginate(artist.relationships.albums, nextUrl => + this.#store.core.artists.get(`${artist.id}${nextUrl.split(artist.href)[1]}`, {storefront}), + ); return this.wrapArtistData(artist); }, ), @@ -313,7 +310,7 @@ export default class AppleMusic { (await this.#store.core.playlists.get(`?ids=${items.map(item => item.refID).join(',')}`, {storefront})).data, async playlist => { playlist.tracks = await this.depaginate(playlist.relationships.tracks, nextUrl => - this.#store.core.playlists.get(`${playlist.id}/${nextUrl.split(playlist.href)[1]}`, {storefront}), + this.#store.core.playlists.get(`${playlist.id}${nextUrl.split(playlist.href)[1]}`, {storefront}), ); return this.wrapPlaylistData(playlist); },