Commit 1617a814 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

IParserService: Use IItem instead of a plain Item

parent aa2e48aa
......@@ -69,7 +69,7 @@ bool MetadataParser::initialize( MediaLibrary* ml)
return cacheUnknownArtist();
}
int MetadataParser::toInt( parser::Task::Item& item, parser::Task::Item::Metadata meta )
int MetadataParser::toInt( parser::IItem& item, parser::IItem::Metadata meta )
{
auto str = item.meta( meta );
if ( str.empty() == false )
......@@ -81,14 +81,14 @@ int MetadataParser::toInt( parser::Task::Item& item, parser::Task::Item::Metadat
catch( std::logic_error& ex)
{
LOG_WARN( "Invalid meta #",
static_cast<typename std::underlying_type<parser::Task::Item::Metadata>::type>( meta ),
static_cast<typename std::underlying_type<parser::IItem::Metadata>::type>( meta ),
" provided (", str, "): ", ex.what() );
}
}
return 0;
}
parser::Task::Status MetadataParser::run( parser::Task::Item& item )
parser::Task::Status MetadataParser::run( parser::IItem& item )
{
bool alreadyInParser = false;
int nbSubitem = item.nbSubItems();
......@@ -183,7 +183,7 @@ parser::Task::Status MetadataParser::run( parser::Task::Item& item )
auto t = m_ml->getConn()->newTransaction();
for ( const auto& track : tracks )
{
if ( track.type == parser::Task::Item::Track::Type::Video )
if ( track.type == parser::IItem::Track::Type::Video )
{
item.media()->addVideoTrack( track.codec, track.v.width, track.v.height,
static_cast<float>( track.v.fpsNum ) /
......@@ -193,7 +193,7 @@ parser::Task::Status MetadataParser::run( parser::Task::Item& item )
}
else
{
assert( track.type == parser::Task::Item::Track::Type::Audio );
assert( track.type == parser::IItem::Track::Type::Audio );
item.media()->addAudioTrack( track.codec, track.bitrate,
track.a.rate, track.a.nbChannels,
track.language, track.description );
......@@ -223,7 +223,7 @@ parser::Task::Status MetadataParser::run( parser::Task::Item& item )
/* Playlist files */
bool MetadataParser::addPlaylistMedias( parser::Task::Item& item ) const
bool MetadataParser::addPlaylistMedias( parser::IItem& item ) const
{
const auto& mrl = item.mrl();
LOG_INFO( "Try to import ", mrl, " as a playlist" );
......@@ -246,7 +246,7 @@ bool MetadataParser::addPlaylistMedias( parser::Task::Item& item ) const
}
else
{
auto playlistName = item.meta( parser::Task::Item::Metadata::Title );
auto playlistName = item.meta( parser::IItem::Metadata::Title );
if ( playlistName.empty() == true )
playlistName = utils::url::decode( utils::file::fileName( mrl ) );
auto t = m_ml->getConn()->newTransaction();
......@@ -281,7 +281,7 @@ bool MetadataParser::addPlaylistMedias( parser::Task::Item& item ) const
return true;
}
void MetadataParser::addPlaylistElement( parser::Task::Item& item,
void MetadataParser::addPlaylistElement( parser::IItem& item,
std::shared_ptr<Playlist> playlistPtr,
const parser::IItem& subitem ) const
{
......@@ -301,7 +301,7 @@ void MetadataParser::addPlaylistElement( parser::Task::Item& item,
{
auto t2 = m_ml->getConn()->newTransaction();
auto externalMedia = Media::create( m_ml, IMedia::Type::Unknown, utils::url::encode(
subitem.meta( parser::Task::Item::Metadata::Title ) ) );
subitem.meta( parser::IItem::Metadata::Title ) ) );
if ( externalMedia == nullptr )
{
LOG_ERROR( "Failed to create external media for ", mrl, " in the playlist ", item.mrl() );
......@@ -366,16 +366,16 @@ void MetadataParser::addPlaylistElement( parser::Task::Item& item,
/* Video files */
bool MetadataParser::parseVideoFile( parser::Task::Item& item ) const
bool MetadataParser::parseVideoFile( parser::IItem& item ) const
{
auto media = item.media().get();
media->setType( IMedia::Type::Video );
const auto& title = item.meta( parser::Task::Item::Metadata::Title );
const auto& title = item.meta( parser::IItem::Metadata::Title );
if ( title.length() == 0 )
return true;
const auto& showName = item.meta( parser::Task::Item::Metadata::ShowName );
const auto& artworkMrl = item.meta( parser::Task::Item::Metadata::ArtworkUrl );
const auto& showName = item.meta( parser::IItem::Metadata::ShowName );
const auto& artworkMrl = item.meta( parser::IItem::Metadata::ArtworkUrl );
return sqlite::Tools::withRetries( 3, [this, &showName, &title, &item, &artworkMrl]() {
auto t = m_ml->getConn()->newTransaction();
......@@ -393,7 +393,7 @@ bool MetadataParser::parseVideoFile( parser::Task::Item& item ) const
if ( show == nullptr )
return false;
}
auto episode = toInt( item, parser::Task::Item::Metadata::Episode );
auto episode = toInt( item, parser::IItem::Metadata::Episode );
if ( episode != 0 )
{
std::shared_ptr<Show> s = std::static_pointer_cast<Show>( show );
......@@ -413,11 +413,11 @@ bool MetadataParser::parseVideoFile( parser::Task::Item& item ) const
/* Audio files */
bool MetadataParser::parseAudioFile( parser::Task::Item& item )
bool MetadataParser::parseAudioFile( parser::IItem& item )
{
item.media()->setType( IMedia::Type::Audio );
auto artworkMrl = item.meta( parser::Task::Item::Metadata::ArtworkUrl );
auto artworkMrl = item.meta( parser::IItem::Metadata::ArtworkUrl );
if ( artworkMrl.empty() == false )
{
item.media()->setThumbnail( artworkMrl, Thumbnail::Origin::Media );
......@@ -437,7 +437,7 @@ bool MetadataParser::parseAudioFile( parser::Task::Item& item )
auto t = m_ml->getConn()->newTransaction();
if ( album == nullptr )
{
const auto& albumName = item.meta( parser::Task::Item::Metadata::Album );
const auto& albumName = item.meta( parser::IItem::Metadata::Album );
int64_t thumbnailId = 0;
if ( artworkMrl.empty() == false )
{
......@@ -462,9 +462,9 @@ bool MetadataParser::parseAudioFile( parser::Task::Item& item )
}, std::move( artworkMrl ), std::move( album ), std::move( genre ) );
}
std::shared_ptr<Genre> MetadataParser::handleGenre( parser::Task::Item& item ) const
std::shared_ptr<Genre> MetadataParser::handleGenre( parser::IItem& item ) const
{
const auto& genreStr = item.meta( parser::Task::Item::Metadata::Genre );
const auto& genreStr = item.meta( parser::IItem::Metadata::Genre );
if ( genreStr.length() == 0 )
return nullptr;
auto genre = Genre::fromName( m_ml, genreStr );
......@@ -479,10 +479,10 @@ std::shared_ptr<Genre> MetadataParser::handleGenre( parser::Task::Item& item ) c
/* Album handling */
std::shared_ptr<Album> MetadataParser::findAlbum( parser::Task::Item& item, std::shared_ptr<Artist> albumArtist,
std::shared_ptr<Album> MetadataParser::findAlbum( parser::IItem& item, std::shared_ptr<Artist> albumArtist,
std::shared_ptr<Artist> trackArtist )
{
const auto& albumName = item.meta( parser::Task::Item::Metadata::Album );
const auto& albumName = item.meta( parser::IItem::Metadata::Album );
if ( albumName.empty() == true )
{
if ( albumArtist != nullptr )
......@@ -507,8 +507,8 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::Task::Item& item, std:
if ( albums.size() == 0 )
return nullptr;
const auto discTotal = toInt( item, parser::Task::Item::Metadata::DiscTotal );
const auto discNumber = toInt( item, parser::Task::Item::Metadata::DiscNumber );
const auto discTotal = toInt( item, parser::IItem::Metadata::DiscTotal );
const auto discNumber = toInt( item, parser::IItem::Metadata::DiscNumber );
/*
* Even if we get only 1 album, we need to filter out invalid matches.
* For instance, if we have already inserted an album "A" by an artist "john"
......@@ -605,7 +605,7 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::Task::Item& item, std:
// tagged with a year.
if ( multipleArtists == false )
{
auto candidateDate = item.meta( parser::Task::Item::Metadata::Date );
auto candidateDate = item.meta( parser::IItem::Metadata::Date );
if ( candidateDate.empty() == false )
{
try
......@@ -651,14 +651,14 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::Task::Item& item, std:
/// The album artist as a first element
/// The track artist as a second element, or nullptr if it is the same as album artist
///
std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> MetadataParser::findOrCreateArtist( parser::Task::Item& item ) const
std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> MetadataParser::findOrCreateArtist( parser::IItem& item ) const
{
std::shared_ptr<Artist> albumArtist;
std::shared_ptr<Artist> artist;
static const std::string req = "SELECT * FROM " + policy::ArtistTable::Name + " WHERE name = ?";
const auto& albumArtistStr = item.meta( parser::Task::Item::Metadata::AlbumArtist );
const auto& artistStr = item.meta( parser::Task::Item::Metadata::Artist );
const auto& albumArtistStr = item.meta( parser::IItem::Metadata::AlbumArtist );
const auto& artistStr = item.meta( parser::IItem::Metadata::Artist );
if ( albumArtistStr.empty() == true && artistStr.empty() == true )
{
return {m_unknownArtist, m_unknownArtist};
......@@ -697,14 +697,14 @@ std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> MetadataParser::find
/* Tracks handling */
std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album> album, parser::Task::Item& item,
std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album> album, parser::IItem& item,
std::shared_ptr<Artist> artist, Genre* genre ) const
{
assert( sqlite::Transaction::transactionInProgress() == true );
auto title = item.meta( parser::Task::Item::Metadata::Title );
const auto trackNumber = toInt( item, parser::Task::Item::Metadata::TrackNumber );
const auto discNumber = toInt( item, parser::Task::Item::Metadata::DiscNumber );
auto title = item.meta( parser::IItem::Metadata::Title );
const auto trackNumber = toInt( item, parser::IItem::Metadata::TrackNumber );
const auto discNumber = toInt( item, parser::IItem::Metadata::DiscNumber );
if ( title.empty() == true )
{
LOG_WARN( "Failed to get track title" );
......@@ -726,7 +726,7 @@ std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album>
return nullptr;
}
const auto& releaseDate = item.meta( parser::Task::Item::Metadata::Date );
const auto& releaseDate = item.meta( parser::IItem::Metadata::Date );
if ( releaseDate.empty() == false )
{
auto releaseYear = atoi( releaseDate.c_str() );
......
......@@ -38,28 +38,28 @@ public:
protected:
bool cacheUnknownArtist();
virtual bool initialize( MediaLibrary* ml ) override;
virtual parser::Task::Status run( parser::Task::Item& item ) override;
virtual parser::Task::Status run( parser::IItem& item ) override;
virtual const char* name() const override;
virtual uint8_t nbThreads() const override;
virtual void onFlushing() override;
virtual void onRestarted() override;
virtual parser::Task::ParserStep targetedStep() const override;
bool addPlaylistMedias( parser::Task::Item& item ) const;
void addPlaylistElement( parser::Task::Item& item, std::shared_ptr<Playlist> playlistPtr,
bool addPlaylistMedias( parser::IItem& item ) const;
void addPlaylistElement( parser::IItem& item, std::shared_ptr<Playlist> playlistPtr,
const parser::IItem& subitem ) const;
bool parseAudioFile( parser::Task::Item& task );
bool parseVideoFile( parser::Task::Item& task ) const;
std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> findOrCreateArtist( parser::Task::Item& item ) const;
std::shared_ptr<AlbumTrack> handleTrack( std::shared_ptr<Album> album, parser::Task::Item& item,
bool parseAudioFile( parser::IItem& task );
bool parseVideoFile( parser::IItem& task ) const;
std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> findOrCreateArtist( parser::IItem& item ) const;
std::shared_ptr<AlbumTrack> handleTrack( std::shared_ptr<Album> album, parser::IItem& item,
std::shared_ptr<Artist> artist, Genre* genre ) const;
bool link(Media& media, std::shared_ptr<Album> album, std::shared_ptr<Artist> albumArtist, std::shared_ptr<Artist> artist );
std::shared_ptr<Album> findAlbum( parser::Task::Item& item, std::shared_ptr<Artist> albumArtist,
std::shared_ptr<Album> findAlbum( parser::IItem& item, std::shared_ptr<Artist> albumArtist,
std::shared_ptr<Artist> artist );
std::shared_ptr<Genre> handleGenre( parser::Task::Item& item ) const;
std::shared_ptr<Genre> handleGenre( parser::IItem& item ) const;
private:
static int toInt( parser::Task::Item& item, parser::Task::Item::Metadata meta );
static int toInt( parser::IItem& item, parser::IItem::Metadata meta );
private:
MediaLibrary* m_ml;
......
......@@ -45,7 +45,7 @@ bool VLCMetadataService::initialize( MediaLibrary* )
return true;
}
parser::Task::Status VLCMetadataService::run( parser::Task::Item& item )
parser::Task::Status VLCMetadataService::run( parser::IItem& item )
{
auto mrl = item.mrl();
LOG_INFO( "Parsing ", mrl );
......@@ -117,46 +117,46 @@ parser::Task::ParserStep VLCMetadataService::targetedStep() const
void VLCMetadataService::mediaToItem( VLC::Media& media, parser::IItem& item )
{
item.setMeta( parser::Task::Item::Metadata::Title,
item.setMeta( parser::IItem::Metadata::Title,
media.meta( libvlc_meta_Title ) );
item.setMeta( parser::Task::Item::Metadata::ArtworkUrl,
item.setMeta( parser::IItem::Metadata::ArtworkUrl,
media.meta( libvlc_meta_ArtworkURL ) );
item.setMeta( parser::Task::Item::Metadata::ShowName,
item.setMeta( parser::IItem::Metadata::ShowName,
media.meta( libvlc_meta_ShowName ) );
item.setMeta( parser::Task::Item::Metadata::Episode,
item.setMeta( parser::IItem::Metadata::Episode,
media.meta( libvlc_meta_Episode ) );
item.setMeta( parser::Task::Item::Metadata::Album,
item.setMeta( parser::IItem::Metadata::Album,
media.meta( libvlc_meta_Album ) );
item.setMeta( parser::Task::Item::Metadata::Genre,
item.setMeta( parser::IItem::Metadata::Genre,
media.meta( libvlc_meta_Genre ) );
item.setMeta( parser::Task::Item::Metadata::Date,
item.setMeta( parser::IItem::Metadata::Date,
media.meta( libvlc_meta_Date ) );
item.setMeta( parser::Task::Item::Metadata::AlbumArtist,
item.setMeta( parser::IItem::Metadata::AlbumArtist,
media.meta( libvlc_meta_AlbumArtist ) );
item.setMeta( parser::Task::Item::Metadata::Artist,
item.setMeta( parser::IItem::Metadata::Artist,
media.meta( libvlc_meta_Artist ) );
item.setMeta( parser::Task::Item::Metadata::TrackNumber,
item.setMeta( parser::IItem::Metadata::TrackNumber,
media.meta( libvlc_meta_TrackNumber ) );
item.setMeta( parser::Task::Item::Metadata::DiscNumber,
item.setMeta( parser::IItem::Metadata::DiscNumber,
media.meta( libvlc_meta_DiscNumber ) );
item.setMeta( parser::Task::Item::Metadata::DiscTotal,
item.setMeta( parser::IItem::Metadata::DiscTotal,
media.meta( libvlc_meta_DiscTotal ) );
item.setDuration( media.duration() );
auto tracks = media.tracks();
for ( const auto& track : tracks )
{
parser::Task::Item::Track t;
parser::IItem::Track t;
if ( track.type() == VLC::MediaTrack::Type::Audio )
{
t.type = parser::Task::Item::Track::Type::Audio;
t.type = parser::IItem::Track::Type::Audio;
t.a.nbChannels = track.channels();
t.a.rate = track.rate();
}
else if ( track.type() == VLC::MediaTrack::Type::Video )
{
t.type = parser::Task::Item::Track::Type::Video;
t.type = parser::IItem::Track::Type::Video;
t.v.fpsNum = track.fpsNum();
t.v.fpsDen = track.fpsDen();
t.v.width = track.width();
......
......@@ -43,7 +43,7 @@ class VLCMetadataService : public IParserService
private:
virtual bool initialize( MediaLibrary* ml ) override;
virtual parser::Task::Status run( parser::Task::Item& item ) override;
virtual parser::Task::Status run( parser::IItem& item ) override;
virtual const char* name() const override;
virtual uint8_t nbThreads() const override;
virtual void onFlushing() override;
......
......@@ -37,7 +37,7 @@ public:
* @param task The task to be processed
* @return A status code
*/
virtual parser::Task::Status run( parser::Task::Item& item ) = 0;
virtual parser::Task::Status run( parser::IItem& item ) = 0;
/**
* @brief name returns the name of this service.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment