/******************************************************************************************************************* * * Constrains the search to tracks contained in the given record. * * @param record the record * @return the {@code Finder}, in fluent fashion * ******************************************************************************************************************/ @Nonnull public default TrackFinder inRecord (final @Nonnull Record record) { return inRecord(record.getId()); } }
@Override @Nonnull public TrackFinder findTracks() { return configured(new RepositoryOptimizedTrackFinder(repository, trackCount)).inRecord(this); }
/******************************************************************************************************************* * * 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))); }