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

Album: Create albums with their artwork url instead of create + update

parent 4d510119
......@@ -55,12 +55,13 @@ Album::Album(MediaLibraryPtr ml, sqlite::Row& row)
>> m_isPresent;
}
Album::Album( MediaLibraryPtr ml, const std::string& title )
Album::Album( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl )
: m_ml( ml )
, m_id( 0 )
, m_title( title )
, m_artistId( 0 )
, m_releaseYear( ~0u )
, m_artworkMrl( artworkMrl )
, m_nbTracks( 0 )
, m_duration( 0 )
, m_isPresent( true )
......@@ -410,12 +411,12 @@ bool Album::createTriggers(DBConnection dbConnection)
sqlite::Tools::executeRequest( dbConnection, vtriggerDelete );
}
std::shared_ptr<Album> Album::create( MediaLibraryPtr ml, const std::string& title )
std::shared_ptr<Album> Album::create( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl )
{
auto album = std::make_shared<Album>( ml, title );
auto album = std::make_shared<Album>( ml, title, artworkMrl );
static const std::string req = "INSERT INTO " + policy::AlbumTable::Name +
"(id_album, title) VALUES(NULL, ?)";
if ( insert( ml, album, req, title ) == false )
"(id_album, title, artwork_mrl) VALUES(NULL, ?, ?)";
if ( insert( ml, album, req, title, artworkMrl ) == false )
return nullptr;
return album;
}
......
......@@ -54,7 +54,7 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
{
public:
Album( MediaLibraryPtr ml, sqlite::Row& row );
Album( MediaLibraryPtr ml, const std::string& title );
Album( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl );
Album( MediaLibraryPtr ml, const Artist* artist );
virtual int64_t id() const override;
......@@ -100,7 +100,7 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
static bool createTable( DBConnection dbConnection );
static bool createTriggers( DBConnection dbConnection );
static std::shared_ptr<Album> create( MediaLibraryPtr ml, const std::string& title );
static std::shared_ptr<Album> create( MediaLibraryPtr ml, const std::string& title, const std::string& artworkMrl );
static std::shared_ptr<Album> createUnknownAlbum( MediaLibraryPtr ml, const Artist* artist );
///
/// \brief search search for an album, through its albumartist or title
......
......@@ -382,9 +382,9 @@ AlbumPtr MediaLibrary::album( int64_t id ) const
return Album::fetch( this, id );
}
std::shared_ptr<Album> MediaLibrary::createAlbum(const std::string& title )
std::shared_ptr<Album> MediaLibrary::createAlbum( const std::string& title, const std::string& artworkMrl )
{
return Album::create( this, title );
return Album::create( this, title, artworkMrl );
}
std::vector<AlbumPtr> MediaLibrary::albums( SortingCriteria sort, bool desc ) const
......
......@@ -79,7 +79,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual bool deleteLabel( LabelPtr label ) override;
virtual AlbumPtr album( int64_t id ) const override;
std::shared_ptr<Album> createAlbum( const std::string& title );
std::shared_ptr<Album> createAlbum( const std::string& title, const std::string& artworkMrl );
virtual std::vector<AlbumPtr> albums(SortingCriteria sort, bool desc) const override;
virtual std::vector<GenrePtr> genres( SortingCriteria sort, bool desc ) const override;
......
......@@ -128,11 +128,9 @@ bool MetadataParser::parseAudioFile( parser::Task& task ) const
auto t = m_ml->getConn()->newTransaction();
if ( album == nullptr )
{
album = m_ml->createAlbum( task.albumName );
album = m_ml->createAlbum( task.albumName, task.artworkMrl );
if ( album == nullptr )
return false;
if ( task.artworkMrl.length() != 0 )
album->setArtworkMrl( task.artworkMrl );
m_notifier->notifyAlbumCreation( album );
}
// If we know a track artist, specify it, otherwise, fallback to the album/unknown artist
......
......@@ -95,6 +95,11 @@ void MediaLibraryTester::deleteAlbum( int64_t albumId )
Album::destroy( this, albumId );
}
std::shared_ptr<Album> MediaLibraryTester::createAlbum( const std::string& title )
{
return MediaLibrary::createAlbum( title, "dummy artwork" );
}
std::shared_ptr<Genre> MediaLibraryTester::createGenre( const std::string& name )
{
return Genre::create( this, name );
......
......@@ -47,6 +47,7 @@ public:
std::shared_ptr<Media> addFile( const std::string& path );
std::shared_ptr<Playlist> playlist( int64_t playlistId );
void deleteAlbum( int64_t albumId );
std::shared_ptr<Album> createAlbum( const std::string& title );
std::shared_ptr<Genre> createGenre( const std::string& name );
void deleteGenre( int64_t genreId );
void deleteArtist( int64_t artistId );
......
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