Skip to content

Commit

Permalink
fix(lidarr api): fixed Lidarr API not working when adding albums
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ano0002 committed Aug 18, 2024
1 parent f115bd3 commit 183e221
Showing 1 changed file with 53 additions and 40 deletions.
93 changes: 53 additions & 40 deletions server/api/servarr/lidarr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,62 +278,75 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> {
options: LidarrAlbumOptions
): Promise<LidarrAlbum> => {
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<LidarrAlbum>(`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<LidarrAlbum>(`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) {
Expand Down

0 comments on commit 183e221

Please sign in to comment.