public RepositoryBrowserByRecordThenTrack() { super(catalog -> catalog.findRecords()); } }
public RepositoryBrowserByArtistSupport() { super(catalog -> catalog.findArtists()); } }
/******************************************************************************************************************* * * 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))); }
/******************************************************************************************************************* * * 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); }
/******************************************************************************************************************* * * Exports audio file resources. * * @param source the data source * @param fallback the fallback data source * @return the JSON representation of the audio files * ******************************************************************************************************************/ @ResponseBody @RequestMapping(value = "/audiofile", produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE }) public List<AudioFileResource> getAudioFiles (final @RequestParam(required = false, defaultValue = "embedded") String source, final @RequestParam(required = false, defaultValue = "embedded") String fallback) { log.info("getAudioFiles({}, {})", source, fallback); checkStatus(); return finalized(catalog.findAudioFiles(), source, fallback, AudioFileResource::new); }
public RepositoryBrowserByTrack() { super(catalog -> catalog.findTracks().sort(new ByTrackName())); } }
/******************************************************************************************************************* * * @param id the audio file id * @return the binary contents * ******************************************************************************************************************/ @RequestMapping(value = "/audiofile/{id}/coverart") public ResponseEntity<byte[]> getAudioFileCoverArt (final @PathVariable String id) { log.info("getAudioFileCoverArt({})", id); checkStatus(); final Optional<AudioFile> audioFile = catalog.findAudioFiles().withId(new Id(id)).optionalResult(); log.debug(">>>> audioFile: {}", audioFile); return audioFile.flatMap(file -> file.getMetadata().getAll(ARTWORK).stream().findFirst()) .map(bytes -> bytesResponse(bytes, "image", "jpeg", "coverart.jpg")) .orElseThrow(NotFoundException::new); }
/******************************************************************************************************************* * * 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 record resources. * * @param source the data source * @param fallback the fallback data source * @return the JSON representation of the records * ******************************************************************************************************************/ @ResponseBody @RequestMapping(value = "/record", produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE }) public List<RecordResource> getRecords (final @RequestParam(required = false, defaultValue = "embedded") String source, final @RequestParam(required = false, defaultValue = "embedded") String fallback) { log.info("getRecords({}, {})", source, fallback); checkStatus(); return finalized(catalog.findRecords(), source, fallback, RecordResource::new); }
/******************************************************************************************************************* * * Exports a single audio file resource. * * @param id the audio file id * @param source the data source * @param fallback the fallback data source * @return the JSON representation of the audio file * ******************************************************************************************************************/ @ResponseBody @RequestMapping(value = "/audiofile/{id}", produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE }) public AudioFileResource getAudioFile (final @PathVariable String id, final @RequestParam(required = false, defaultValue = "embedded") String source, final @RequestParam(required = false, defaultValue = "embedded") String fallback) { log.info("getAudioFile({}, {}, {})", id, source, fallback); checkStatus(); return single(finalized(catalog.findAudioFiles().withId(new Id(id)), source, fallback, AudioFileResource::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); }
/******************************************************************************************************************* * * @param id the audio file id * @param rangeHeader the "Range" HTTP header * @return the binary contents * ******************************************************************************************************************/ @RequestMapping(value = "/audiofile/{id}/content") public ResponseEntity<ResourceRegion> getAudioFileContent ( final @PathVariable String id, final @RequestHeader(name = "Range", required = false) String rangeHeader) { log.info("getAudioFileContent({})", id); checkStatus(); return catalog.findAudioFiles().withId(new Id(id)).optionalResult() .map(_f(af -> audioFileContentResponse(af, rangeHeader))) .orElseThrow(NotFoundException::new); }