Commit 0f2b16dc authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MetadataParser: Cache the previously selected album

And use it again if the name and containing folder are the same
parent cfa1567e
......@@ -39,6 +39,11 @@
namespace medialibrary
{
MetadataParser::MetadataParser()
: m_previousFolderId( 0 )
{
}
bool MetadataParser::initialize()
{
m_unknownArtist = Artist::fetch( m_ml, UnknownArtistID );
......@@ -222,7 +227,7 @@ std::shared_ptr<Genre> MetadataParser::handleGenre( parser::Task& task ) const
/* Album handling */
std::shared_ptr<Album> MetadataParser::findAlbum( parser::Task& task, std::shared_ptr<Artist> albumArtist,
std::shared_ptr<Artist> trackArtist ) const
std::shared_ptr<Artist> trackArtist )
{
const auto& albumName = task.vlcMedia.meta( libvlc_meta_Album );
if ( albumName.empty() == true )
......@@ -235,6 +240,12 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::Task& task, std::share
return m_unknownArtist->unknownAlbum();
}
if ( m_previousAlbum != nullptr && albumName == m_previousAlbum->title() &&
m_previousFolderId != 0 && task.file->folderId() == m_previousFolderId )
return m_previousAlbum;
m_previousAlbum.reset();
m_previousFolderId = 0;
// Album matching depends on the difference between artist & album artist.
// Specificaly pass the albumArtist here.
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
......@@ -330,7 +341,9 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::Task& task, std::share
{
LOG_WARN( "Multiple candidates for album ", albumName, ". Selecting first one out of luck" );
}
return std::static_pointer_cast<Album>( albums[0] );
m_previousFolderId = task.file->folderId();
m_previousAlbum = albums[0];
return albums[0];
}
///
......
......@@ -32,6 +32,9 @@ class AlbumTrack;
class MetadataParser : public ParserService
{
public:
MetadataParser();
protected:
virtual bool initialize() override;
virtual parser::Task::Status run( parser::Task& task ) override;
......@@ -46,7 +49,7 @@ protected:
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& task, std::shared_ptr<Artist> albumArtist,
std::shared_ptr<Artist> artist ) const;
std::shared_ptr<Artist> artist );
std::shared_ptr<Genre> handleGenre( parser::Task& task ) const;
private:
......@@ -55,6 +58,8 @@ private:
private:
std::shared_ptr<Artist> m_unknownArtist;
std::shared_ptr<Artist> m_variousArtists;
std::shared_ptr<Album> m_previousAlbum;
int64_t m_previousFolderId;
};
}
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