From 183e221eb3fc54cfafa2637c4a0b806b5be81acf Mon Sep 17 00:00:00 2001 From: Anatole Sot Date: Sun, 18 Aug 2024 16:52:06 +0200 Subject: [PATCH] fix(lidarr api): fixed Lidarr API not working when adding albums Since I was previously using an outdated version of Lidarr, my API calls were not functionnal with the latest versions I updated and fixed them.I however found a bug in Lidarr that will need to be fixed before the calls fully work. re #9 --- server/api/servarr/lidarr.ts | 93 ++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/server/api/servarr/lidarr.ts b/server/api/servarr/lidarr.ts index fb6cd874b4..0d85533963 100644 --- a/server/api/servarr/lidarr.ts +++ b/server/api/servarr/lidarr.ts @@ -278,62 +278,75 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> { options: LidarrAlbumOptions ): Promise => { try { - let album = await this.getAlbumByMusicBrainzId(options.mbId); - - if (!album.artist.monitored) { - logger.info('Artist is not already in Lidarr. Monitoring artist.', { - label: 'Lidarr', - albumId: album.id, - albumTitle: album.title, - }); - - const artist = album.artist; - - const artist_options: LidarrArtistOptions = { - profileId: options.profileId, - qualityProfileId: options.qualityProfileId, - rootFolderPath: options.rootFolderPath, - mbId: artist.foreignArtistId, - monitored: true, - tags: [], - searchNow: true, - monitorNewItems: 'none', - searchForMissingAlbums: false, - monitor: 'none', - }; - - await this.addArtist(artist_options); - - album = await this.getAlbumByMusicBrainzId(options.mbId); - } - - if (!album.monitored) { + const album = await this.getAlbumByMusicBrainzId(options.mbId); + let response; + if (!album.id) { logger.info( - 'Album is not already monitored in Lidarr. Monitoring it before download.\nalbumId: ' + - album.id, + 'Album is not already in Lidarr. Monitoring it and downloading.', { label: 'Lidarr' } ); - await this.axios.put(`album/monitor/`, { - albumIds: [album.id], + const settings = { + ...album, + artistId: album.artistId ?? 0, + foreignAlbumId: options.mbId, monitored: true, - }); + anyReleaseOk: true, + profileId: options.profileId, + artist: { + ...album.artist, + qualityProfileId: options.qualityProfileId, + monitored: true, + monitorNewItems: 'none', + folder: album.artist.artistName, + added: '0001-01-01T00:00:00Z', + addOptions: { + monitor: 'none', + searchForMissingAlbums: false, + }, + rootFolderPath: options.rootFolderPath, + images: [], + links: [], + }, + addOptions: { + searchForNewAlbum: options.searchNow, + }, + }; + response = await this.axios.post(`album/`, settings); + + if (response.data.id) { + logger.info('Lidarr accepted request', { label: 'Lidarr' }); + } else { + logger.error('Failed to add album to Lidarr', { + label: 'Lidarr', + options, + }); + throw new Error('Failed to add album to Lidarr'); + } + album.id = response.data.id; } + logger.info('Monitoring album in Lidarr', { label: 'Lidarr' }); + response = await this.axios.put(`/album/monitor`, { + albumIds: [album.id], + monitored: true, + }); - logger.info('Starting search for album in Lidarr.', { label: 'Lidarr' }); + logger.info('Starting search for monitored album in Lidarr.', { + label: 'Lidarr', + }); - const response = await this.axios.post(`/command`, { + response = await this.axios.post(`/command`, { name: 'AlbumSearch', albumIds: [album.id], }); if (response.data.id) { - logger.info('Lidarr accepted request', { label: 'Lidarr' }); + logger.info('Lidarr accepted download request', { label: 'Lidarr' }); } else { - logger.error('Failed to add album to Lidarr', { + logger.error('Lidarr refused download request', { label: 'Lidarr', options, }); - throw new Error('Failed to add album to Lidarr'); + throw new Error('Lidarr refused download request'); } return response.data; } catch (e) {