Commit 592aef8b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

VLCMetadataService: Extract albums handling in its own method

parent b410cb55
......@@ -141,24 +141,14 @@ std::shared_ptr<Album> VLCMetadataService::findAlbum( const std::string& title,
return std::static_pointer_cast<Album>( albums[0] );
}
bool VLCMetadataService::parseAudioFile( std::shared_ptr<Media> media, VLC::Media& vlcMedia ) const
std::pair<std::shared_ptr<Album>, bool> VLCMetadataService::handleAlbum( std::shared_ptr<Media> media, VLC::Media& vlcMedia ) const
{
media->setType( IMedia::Type::AudioType );
auto albumTitle = vlcMedia.meta( libvlc_meta_Album );
auto newAlbum = false;
std::shared_ptr<Album> album;
std::shared_ptr<AlbumTrack> track;
auto artistPair = handleArtist( media, vlcMedia );
if ( artistPair.first == nullptr && artistPair.second == true )
{
LOG_WARN( "Failed to create a new artist" );
return false;
}
if ( albumTitle.length() > 0 )
{
album = findAlbum( albumTitle, vlcMedia );
auto newAlbum = false;
auto album = findAlbum( albumTitle, vlcMedia );
if ( album == nullptr )
{
album = m_ml->createAlbum( albumTitle );
......@@ -175,12 +165,33 @@ bool VLCMetadataService::parseAudioFile( std::shared_ptr<Media> media, VLC::Medi
}
if ( album != nullptr )
{
track = handleTrack( album, media, vlcMedia );
auto track = handleTrack( album, media, vlcMedia );
if ( track != nullptr )
media->setAlbumTrack( track );
}
return {album, newAlbum};
}
return link( media, album, artistPair.first, newAlbum, artistPair.second );
return {nullptr, false};
}
bool VLCMetadataService::parseAudioFile( std::shared_ptr<Media> media, VLC::Media& vlcMedia ) const
{
media->setType( IMedia::Type::AudioType );
auto artistPair = handleArtist( media, vlcMedia );
if ( artistPair.first == nullptr && artistPair.second == true )
{
LOG_WARN( "Failed to create a new artist" );
return false;
}
auto albumPair = handleAlbum( media, vlcMedia );
if ( albumPair.first == nullptr && albumPair.second == true )
{
LOG_WARN( "Failed to create a new album" );
return false;
}
return link( media, albumPair.first, artistPair.first, albumPair.second, artistPair.second );
}
bool VLCMetadataService::parseVideoFile( std::shared_ptr<Media> file, VLC::Media& media ) const
......
......@@ -50,7 +50,7 @@ class VLCMetadataService : public IMetadataService
virtual unsigned int priority() const override;
virtual void run( std::shared_ptr<Media> file, void *data ) override;
private:
private:
Status handleMediaMeta( std::shared_ptr<Media> media , VLC::Media &vlcMedia ) const;
std::shared_ptr<Album> findAlbum( const std::string& title, VLC::Media& vlcMedia ) const;
bool parseAudioFile( std::shared_ptr<Media> media, VLC::Media &vlcMedia ) const;
......@@ -58,6 +58,7 @@ class VLCMetadataService : public IMetadataService
std::pair<std::shared_ptr<Artist>, bool> handleArtist( std::shared_ptr<Media> media, VLC::Media& vlcMedia ) const;
std::shared_ptr<AlbumTrack> handleTrack( std::shared_ptr<Album> album, std::shared_ptr<Media> media, VLC::Media& vlcMedia ) const;
bool link( std::shared_ptr<Media> media, std::shared_ptr<Album> album, std::shared_ptr<Artist> artist, bool newAlbum, bool newArtist ) const;
std::pair<std::shared_ptr<Album>, bool> handleAlbum( std::shared_ptr<Media> media, VLC::Media& vlcMedia ) const;
VLC::Instance m_instance;
IMetadataServiceCb* m_cb;
......
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