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 & {
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<ArtistInfo> =>
this.getJSON<GetArtistInfoResponse>(credentials, "/rest/getArtistInfo", {
this.getJSON<GetArtistInfoResponse>(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<Artist> =>
navidrome.getArtistWithInfo(credentials, id),
albums: (q: AlbumQuery): Promise<Result<AlbumSummary>> => {
albums: async (q: AlbumQuery): Promise<Result<AlbumSummary>> => {
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<GetAlbumListResponse>(credentials, "/rest/getAlbumList", {
.getJSON<GetAlbumListResponse>(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<GetSimilarSongsResponse>(
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) =>

View File

@@ -168,7 +168,7 @@ const similarArtistXml = (similarArtist: SimilarArtist) => {
const getArtistInfoXml = (
artist: Artist
) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)">
<artistInfo>
<artistInfo2>
<biography></biography>
<musicBrainzId></musicBrainzId>
<lastFmUrl></lastFmUrl>
@@ -176,7 +176,7 @@ const getArtistInfoXml = (
<mediumImageUrl>${artist.image.medium || ""}</mediumImageUrl>
<largeImageUrl>${artist.image.large || ""}</largeImageUrl>
${artist.similarArtists.map(similarArtistXml).join("")}
</artistInfo>
</artistInfo2>
</subsonic-response>`;
const albumXml = (
@@ -223,11 +223,11 @@ const songXml = (track: Track) => `<song
const albumListXml = (
albums: [Artist, Album][]
) => `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.16.1" type="navidrome" serverVersion="0.40.0 (8799358a)">
<albumList>
<albumList2>
${albums
.map(([artist, album]) => albumXml(artist, album))
.join("")}
</albumList>
</albumList2>
</subsonic-response>`;
const artistXml = (artist: Artist) => `<artist id="${artist.id}" name="${
@@ -280,9 +280,9 @@ const getSongXml = (
const similarSongsXml = (
tracks: Track[]
) => `<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("")}
</similarSongs>
</similarSongs2>
</subsonic-response>`;
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,