Migrate to v2 subsonic APIs (#45)

This commit is contained in:
Simon J
2021-09-04 09:13:57 +10:00
committed by GitHub
parent b99ff0e5dc
commit 588141e569
2 changed files with 54 additions and 54 deletions

View File

@@ -90,7 +90,7 @@ export type GetArtistsResponse = SubsonicResponse & {
}; };
export type GetAlbumListResponse = SubsonicResponse & { export type GetAlbumListResponse = SubsonicResponse & {
albumList: { albumList2: {
album: album[]; album: album[];
}; };
}; };
@@ -130,7 +130,7 @@ export type ArtistInfo = {
}; };
export type GetArtistInfoResponse = SubsonicResponse & { export type GetArtistInfoResponse = SubsonicResponse & {
artistInfo: artistInfo; artistInfo2: artistInfo;
}; };
export type GetArtistResponse = SubsonicResponse & { export type GetArtistResponse = SubsonicResponse & {
@@ -197,7 +197,7 @@ export type GetPlaylistsResponse = {
}; };
export type GetSimilarSongsResponse = { export type GetSimilarSongsResponse = {
similarSongs: { song: song[] }; similarSongs2: { song: song[] };
}; };
export type GetTopSongsResponse = { export type GetTopSongsResponse = {
@@ -349,18 +349,18 @@ export class Navidrome implements MusicService {
new X2JS({ new X2JS({
arrayAccessFormPaths: [ arrayAccessFormPaths: [
"subsonic-response.album.song", "subsonic-response.album.song",
"subsonic-response.albumList.album", "subsonic-response.albumList2.album",
"subsonic-response.artist.album", "subsonic-response.artist.album",
"subsonic-response.artists.index", "subsonic-response.artists.index",
"subsonic-response.artists.index.artist", "subsonic-response.artists.index.artist",
"subsonic-response.artistInfo.similarArtist", "subsonic-response.artistInfo2.similarArtist",
"subsonic-response.genres.genre", "subsonic-response.genres.genre",
"subsonic-response.playlist.entry", "subsonic-response.playlist.entry",
"subsonic-response.playlists.playlist", "subsonic-response.playlists.playlist",
"subsonic-response.searchResult3.album", "subsonic-response.searchResult3.album",
"subsonic-response.searchResult3.artist", "subsonic-response.searchResult3.artist",
"subsonic-response.searchResult3.song", "subsonic-response.searchResult3.song",
"subsonic-response.similarSongs.song", "subsonic-response.similarSongs2.song",
"subsonic-response.topSongs.song", "subsonic-response.topSongs.song",
], ],
}).xml2js(response.data) as SubconicEnvelope }).xml2js(response.data) as SubconicEnvelope
@@ -403,17 +403,17 @@ export class Navidrome implements MusicService {
); );
getArtistInfo = (credentials: Credentials, id: string): Promise<ArtistInfo> => getArtistInfo = (credentials: Credentials, id: string): Promise<ArtistInfo> =>
this.getJSON<GetArtistInfoResponse>(credentials, "/rest/getArtistInfo", { this.getJSON<GetArtistInfoResponse>(credentials, "/rest/getArtistInfo2", {
id, id,
count: 50, count: 50,
includeNotPresent: true, includeNotPresent: true,
}).then((it) => ({ }).then((it) => ({
image: { image: {
small: validate(it.artistInfo.smallImageUrl), small: validate(it.artistInfo2.smallImageUrl),
medium: validate(it.artistInfo.mediumImageUrl), medium: validate(it.artistInfo2.mediumImageUrl),
large: validate(it.artistInfo.largeImageUrl), large: validate(it.artistInfo2.largeImageUrl),
}, },
similarArtist: (it.artistInfo.similarArtist || []).map((artist) => ({ similarArtist: (it.artistInfo2.similarArtist || []).map((artist) => ({
id: artist._id, id: artist._id,
name: artist._name, name: artist._name,
inLibrary: artist._id != "-1", inLibrary: artist._id != "-1",
@@ -519,7 +519,7 @@ export class Navidrome implements MusicService {
})), })),
artist: async (id: string): Promise<Artist> => artist: async (id: string): Promise<Artist> =>
navidrome.getArtistWithInfo(credentials, id), navidrome.getArtistWithInfo(credentials, id),
albums: (q: AlbumQuery): Promise<Result<AlbumSummary>> => { albums: async (q: AlbumQuery): Promise<Result<AlbumSummary>> => {
return Promise.all([ return Promise.all([
navidrome navidrome
.getArtists(credentials) .getArtists(credentials)
@@ -527,12 +527,12 @@ export class Navidrome implements MusicService {
_.inject(it, (total, artist) => total + artist.albumCount, 0) _.inject(it, (total, artist) => total + artist.albumCount, 0)
), ),
navidrome navidrome
.getJSON<GetAlbumListResponse>(credentials, "/rest/getAlbumList", { .getJSON<GetAlbumListResponse>(credentials, "/rest/getAlbumList2", {
...pick(q, "type", "genre"), ...pick(q, "type", "genre"),
size: 500, size: 500,
offset: q._index, offset: q._index,
}) })
.then((response) => response.albumList.album || []) .then((response) => response.albumList2.album || [])
.then(navidrome.toAlbumSummary), .then(navidrome.toAlbumSummary),
]).then(([total, albums]) => ({ ]).then(([total, albums]) => ({
results: albums.slice(0, q._count), results: albums.slice(0, q._count),
@@ -760,10 +760,10 @@ export class Navidrome implements MusicService {
navidrome navidrome
.getJSON<GetSimilarSongsResponse>( .getJSON<GetSimilarSongsResponse>(
credentials, credentials,
"/rest/getSimilarSongs", "/rest/getSimilarSongs2",
{ id, count: 50 } { id, count: 50 }
) )
.then((it) => it.similarSongs.song || []) .then((it) => it.similarSongs2.song || [])
.then((songs) => .then((songs) =>
Promise.all( Promise.all(
songs.map((song) => songs.map((song) =>

View File

@@ -168,7 +168,7 @@ const similarArtistXml = (similarArtist: SimilarArtist) => {
const getArtistInfoXml = ( const getArtistInfoXml = (
artist: Artist artist: Artist
) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)"> ) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)">
<artistInfo> <artistInfo2>
<biography></biography> <biography></biography>
<musicBrainzId></musicBrainzId> <musicBrainzId></musicBrainzId>
<lastFmUrl></lastFmUrl> <lastFmUrl></lastFmUrl>
@@ -176,7 +176,7 @@ const getArtistInfoXml = (
<mediumImageUrl>${artist.image.medium || ""}</mediumImageUrl> <mediumImageUrl>${artist.image.medium || ""}</mediumImageUrl>
<largeImageUrl>${artist.image.large || ""}</largeImageUrl> <largeImageUrl>${artist.image.large || ""}</largeImageUrl>
${artist.similarArtists.map(similarArtistXml).join("")} ${artist.similarArtists.map(similarArtistXml).join("")}
</artistInfo> </artistInfo2>
</subsonic-response>`; </subsonic-response>`;
const albumXml = ( const albumXml = (
@@ -223,11 +223,11 @@ const songXml = (track: Track) => `<song
const albumListXml = ( const albumListXml = (
albums: [Artist, Album][] albums: [Artist, Album][]
) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)"> ) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)">
<albumList> <albumList2>
${albums ${albums
.map(([artist, album]) => albumXml(artist, album)) .map(([artist, album]) => albumXml(artist, album))
.join("")} .join("")}
</albumList> </albumList2>
</subsonic-response>`; </subsonic-response>`;
const artistXml = (artist: Artist) => `<artist id="${artist.id}" name="${ const artistXml = (artist: Artist) => `<artist id="${artist.id}" name="${
@@ -280,9 +280,9 @@ const getSongXml = (
const similarSongsXml = ( const similarSongsXml = (
tracks: Track[] tracks: Track[]
) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)"> ) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)">
<similarSongs> <similarSongs2>
${tracks.map(songXml).join("")} ${tracks.map(songXml).join("")}
</similarSongs> </similarSongs2>
</subsonic-response>`; </subsonic-response>`;
const topSongsXml = ( const topSongsXml = (
@@ -653,7 +653,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id: artist.id, id: artist.id,
@@ -720,7 +720,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id: artist.id, id: artist.id,
@@ -785,7 +785,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id: artist.id, id: artist.id,
@@ -850,7 +850,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id: artist.id, id: artist.id,
@@ -906,7 +906,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id: artist.id, id: artist.id,
@@ -960,7 +960,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id: artist.id, id: artist.id,
@@ -1012,7 +1012,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getArtistInfo2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id: artist.id, id: artist.id,
@@ -1257,7 +1257,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "byGenre", type: "byGenre",
@@ -1308,7 +1308,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "newest", type: "newest",
@@ -1358,7 +1358,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "recent", type: "recent",
@@ -1403,7 +1403,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "frequent", type: "frequent",
@@ -1457,7 +1457,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1510,7 +1510,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1578,7 +1578,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1632,7 +1632,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1720,7 +1720,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1780,7 +1780,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1839,7 +1839,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1907,7 +1907,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -1970,7 +1970,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -2032,7 +2032,7 @@ describe("Navidrome", () => {
headers, headers,
}); });
expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList`, { expect(axios.get).toHaveBeenCalledWith(`${url}/rest/getAlbumList2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
type: "alphabeticalByArtist", type: "alphabeticalByArtist",
@@ -2760,7 +2760,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -2837,7 +2837,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -2914,7 +2914,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -2984,7 +2984,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -3064,7 +3064,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -3142,7 +3142,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -3215,7 +3215,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -3293,7 +3293,7 @@ describe("Navidrome", () => {
}); });
expect(axios.get).toHaveBeenCalledWith( expect(axios.get).toHaveBeenCalledWith(
`${url}/rest/getArtistInfo`, `${url}/rest/getArtistInfo2`,
{ {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
@@ -4134,7 +4134,7 @@ describe("Navidrome", () => {
expect(result).toEqual([track1]); expect(result).toEqual([track1]);
expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs`, { expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id, id,
@@ -4206,7 +4206,7 @@ describe("Navidrome", () => {
expect(result).toEqual([track1, track2, track3]); expect(result).toEqual([track1, track2, track3]);
expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs`, { expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id, id,
@@ -4234,7 +4234,7 @@ describe("Navidrome", () => {
expect(result).toEqual([]); expect(result).toEqual([]);
expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs`, { expect(mockGET).toHaveBeenCalledWith(`${url}/rest/getSimilarSongs2`, {
params: asURLSearchParams({ params: asURLSearchParams({
...authParams, ...authParams,
id, id,