Commit d64468fb authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

AlbumTrack: Remove title field, as it already is exposed by the media

parent e57a323f
......@@ -34,10 +34,8 @@ class IAlbumTrack
virtual unsigned int id() const = 0;
virtual const std::string& genre() = 0;
virtual const std::string& title() = 0;
virtual unsigned int trackNumber() = 0;
virtual std::shared_ptr<IAlbum> album() = 0;
virtual std::vector<MediaPtr> files() = 0;
};
#endif // IALBUMTRACK_H
......@@ -36,17 +36,15 @@ AlbumTrack::AlbumTrack( DBConnection dbConnection, sqlite3_stmt* stmt )
{
m_id = sqlite::Traits<unsigned int>::Load( stmt, 0 );
m_mediaId = sqlite::Traits<unsigned int>::Load( stmt, 1 );
m_title = sqlite::Traits<std::string>::Load( stmt, 2 );
m_genre = sqlite::Traits<std::string>::Load( stmt, 3 );
m_trackNumber = sqlite::Traits<unsigned int>::Load( stmt, 4 );
m_albumId = sqlite::Traits<unsigned int>::Load( stmt, 5 );
m_genre = sqlite::Traits<std::string>::Load( stmt, 2 );
m_trackNumber = sqlite::Traits<unsigned int>::Load( stmt, 3 );
m_albumId = sqlite::Traits<unsigned int>::Load( stmt, 4 );
}
//FIXME: constify media
AlbumTrack::AlbumTrack( Media* media, unsigned int trackNumber, unsigned int albumId )
: m_id( 0 )
, m_mediaId( media->id() )
, m_title( media->name() )
, m_trackNumber( trackNumber )
, m_albumId( albumId )
, m_album( nullptr )
......@@ -63,7 +61,6 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::AlbumTrackTable::Name + "("
"id_track INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id INTEGER,"
"title TEXT,"
"genre TEXT,"
"track_number UNSIGNED INTEGER,"
"album_id UNSIGNED INTEGER NOT NULL,"
......@@ -79,8 +76,8 @@ std::shared_ptr<AlbumTrack> AlbumTrack::create(DBConnection dbConnection, unsign
{
auto self = std::make_shared<AlbumTrack>( media, trackNb, albumId );
static const std::string req = "INSERT INTO " + policy::AlbumTrackTable::Name
+ "(media_id, title, track_number, album_id) VALUES(?, ?, ?, ?)";
if ( _Cache::insert( dbConnection, self, req, media->id(), media->name(), trackNb, albumId ) == false )
+ "(media_id, track_number, album_id) VALUES(?, ?, ?)";
if ( _Cache::insert( dbConnection, self, req, media->id(), trackNb, albumId ) == false )
return nullptr;
self->m_dbConnection = dbConnection;
return self;
......@@ -101,11 +98,6 @@ bool AlbumTrack::setGenre(const std::string& genre)
return true;
}
const std::string& AlbumTrack::title()
{
return m_title;
}
unsigned int AlbumTrack::trackNumber()
{
return m_trackNumber;
......@@ -119,10 +111,3 @@ std::shared_ptr<IAlbum> AlbumTrack::album()
}
return m_album;
}
std::vector<MediaPtr> AlbumTrack::files()
{
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
+ " WHERE album_track_id = ? ";
return Media::fetchAll( m_dbConnection, req, m_id );
}
......@@ -55,10 +55,8 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
virtual unsigned int id() const override;
virtual const std::string& genre() override;
bool setGenre( const std::string& genre );
virtual const std::string& title() override;
virtual unsigned int trackNumber() override;
virtual std::shared_ptr<IAlbum> album() override;
virtual std::vector<MediaPtr> files() override;
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<AlbumTrack> create(DBConnection dbConnection, unsigned int albumId,
......@@ -68,7 +66,6 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
DBConnection m_dbConnection;
unsigned int m_id;
unsigned int m_mediaId;
std::string m_title;
std::string m_genre;
unsigned int m_trackNumber;
unsigned int m_albumId;
......
......@@ -234,9 +234,10 @@ std::shared_ptr<AlbumTrack> VLCMetadataService::handleTrack(std::shared_ptr<Albu
if ( title.length() == 0 )
{
LOG_WARN( "Failed to get track title" );
title = "Unknown track #";
title = "Track #";
title += trackNbStr;
}
media->setName( title );
unsigned int trackNb = std::stoi( trackNbStr );
auto track = std::static_pointer_cast<AlbumTrack>( album->addTrack( media, trackNb ) );
if ( track == nullptr )
......
......@@ -108,7 +108,7 @@ TEST_F( VLCMetadataServices, ParseAlbum )
file = std::static_pointer_cast<Media>( ml->file( "mr-zebra.mp3" ) );
auto track = file->albumTrack();
ASSERT_NE( track, nullptr );
ASSERT_EQ( track->title(), "Mr. Zebra" );
ASSERT_EQ( file->name(), "Mr. Zebra" );
ASSERT_EQ( track->genre(), "Rock" );
auto artists = file->artists();
ASSERT_EQ( artists.size(), 1u );
......
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