/*********************************************************************************************************** * * Factory method extracting data from a string representation. * * @param string the string source * @return the {@code ITunesComment} * **********************************************************************************************************/ @Nonnull public static ITunesComment fromToString (final @Nonnull String string) { final Matcher matcher = PATTERN_TO_STRING.matcher(string); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid string: " + string); } return new ITunesComment(matcher.group(1), matcher.group(2)); }
/*********************************************************************************************************** * * Factory method extracting data from a {@link Metadata} instance. * * @param metadata the data source * @return the {@code ITunesComment} * **********************************************************************************************************/ @Nonnull public static Optional<ITunesComment> from (final @Nonnull Metadata metadata) { return metadata.get(ENCODER).flatMap( encoders -> encoders.stream().anyMatch(encoder -> encoder.startsWith("iTunes")) ? metadata.get(COMMENT).flatMap(comments -> from(comments)) : Optional.empty()); }
metadata = metadata.with(ITUNES_COMMENT, ITunesComment.from(metadata));
final Cddb requestedCddb = metadata.get(ITUNES_COMMENT).get().getCddb(); final Optional<String> dTitle = album.getProperty("DTITLE");
lines.stream().filter(s -> s.contains("[iTunes.comment]")) .findFirst() .map(s -> ITunesComment.fromToString(s.replaceAll("^.* = ", "")));
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public <T> MediaItem.Metadata with (final @Nonnull Key<T> key, final @Nonnull T value) { final MetadataSupport clone = new MetadataSupport(path, fallback); clone.properties.putAll(this.properties); clone.put(key, value); if (value instanceof ITunesComment) { clone.put(CDDB, ((ITunesComment) value).getCddb()); } return clone; }
/*********************************************************************************************************** * * Factory method extracting data from a string representation as in the iTunes Comment MP3 tag. * * @param comments the source * @return the {@code ITunesComment} * **********************************************************************************************************/ @Nonnull private static Optional<ITunesComment> from (final @Nonnull List <String> comments) { return comments.get(comments.size() - 2).contains("+") ? Optional.of(new ITunesComment(comments.get(3), comments.get(4))) : Optional.empty(); } }