From 588141e569c356954e6791240fc41bdd209e826c Mon Sep 17 00:00:00 2001 From: Simon J Date: Sat, 4 Sep 2021 09:13:57 +1000 Subject: [PATCH] Migrate to v2 subsonic APIs (#45) --- src/navidrome.ts | 32 ++++++++--------- tests/navidrome.test.ts | 76 ++++++++++++++++++++--------------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/navidrome.ts b/src/navidrome.ts index 1d0442f..987cb7b 100644 --- a/src/navidrome.ts +++ b/src/navidrome.ts @@ -90,7 +90,7 @@ export type GetArtistsResponse = SubsonicResponse & { }; export type GetAlbumListResponse = SubsonicResponse & { - albumList: { + albumList2: { album: album[]; }; }; @@ -130,7 +130,7 @@ export type ArtistInfo = { }; export type GetArtistInfoResponse = SubsonicResponse & { - artistInfo: artistInfo; + artistInfo2: artistInfo; }; export type GetArtistResponse = SubsonicResponse & { @@ -197,7 +197,7 @@ export type GetPlaylistsResponse = { }; export type GetSimilarSongsResponse = { - similarSongs: { song: song[] }; + similarSongs2: { song: song[] }; }; export type GetTopSongsResponse = { @@ -349,18 +349,18 @@ export class Navidrome implements MusicService { new X2JS({ arrayAccessFormPaths: [ "subsonic-response.album.song", - "subsonic-response.albumList.album", + "subsonic-response.albumList2.album", "subsonic-response.artist.album", "subsonic-response.artists.index", "subsonic-response.artists.index.artist", - "subsonic-response.artistInfo.similarArtist", + "subsonic-response.artistInfo2.similarArtist", "subsonic-response.genres.genre", "subsonic-response.playlist.entry", "subsonic-response.playlists.playlist", "subsonic-response.searchResult3.album", "subsonic-response.searchResult3.artist", "subsonic-response.searchResult3.song", - "subsonic-response.similarSongs.song", + "subsonic-response.similarSongs2.song", "subsonic-response.topSongs.song", ], }).xml2js(response.data) as SubconicEnvelope @@ -403,17 +403,17 @@ export class Navidrome implements MusicService { ); getArtistInfo = (credentials: Credentials, id: string): Promise => - this.getJSON(credentials, "/rest/getArtistInfo", { + this.getJSON(credentials, "/rest/getArtistInfo2", { id, count: 50, includeNotPresent: true, }).then((it) => ({ image: { - small: validate(it.artistInfo.smallImageUrl), - medium: validate(it.artistInfo.mediumImageUrl), - large: validate(it.artistInfo.largeImageUrl), + small: validate(it.artistInfo2.smallImageUrl), + medium: validate(it.artistInfo2.mediumImageUrl), + large: validate(it.artistInfo2.largeImageUrl), }, - similarArtist: (it.artistInfo.similarArtist || []).map((artist) => ({ + similarArtist: (it.artistInfo2.similarArtist || []).map((artist) => ({ id: artist._id, name: artist._name, inLibrary: artist._id != "-1", @@ -519,7 +519,7 @@ export class Navidrome implements MusicService { })), artist: async (id: string): Promise => navidrome.getArtistWithInfo(credentials, id), - albums: (q: AlbumQuery): Promise> => { + albums: async (q: AlbumQuery): Promise> => { return Promise.all([ navidrome .getArtists(credentials) @@ -527,12 +527,12 @@ export class Navidrome implements MusicService { _.inject(it, (total, artist) => total + artist.albumCount, 0) ), navidrome - .getJSON(credentials, "/rest/getAlbumList", { + .getJSON(credentials, "/rest/getAlbumList2", { ...pick(q, "type", "genre"), size: 500, offset: q._index, }) - .then((response) => response.albumList.album || []) + .then((response) => response.albumList2.album || []) .then(navidrome.toAlbumSummary), ]).then(([total, albums]) => ({ results: albums.slice(0, q._count), @@ -760,10 +760,10 @@ export class Navidrome implements MusicService { navidrome .getJSON( credentials, - "/rest/getSimilarSongs", + "/rest/getSimilarSongs2", { id, count: 50 } ) - .then((it) => it.similarSongs.song || []) + .then((it) => it.similarSongs2.song || []) .then((songs) => Promise.all( songs.map((song) => diff --git a/tests/navidrome.test.ts b/tests/navidrome.test.ts index a7b3cf3..49f662a 100644 --- a/tests/navidrome.test.ts +++ b/tests/navidrome.test.ts @@ -168,7 +168,7 @@ const similarArtistXml = (similarArtist: SimilarArtist) => { const getArtistInfoXml = ( artist: Artist ) => ` - + @@ -176,7 +176,7 @@ const getArtistInfoXml = ( ${artist.image.medium || ""} ${artist.image.large || ""} ${artist.similarArtists.map(similarArtistXml).join("")} - + `; const albumXml = ( @@ -223,11 +223,11 @@ const songXml = (track: Track) => ` ` - + ${albums .map(([artist, album]) => albumXml(artist, album)) .join("")} - + `; const artistXml = (artist: Artist) => ` - + ${tracks.map(songXml).join("")} - + `; const topSongsXml = ( @@ -653,7 +653,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, id: artist.id, @@ -720,7 +720,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, id: artist.id, @@ -785,7 +785,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, id: artist.id, @@ -850,7 +850,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, id: artist.id, @@ -906,7 +906,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, id: artist.id, @@ -960,7 +960,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, id: artist.id, @@ -1012,7 +1012,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, id: artist.id, @@ -1257,7 +1257,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "byGenre", @@ -1308,7 +1308,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "newest", @@ -1358,7 +1358,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "recent", @@ -1403,7 +1403,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "frequent", @@ -1457,7 +1457,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1510,7 +1510,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1578,7 +1578,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1632,7 +1632,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1720,7 +1720,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1780,7 +1780,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1839,7 +1839,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1907,7 +1907,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -1970,7 +1970,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -2032,7 +2032,7 @@ describe("Navidrome", () => { headers, }); - expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { + expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, { params: asURLSearchParams({ ...authParams, type: "alphabeticalByArtist", @@ -2760,7 +2760,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -2837,7 +2837,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -2914,7 +2914,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -2984,7 +2984,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -3064,7 +3064,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -3142,7 +3142,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -3215,7 +3215,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -3293,7 +3293,7 @@ describe("Navidrome", () => { }); expect(axios.get).toHaveBeenCalledWith( - `${url}/rest/getArtistInfo`, + `${url}/rest/getArtistInfo2`, { params: asURLSearchParams({ ...authParams, @@ -4134,7 +4134,7 @@ describe("Navidrome", () => { expect(result).toEqual([track1]); - expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs`, { + expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs2`, { params: asURLSearchParams({ ...authParams, id, @@ -4206,7 +4206,7 @@ describe("Navidrome", () => { expect(result).toEqual([track1, track2, track3]); - expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs`, { + expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs2`, { params: asURLSearchParams({ ...authParams, id, @@ -4234,7 +4234,7 @@ describe("Navidrome", () => { expect(result).toEqual([]); - expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs`, { + expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs2`, { params: asURLSearchParams({ ...authParams, id,