You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
overseerr/server/api/musicbrainz/poster.ts

55 lines
1.8 KiB

import LidarrAPI from '@server/api/servarr/lidarr';
import { getSettings } from '@server/lib/settings';
import type { mbArtist, mbRelease, mbReleaseGroup } from './interfaces';
function getPosterFromMB(
element: mbRelease | mbReleaseGroup | mbArtist
): string | undefined {
if (element.media_type === 'artist') {
const settings = getSettings();
const lidarrSettings = settings.lidarr.find((lidarr) => lidarr.isDefault);
if (!lidarrSettings) {
throw new Error('No default Lidarr instance found');
}
const lidarr: LidarrAPI = new LidarrAPI({
apiKey: lidarrSettings.apiKey,
url: LidarrAPI.buildUrl(lidarrSettings, '/api/v1'),
});
try {
const artist = (lidarr as LidarrAPI).getArtist(element.id);
return LidarrAPI.buildUrl(
lidarrSettings,
(artist.images ?? [{ coverType: 'poster', url: undefined }]).find(
(i) => i.coverType === 'poster'
)?.url
);
} catch (e) {
return undefined;
}
}
return `https://coverartarchive.org/${element.media_type}/${element.id}/front-250.jpg`;
}
async function getFanartFromMB(element: mbArtist): Promise<string | undefined> {
const settings = getSettings();
const lidarrSettings = settings.lidarr.find((lidarr) => lidarr.isDefault);
if (!lidarrSettings) {
throw new Error('No default Lidarr instance found');
}
const lidarr = new LidarrAPI({
apiKey: lidarrSettings.apiKey,
url: LidarrAPI.buildUrl(lidarrSettings, '/api/v1'),
});
try {
const artist = lidarr.getArtist(element.id);
return (
artist.images ?? [{ coverType: 'fanart', remoteUrl: undefined }]
).filter((i) => i.coverType === 'fanart')[0].remoteUrl;
} catch (e) {
return undefined;
}
}
export default getPosterFromMB;
export { getFanartFromMB };