Content of file EmbeddedAudioMetadataImporter.java.html
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>EmbeddedAudioMetadataImporter.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">blueMarine II :: Media Scanner</a> > <a href="index.source.html" class="el_package">it.tidalwave.bluemarine2.metadata.impl.audio.embedded</a> > <span class="el_source">EmbeddedAudioMetadataImporter.java</span></div><h1>EmbeddedAudioMetadataImporter.java</h1><pre class="source lang-java linenums"><span class="fc" id="L1">/*</span>
* *********************************************************************************************************************
*
* blueMarine II: Semantic Media Centre
* http://tidalwave.it/projects/bluemarine2
*
* Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
*
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
* git clone https://bitbucket.org/tidalwave/bluemarine2-src
* git clone https://github.com/tidalwave-it/bluemarine2-src
*
* *********************************************************************************************************************
*/
package it.tidalwave.bluemarine2.metadata.impl.audio.embedded;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import javax.inject.Inject;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.vocabulary.DC;
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import it.tidalwave.util.ConcurrentHashMapWithOptionals;
import it.tidalwave.util.Id;
import it.tidalwave.util.TimeProvider;
import it.tidalwave.util.annotation.VisibleForTesting;
import it.tidalwave.messagebus.annotation.ListensTo;
import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
import it.tidalwave.bluemarine2.util.ModelBuilder;
import it.tidalwave.bluemarine2.model.MediaItem;
import it.tidalwave.bluemarine2.model.MediaItem.Metadata;
import it.tidalwave.bluemarine2.model.spi.PathAwareEntity;
import it.tidalwave.bluemarine2.model.vocabulary.*;
import it.tidalwave.bluemarine2.mediascanner.impl.MediaItemImportRequest;
import it.tidalwave.bluemarine2.mediascanner.impl.ProgressHandler;
import it.tidalwave.bluemarine2.mediascanner.impl.StatementManager;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.*;
import static it.tidalwave.bluemarine2.util.Formatters.*;
import static it.tidalwave.bluemarine2.util.RdfUtilities.*;
import static it.tidalwave.bluemarine2.model.MediaItem.Metadata.*;
/***********************************************************************************************************************
*
* This class generates RDF triples out of the {@link Metadata} embedded in an audio file.
*
* <pre>
* mo:AudioFile
* IRI computed from the fingerprint of the contents
* bm:importedFrom http://bluemarine.tidalwave.it/source#embedded
* rdfs:label the display name
* dc:title the title
* mo:encodes points to the signal
* bm:latestIndexingTime the latest import time
* bm:path the path of the file
* bm:fileSize the file size
* foaf:sha1 the fingerprint of the file
*
* mo:DigitalSignal
* IRI computed from the fingerprint of related file
* bm:importedFrom http://bluemarine.tidalwave.it/source#embedded
* mo:bitsPerSample the bits per sample
* mo:duration the duration
* mo:sample_rate the sample rate
* mo:published_as points to the Track
* MISSING mo:channels
* MISSING mo:time
* MISSING mo:trmid
*
* mo:Track
* IRI computed from the fingerprint of related file
* bm:importedFrom http://bluemarine.tidalwave.it/source#embedded
* rdfs:label the display name
* dc:title the title
* mo:track_number the track number in the record
* bm:discCount the number of disks in a collection
* bm:discNumber the index of the disk in a collection
* bm:iTunesCddb1 the CDDB1 attribute encoded by iTunes plus the track index
* foaf:maker points to the MusicArtists
*
* mo:Record
* IRI computed from the fingerprint of the name
* bm:importedFrom http://bluemarine.tidalwave.it/source#embedded
* rdfs:label the display name (ALBUM from audiofile metadata, or the name of the folder)
* dc:title the title (see above)
* mo:mediaType CD
* mo:track points to the Tracks
* bm:iTunesCddb1 the CDDB1 attribute encoded by iTunes
* foaf:maker points to the MusicArtists (union of the makers of Tracks)
* MISSING dc:date
* MISSING dc:language
* MISSING mo:release TODO points to the Label (EMI, etc...)
*
* mo:MusicArtist
* IRI computed from the fingerprint of the name
* bm:importedFrom http://bluemarine.tidalwave.it/source#embedded
* rdfs:label the display name
* foaf:name the name
* (in case of a group also the predicates below)
* dbtune:artist_type 2, which means a group
* purl:collaborates_with the MusicArtists in the group
* </pre>
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="fc" id="L135">@SimpleMessageSubscriber @Slf4j</span>
<span class="fc" id="L136">public class EmbeddedAudioMetadataImporter</span>
{
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
<span class="pc" id="L143"> @Immutable @RequiredArgsConstructor @Getter @ToString</span>
static class Pair
{
@Nonnull
<span class="fc" id="L147"> private final IRI iri;</span>
@Nonnull
<span class="fc" id="L150"> private final String name;</span>
}
@Inject
private StatementManager statementManager;
@Inject
private TimeProvider timeProvider;
@Inject
private ProgressHandler progress;
// Set would suffice, but there's no ConcurrentSet
<span class="fc" id="L163"> private final ConcurrentHashMapWithOptionals<IRI, Optional<String>> seenArtistUris =</span>
new ConcurrentHashMapWithOptionals<>();
<span class="fc" id="L166"> private final ConcurrentHashMapWithOptionals<IRI, Boolean> seenRecordUris = new ConcurrentHashMapWithOptionals<>();</span>
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
private void reset()
{
// FIXME: should load existing URIs from the Persistence