Update artist and added endpoints for every secondary type of music medias in routes

Anatole Sot 9 months ago
parent ff2509df48
commit 64cc39bae4

@ -6101,7 +6101,7 @@ paths:
/music/artist/{artistId}: /music/artist/{artistId}:
get: get:
summary: Get artist details summary: Get artist details
description: Returns full artist details in a JSON object. description: Returns artist details in a JSON object.
tags: tags:
- music - music
parameters: parameters:
@ -6111,6 +6111,12 @@ paths:
schema: schema:
type: string type: string
example: 87f17f8a-c0e2-406c-a149-8c8e311bf330 example: 87f17f8a-c0e2-406c-a149-8c8e311bf330
- in: query
name: full
schema:
type: boolean
example: false
default: false
responses: responses:
'200': '200':
description: Artist details description: Artist details
@ -6118,6 +6124,46 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ArtistResult' $ref: '#/components/schemas/ArtistResult'
/music/release/{releaseId}:
get:
summary: Get release details
description: Returns full release details in a JSON object.
tags:
- music
parameters:
- in: path
name: releaseId
required: true
schema:
type: string
example: 87f17f8a-c0e2-406c-a149-8c8e311bf330
responses:
'200':
description: Release details
content:
application/json:
schema:
$ref: '#/components/schemas/ReleaseResult'
/music/release-group/{releaseGroupId}:
get:
summary: Get release group details
description: Returns full release group details in a JSON object.
tags:
- music
parameters:
- in: path
name: releaseGroupId
required: true
schema:
type: string
example: 87f17f8a-c0e2-406c-a149-8c8e311bf330
responses:
'200':
description: Release Group details
content:
application/json:
schema:
$ref: '#/components/schemas/ReleaseGroupResult'
/media: /media:
get: get:
summary: Get media summary: Get media

@ -8,7 +8,7 @@ import type {
mbWork, mbWork,
} from '@server/api/musicbrainz/interfaces'; } from '@server/api/musicbrainz/interfaces';
import getPosterFromMB, { import getPosterFromMB, {
getFanartFromMB, cachedFanartFromMB,
} from '@server/api/musicbrainz/poster'; } from '@server/api/musicbrainz/poster';
import type { import type {
TmdbCollectionResult, TmdbCollectionResult,
@ -305,7 +305,7 @@ export const mapArtistResult = async (
tags: artist.tags, tags: artist.tags,
mediaInfo: media ?? undefined, mediaInfo: media ?? undefined,
posterPath: await getPosterFromMB(artist), posterPath: await getPosterFromMB(artist),
fanartPath: await getFanartFromMB(artist), fanartPath: await cachedFanartFromMB(artist),
}); });
export const mapReleaseResult = async ( export const mapReleaseResult = async (

@ -2,7 +2,11 @@ import MusicBrainz from '@server/api/musicbrainz';
import { MediaType } from '@server/constants/media'; import { MediaType } from '@server/constants/media';
import Media from '@server/entity/Media'; import Media from '@server/entity/Media';
import logger from '@server/logger'; import logger from '@server/logger';
import { mapArtistResult } from '@server/models/Search'; import {
mapArtistResult,
mapReleaseGroupResult,
mapReleaseResult,
} from '@server/models/Search';
import { Router } from 'express'; import { Router } from 'express';
const musicRoutes = Router(); const musicRoutes = Router();
@ -11,7 +15,9 @@ musicRoutes.get('/artist/:id', async (req, res, next) => {
const mb = new MusicBrainz(); const mb = new MusicBrainz();
try { try {
const artist = await mb.getArtist(req.params.id); const artist = req.query.full
? await mb.getFullArtist(req.params.id)
: await mb.getArtist(req.params.id);
const media = await Media.getMedia(artist.id, MediaType.MUSIC); const media = await Media.getMedia(artist.id, MediaType.MUSIC);
@ -29,4 +35,50 @@ musicRoutes.get('/artist/:id', async (req, res, next) => {
} }
}); });
musicRoutes.get('/release/:id', async (req, res, next) => {
const mb = new MusicBrainz();
try {
const release = await mb.getRelease(req.params.id);
const media = await Media.getMedia(release.id, MediaType.MUSIC);
return res.status(200).json(await mapReleaseResult(release, media));
} catch (e) {
logger.debug('Something went wrong retrieving release', {
label: 'API',
errorMessage: e.message,
releaseId: req.params.id,
});
return next({
status: 500,
message: 'Unable to retrieve release.',
});
}
});
musicRoutes.get('/release-group/:id', async (req, res, next) => {
const mb = new MusicBrainz();
try {
const releaseGroup = await mb.getReleaseGroup(req.params.id);
const media = await Media.getMedia(releaseGroup.id, MediaType.MUSIC);
return res
.status(200)
.json(await mapReleaseGroupResult(releaseGroup, media));
} catch (e) {
logger.debug('Something went wrong retrieving release group', {
label: 'API',
errorMessage: e.message,
releaseGroupId: req.params.id,
});
return next({
status: 500,
message: 'Unable to retrieve release group.',
});
}
});
export default musicRoutes; export default musicRoutes;

Loading…
Cancel
Save