/******************************************************************************************************************* * * Exports track resources. * * @param source the data source * @param fallback the fallback data source * @return the JSON representation of the tracks * ******************************************************************************************************************/ @ResponseBody @RequestMapping(value = "/track", produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE }) public List<TrackResource> getTracks (final @RequestParam(required = false, defaultValue = "embedded") String source, final @RequestParam(required = false, defaultValue = "embedded") String fallback) { log.info("getTracks({}, {})", source, fallback); checkStatus(); return finalized(catalog.findTracks(), source, fallback, TrackResource::new); }
public RepositoryBrowserByTrack() { super(catalog -> catalog.findTracks().sort(new ByTrackName())); } }
/******************************************************************************************************************* * * Exports a single track resource. * * @param id the track id * @param source the data source * @param fallback the fallback data source * @return the JSON representation of the track * ******************************************************************************************************************/ @ResponseBody @RequestMapping(value = "/track/{id}", produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE }) public TrackResource getTrack (final @PathVariable String id, final @RequestParam(required = false, defaultValue = "embedded") String source, final @RequestParam(required = false, defaultValue = "embedded") String fallback) { log.info("getTrack({}, {}, {})", id, source, fallback); checkStatus(); return single(finalized(catalog.findTracks().withId(new Id(id)), source, fallback, TrackResource::new)); }
/******************************************************************************************************************* * * Exports the cover art of a record. * * @param id the record id * @return the cover art image * ******************************************************************************************************************/ @RequestMapping(value = "/record/{id}/coverart") public ResponseEntity<byte[]> getRecordCoverArt (final @PathVariable String id) { log.info("getRecordCoverArt({})", id); checkStatus(); return catalog.findTracks().inRecord(new Id(id)) .stream() .flatMap(track -> track.asMany(AudioFileSupplier).stream()) .map(afs -> afs.getAudioFile()) .flatMap(af -> af.getMetadata().getAll(ARTWORK).stream()) .findAny() .map(bytes -> bytesResponse(bytes, "image", "jpeg", "coverart.jpg")) .orElseThrow(NotFoundException::new); }
/******************************************************************************************************************* * * Exports a single record resource. * * @param id the record id * @param source the data source * @param fallback the fallback data source * @return the JSON representation of the record * ******************************************************************************************************************/ @ResponseBody @RequestMapping(value = "/record/{id}", produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE }) public DetailedRecordResource getRecord (final @PathVariable String id, final @RequestParam(required = false, defaultValue = "embedded") String source, final @RequestParam(required = false, defaultValue = "embedded") String fallback) { log.info("getRecord({}, {}, {})", id, source, fallback); checkStatus(); final List<TrackResource> tracks = finalized(catalog.findTracks().inRecord(new Id(id)), source, fallback, TrackResource::new); return single(finalized(catalog.findRecords().withId(new Id(id)), source, fallback, record -> new DetailedRecordResource(record, tracks))); }