final Cddb cddb = Cddb.builder() .discId("") // FIXME .trackFrameOffsets(
/*********************************************************************************************************** * * Returns {@code true} if this object matches the other CDDB within a given threshold. * * @param other the other CDDB * @param threshold the threshold of the comparison * @return {@code true} if this object matches * **********************************************************************************************************/ public boolean matches (final @Nonnull Cddb other, final @Nonnegative int threshold) { if (Arrays.equals(this.trackFrameOffsets, other.trackFrameOffsets)) { return true; } if (!this.sameTrackCountOf(other)) { return false; } return this.computeDifference(other) <= threshold; }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull private IRI signalIriFor (final @Nonnull Cddb cddb, final @Nonnegative int trackNumber) { return BMMO.signalIriFor(createSha1IdNew(cddb.getToc() + "/" + trackNumber)); }
final String toc = cddb.getToc();
unmatched.add(recordName + " / " + metadata.get(CDDB).get().getToc());
final Optional<String> dTitle = album.getProperty("DTITLE"); if (!albumCddb.matches(requestedCddb, trackOffsetsMatchThreshold)) log.debug(">>>>>>>> found track offsets: {}", albumCddb.getTrackFrameOffsets()); log.debug(">>>>>>>> searched track offsets: {}", requestedCddb.getTrackFrameOffsets()); log.debug(">>>>>>>> ppm {}", albumCddb.computeDifference(requestedCddb));
final boolean matches = requestedCddb.matches(cddb, trackOffsetsMatchThreshold); log.debug(">>>>>>>> iTunes offsets: {}", requestedCddb.getTrackFrameOffsets()); log.debug(">>>>>>>> found offsets: {}", cddb.getTrackFrameOffsets());
/*********************************************************************************************************** * * Returns the same data in form of a CDDB. * * @return the CDDB * **********************************************************************************************************/ @Nonnull public Cddb getCddb() { return Cddb.builder().discId(cddb1.split("\\+")[0]) .discLength(Integer.parseInt(cddb1.split("\\+")[1])) .trackFrameOffsets(Stream.of(cddb1.split("\\+")) .skip(3) .mapToInt(Integer::parseInt) .toArray()) .build(); }
/*************************************************************************************************************** * **************************************************************************************************************/ @Nonnull public Cddb getCddb() { return MediaItem.Metadata.Cddb.builder() .discId("") // FIXME .trackFrameOffsets(disc.getOffsetList().getOffset() .stream() .map(offset -> offset.getValue()) .mapToInt(x -> x.intValue()) .toArray()) .build(); }
/******************************************************************************************************************* * * FIXME: DUPLICATED FROM EmbbededAudioMetadataImporter * ******************************************************************************************************************/ @Nonnull private static IRI recordIriOf (final @Nonnull Metadata metadata, final @Nonnull String recordTitle) { final Optional<Cddb> cddb = metadata.get(CDDB); return BMMO.recordIriFor((cddb.isPresent()) ? createSha1IdNew(cddb.get().getToc()) : createSha1IdNew("RECORD:" + recordTitle)); }
@Nonnull public String toDumpString() { return "CddbAlbum\n" + "trackFrameOffsets: " + Arrays.stream(cddb.getTrackFrameOffsets()) .mapToObj(String::valueOf) .collect(joining(" ")) + "\n" + "discLenght: " + cddb.getDiscLength() + "\n" + properties.entrySet().stream() .map(e -> String.format("%s: %s", e.getKey(), e.getValue())) .collect(joining("\n")); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull private RestResponse<CddbAlbum> findCddbAlbum (final @Nonnull Cddb cddb) throws IOException, InterruptedException { final String discId = cddb.getDiscId(); final ResponseEntity<String> response = request(String.format(FREEDB_URL_TEMPLATE, host, discId)); return CddbResponse.of(response, CddbAlbum::of); } }