Fixed request not working at all

Anatole Sot 7 months ago
parent 8507c09e0f
commit 3013fbdb2e

@ -153,7 +153,7 @@ export interface Medium {
class LidarrAPI extends ServarrBase<{ musicId: number }> { class LidarrAPI extends ServarrBase<{ musicId: number }> {
static lastArtistsUpdate = 0; static lastArtistsUpdate = 0;
static artists: LidarrArtist[] = []; static artists: LidarrArtist[] = [];
static delay = 1000 * 60 * 5; static delay = 1000 * 60;
constructor({ url, apiKey }: { url: string; apiKey: string }) { constructor({ url, apiKey }: { url: string; apiKey: string }) {
super({ url, apiKey, cacheName: 'lidarr', apiName: 'Lidarr' }); super({ url, apiKey, cacheName: 'lidarr', apiName: 'Lidarr' });
if (LidarrAPI.lastArtistsUpdate < Date.now() - LidarrAPI.delay) { if (LidarrAPI.lastArtistsUpdate < Date.now() - LidarrAPI.delay) {
@ -196,6 +196,28 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> {
} }
}; };
public async getArtistByMusicBrainzId(mbId: string): Promise<LidarrArtist> {
try {
const response = await this.axios.get<LidarrArtist[]>('/artist/lookup', {
params: {
term: `mbid:` + mbId,
},
});
if (!response.data[0]) {
throw new Error('Artist not found');
}
return response.data[0];
} catch (e) {
logger.error('Error retrieving artist by MusicBrainz ID', {
label: 'Midarr API',
errorMessage: e.message,
mbId: mbId,
});
throw new Error('Artist not found');
}
}
public getAlbums = async (): Promise<LidarrAlbum[]> => { public getAlbums = async (): Promise<LidarrAlbum[]> => {
try { try {
const response = await this.axios.get<LidarrAlbum[]>('/album'); const response = await this.axios.get<LidarrAlbum[]>('/album');
@ -254,64 +276,28 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> {
try { try {
const album = await this.getAlbumByMusicBrainzId(options.mbId); const album = await this.getAlbumByMusicBrainzId(options.mbId);
// album exists in Lidarr but is neither downloaded nor monitored
if (album.id && !album.monitored) {
const response = await this.axios.post<LidarrAlbum>(`/album`, {
...album,
title: options.title,
qualityProfileId: options.qualityProfileId,
profileId: options.profileId,
foreignAlbumId: options.mbId.toString(),
tags: options.tags,
rootFolderPath: options.rootFolderPath,
monitored: options.monitored,
addOptions: {
searchForNewAlbum: options.searchNow,
},
});
if (response.data.monitored) {
logger.info(
'Found existing title in Lidarr and set it to monitored.',
{
label: 'Lidarr',
albumId: response.data.id,
albumTitle: response.data.title,
}
);
logger.debug('Lidarr update details', {
label: 'Lidarr',
album: response.data,
});
return response.data;
} else {
logger.error('Failed to update existing album in Lidarr.', {
label: 'Lidarr',
options,
});
throw new Error('Failed to update existing album in Lidarr');
}
}
if (album.id) { if (album.id) {
logger.info( logger.info(
'Album is already monitored in Lidarr. Skipping add and returning success', 'Album is already monitored in Lidarr. Starting search for download.',
{ label: 'Lidarr' } { label: 'Lidarr' }
); );
this.axios.post(`/command`, {
name: 'AlbumSearch',
albumIds: [album.id],
});
return album; return album;
} }
const artist = album.artist; const artist = album.artist;
artist.monitored = true; artist.monitored = true;
artist.monitorNewItems = 'all'; artist.monitorNewItems = 'all';
artist.qualityProfileId = options.qualityProfileId; artist.qualityProfileId = options.qualityProfileId;
artist.rootFolderPath = options.rootFolderPath; artist.rootFolderPath = options.rootFolderPath;
artist.addOptions = { artist.addOptions = {
monitor: 'none', monitor: 'none',
searchForMissingAlbums: false, searchForMissingAlbums: true,
}; };
album.anyReleaseOk = true; album.anyReleaseOk = true;
const response = await this.axios.post<LidarrAlbum>(`/album/`, { const response = await this.axios.post<LidarrAlbum>(`/album/`, {
@ -353,7 +339,7 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> {
options: LidarrArtistOptions options: LidarrArtistOptions
): Promise<LidarrArtist> => { ): Promise<LidarrArtist> => {
try { try {
const artist = await this.getArtist(options.mbId); const artist = await this.getArtistByMusicBrainzId(options.mbId);
if (artist.id) { if (artist.id) {
logger.info('Artist is already monitored in Lidarr. Skipping add.', { logger.info('Artist is already monitored in Lidarr. Skipping add.', {
label: 'Lidarr', label: 'Lidarr',
@ -366,6 +352,7 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> {
const response = await this.axios.post<LidarrArtist>('/artist', { const response = await this.axios.post<LidarrArtist>('/artist', {
...artist, ...artist,
qualityProfileId: options.qualityProfileId, qualityProfileId: options.qualityProfileId,
metadataProfileId: options.profileId,
monitored: true, monitored: true,
monitorNewItems: options.monitorNewItems, monitorNewItems: options.monitorNewItems,
rootFolderPath: options.rootFolderPath, rootFolderPath: options.rootFolderPath,

@ -376,7 +376,7 @@ const RequestCard = ({ request, onTitleData }: RequestCardProps) => {
: isTv(title) : isTv(title)
? title.firstAirDate ? title.firstAirDate
: isRelease(title) : isRelease(title)
? title.date?.toDateString() ? (title.date as string)
: isArtist(title) : isArtist(title)
? title.beginDate ? title.beginDate
: '' : ''

Loading…
Cancel
Save