From 3013fbdb2ea42974ddad5a3c32b370052367e55a Mon Sep 17 00:00:00 2001 From: Anatole Sot <47571181+ano0002@users.noreply.github.com> Date: Sat, 24 Feb 2024 19:40:09 +0100 Subject: [PATCH] Fixed request not working at all --- server/api/servarr/lidarr.ts | 77 ++++++++++++---------------- src/components/RequestCard/index.tsx | 2 +- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/server/api/servarr/lidarr.ts b/server/api/servarr/lidarr.ts index 9a4527fc1..83588fb83 100644 --- a/server/api/servarr/lidarr.ts +++ b/server/api/servarr/lidarr.ts @@ -153,7 +153,7 @@ export interface Medium { class LidarrAPI extends ServarrBase<{ musicId: number }> { static lastArtistsUpdate = 0; static artists: LidarrArtist[] = []; - static delay = 1000 * 60 * 5; + static delay = 1000 * 60; constructor({ url, apiKey }: { url: string; apiKey: string }) { super({ url, apiKey, cacheName: 'lidarr', apiName: 'Lidarr' }); if (LidarrAPI.lastArtistsUpdate < Date.now() - LidarrAPI.delay) { @@ -196,6 +196,28 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> { } }; + public async getArtistByMusicBrainzId(mbId: string): Promise { + try { + const response = await this.axios.get('/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 => { try { const response = await this.axios.get('/album'); @@ -254,64 +276,28 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> { try { 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(`/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) { 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' } ); + this.axios.post(`/command`, { + name: 'AlbumSearch', + albumIds: [album.id], + }); return album; } const artist = album.artist; + artist.monitored = true; artist.monitorNewItems = 'all'; artist.qualityProfileId = options.qualityProfileId; artist.rootFolderPath = options.rootFolderPath; artist.addOptions = { monitor: 'none', - searchForMissingAlbums: false, + searchForMissingAlbums: true, }; - album.anyReleaseOk = true; const response = await this.axios.post(`/album/`, { @@ -353,7 +339,7 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> { options: LidarrArtistOptions ): Promise => { try { - const artist = await this.getArtist(options.mbId); + const artist = await this.getArtistByMusicBrainzId(options.mbId); if (artist.id) { logger.info('Artist is already monitored in Lidarr. Skipping add.', { label: 'Lidarr', @@ -366,6 +352,7 @@ class LidarrAPI extends ServarrBase<{ musicId: number }> { const response = await this.axios.post('/artist', { ...artist, qualityProfileId: options.qualityProfileId, + metadataProfileId: options.profileId, monitored: true, monitorNewItems: options.monitorNewItems, rootFolderPath: options.rootFolderPath, diff --git a/src/components/RequestCard/index.tsx b/src/components/RequestCard/index.tsx index ced15e2b7..8033677f7 100644 --- a/src/components/RequestCard/index.tsx +++ b/src/components/RequestCard/index.tsx @@ -376,7 +376,7 @@ const RequestCard = ({ request, onTitleData }: RequestCardProps) => { : isTv(title) ? title.firstAirDate : isRelease(title) - ? title.date?.toDateString() + ? (title.date as string) : isArtist(title) ? title.beginDate : ''