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

Move the release date/year to the media

parent b100aac4
......@@ -35,8 +35,6 @@ public:
virtual const std::string& title() const = 0;
/**
* @brief releaseYear returns the release year, or 0 if unknown.
* The release date of an album is considered unknown if multiple tracks
* of the same album have different release dates
*/
virtual unsigned int releaseYear() const = 0;
virtual const std::string& shortSummary() const = 0;
......
......@@ -48,12 +48,6 @@ class IAlbumTrack
* @return Which disc this tracks appears on (or 0 if unspecified)
*/
virtual unsigned int discNumber() const = 0;
/**
* @brief releaseYear Represent the track release year. It doesn't
* imply anything regarding the album's release year.
* @return This track release year, or 0 if unknown.
*/
virtual unsigned int releaseYear() const = 0;
};
#endif // IALBUMTRACK_H
......@@ -91,4 +91,5 @@ class IMedia
///
virtual const std::string& thumbnail() = 0;
virtual unsigned int insertionDate() const = 0;
virtual unsigned int releaseDate() const = 0;
};
......@@ -31,7 +31,6 @@ class IMovie
virtual ~IMovie() {}
virtual unsigned int id() const = 0;
virtual const std::string& title() const = 0;
virtual time_t releaseDate() const = 0;
virtual const std::string& shortSummary() const = 0;
virtual const std::string& artworkMrl() const = 0;
virtual const std::string& imdbId() const = 0;
......
......@@ -41,7 +41,6 @@ AlbumTrack::AlbumTrack( MediaLibraryPtr ml, sqlite::Row& row )
>> m_genreId
>> m_trackNumber
>> m_albumId
>> m_releaseYear
>> m_discNumber
>> m_isPresent;
}
......@@ -52,7 +51,6 @@ AlbumTrack::AlbumTrack( MediaLibraryPtr ml, unsigned int mediaId, unsigned int t
, m_mediaId( mediaId )
, m_trackNumber( trackNumber )
, m_albumId( albumId )
, m_releaseYear( 0 )
, m_discNumber( discNumber )
, m_isPresent( true )
{
......@@ -97,7 +95,6 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
"genre_id INTEGER,"
"track_number UNSIGNED INTEGER,"
"album_id UNSIGNED INTEGER NOT NULL,"
"release_year UNSIGNED INTEGER,"
"disc_number UNSIGNED INTEGER,"
"is_present BOOLEAN NOT NULL DEFAULT 1,"
"FOREIGN KEY (media_id) REFERENCES " + policy::MediaTable::Name + "(id_media)"
......@@ -174,23 +171,6 @@ unsigned int AlbumTrack::trackNumber()
return m_trackNumber;
}
unsigned int AlbumTrack::releaseYear() const
{
return m_releaseYear;
}
bool AlbumTrack::setReleaseYear(unsigned int year)
{
if ( m_releaseYear == year )
return true;
static const std::string req = "UPDATE " + policy::AlbumTrackTable::Name +
" SET release_year = ? WHERE id_track = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, year, m_id ) == false )
return false;
m_releaseYear = year;
return true;
}
unsigned int AlbumTrack::discNumber() const
{
return m_discNumber;
......
......@@ -60,8 +60,6 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
virtual GenrePtr genre() override;
bool setGenre( std::shared_ptr<Genre> genre );
virtual unsigned int trackNumber() override;
virtual unsigned int releaseYear() const override;
bool setReleaseYear( unsigned int year );
virtual unsigned int discNumber() const override;
virtual std::shared_ptr<IAlbum> album() override;
virtual std::shared_ptr<IMedia> media() override;
......@@ -81,7 +79,6 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
unsigned int m_genreId;
unsigned int m_trackNumber;
unsigned int m_albumId;
unsigned int m_releaseYear;
unsigned int m_discNumber;
bool m_isPresent;
......
......@@ -61,6 +61,7 @@ Media::Media( MediaLibraryPtr ml, sqlite::Row& row )
>> m_progress
>> m_rating
>> m_insertionDate
>> m_releaseDate
>> m_thumbnail
>> m_title
>> m_isFavorite
......@@ -78,6 +79,7 @@ Media::Media( MediaLibraryPtr ml, const std::string& title, Type type )
, m_progress( .0f )
, m_rating( -1 )
, m_insertionDate( time( nullptr ) )
, m_releaseDate( 0 )
, m_title( title )
, m_isFavorite( false )
, m_changed( false )
......@@ -287,6 +289,19 @@ unsigned int Media::insertionDate() const
return m_insertionDate;
}
unsigned int Media::releaseDate() const
{
return m_releaseDate;
}
void Media::setReleaseDate( unsigned int date )
{
if ( m_releaseDate == date )
return;
m_releaseDate = date;
m_changed = true;
}
void Media::setThumbnail(const std::string& thumbnail )
{
if ( m_thumbnail == thumbnail )
......@@ -298,12 +313,12 @@ void Media::setThumbnail(const std::string& thumbnail )
bool Media::save()
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
"type = ?, subtype = ?, duration = ?, progress = ?,"
"type = ?, subtype = ?, duration = ?, progress = ?, release_date = ?,"
"thumbnail = ?, title = ? WHERE id_media = ?";
if ( m_changed == false )
return true;
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_type, m_subType, m_duration,
m_progress, m_thumbnail, m_title, m_id ) == false )
m_progress, m_releaseDate, m_thumbnail, m_title, m_id ) == false )
{
return false;
}
......@@ -387,6 +402,7 @@ bool Media::createTable( DBConnection connection )
"progress REAL,"
"rating INTEGER DEFAULT -1,"
"insertion_date UNSIGNED INTEGER,"
"release_date UNSIGNED INTEGER,"
"thumbnail TEXT,"
"title TEXT,"
"is_favorite BOOLEAN NOT NULL DEFAULT 0,"
......
......@@ -97,6 +97,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual std::vector<AudioTrackPtr> audioTracks() override;
virtual const std::string& thumbnail() override;
virtual unsigned int insertionDate() const override;
virtual unsigned int releaseDate() const override;
void setReleaseDate( unsigned int date );
void setThumbnail( const std::string& thumbnail );
bool save();
......@@ -121,6 +123,7 @@ private:
float m_progress;
int m_rating;
unsigned int m_insertionDate;
unsigned int m_releaseDate;
std::string m_thumbnail;
std::string m_title;
bool m_isFavorite;
......
......@@ -34,7 +34,6 @@ Movie::Movie(MediaLibraryPtr ml, sqlite::Row& row )
row >> m_id
>> m_mediaId
>> m_title
>> m_releaseDate
>> m_summary
>> m_artworkMrl
>> m_imdbId;
......@@ -45,7 +44,6 @@ Movie::Movie( MediaLibraryPtr ml, unsigned int mediaId, const std::string& title
, m_id( 0 )
, m_mediaId( mediaId )
, m_title( title )
, m_releaseDate( 0 )
{
}
......@@ -59,21 +57,6 @@ const std::string&Movie::title() const
return m_title;
}
time_t Movie::releaseDate() const
{
return m_releaseDate;
}
bool Movie::setReleaseDate( time_t date )
{
static const std::string req = "UPDATE " + policy::MovieTable::Name
+ " SET release_date = ? WHERE id_movie = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, date, m_id ) == false )
return false;
m_releaseDate = date;
return true;
}
const std::string& Movie::shortSummary() const
{
return m_summary;
......@@ -133,7 +116,6 @@ bool Movie::createTable( DBConnection dbConnection )
"id_movie INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id UNSIGNED INTEGER NOT NULL,"
"title TEXT UNIQUE ON CONFLICT FAIL,"
"release_date UNSIGNED INTEGER,"
"summary TEXT,"
"artwork_mrl TEXT,"
"imdb_id TEXT,"
......
......@@ -47,8 +47,6 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
virtual unsigned int id() const override;
virtual const std::string& title() const override;
virtual time_t releaseDate() const override;
bool setReleaseDate(time_t date);
virtual const std::string& shortSummary() const override;
bool setShortSummary(const std::string& summary);
virtual const std::string& artworkMrl() const override;
......@@ -66,7 +64,6 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
unsigned int m_id;
unsigned int m_mediaId;
std::string m_title;
time_t m_releaseDate;
std::string m_summary;
std::string m_artworkMrl;
std::string m_imdbId;
......
......@@ -350,7 +350,7 @@ std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album>
if ( task.releaseDate.empty() == false )
{
auto releaseYear = atoi( task.releaseDate.c_str() );
track->setReleaseYear( releaseYear );
task.media->setReleaseDate( releaseYear );
// Let the album handle multiple dates. In order to do this properly, we need
// to know if the date has been changed before, which can be known only by
// using Album class internals.
......
......@@ -278,7 +278,7 @@ void Tests::checkAlbumTracks( const IAlbum* album, const std::vector<MediaPtr>&
}
if ( expectedTrack.HasMember( "releaseYear" ) )
{
if ( albumTrack->releaseYear() != expectedTrack["releaseYear"].GetUint() )
if ( track->releaseDate() != expectedTrack["releaseYear"].GetUint() )
return;
}
if ( expectedTrack.HasMember( "cd" ) )
......
......@@ -73,25 +73,6 @@ TEST_F( AlbumTracks, Artist )
ASSERT_EQ( newArtist->id(), artist->id() );
}
TEST_F( AlbumTracks, SetReleaseYear )
{
auto a = ml->createAlbum( "album" );
auto m = ml->addFile( "test.mp3" );
auto t = a->addTrack( m, 1, 0 );
m->save();
ASSERT_EQ( 0u, t->releaseYear() );
t->setReleaseYear( 1234 );
ASSERT_EQ( t->releaseYear(), 1234u );
Reload();
auto m2 = ml->media( m->id() );
auto t2 = m2->albumTrack();
ASSERT_EQ( t->releaseYear(), t2->releaseYear() );
}
TEST_F( AlbumTracks, SetGenre )
{
auto a = ml->createAlbum( "album" );
......
......@@ -296,3 +296,18 @@ TEST_F( Medias, History )
ASSERT_EQ( m2->id(), history[0]->id() );
ASSERT_EQ( m->id(), history[1]->id() );
}
TEST_F( Medias, SetReleaseDate )
{
auto m = ml->addFile( "movie.mkv" );
ASSERT_EQ( m->releaseDate(), 0u );
m->setReleaseDate( 1234 );
m->save();
ASSERT_EQ( m->releaseDate(), 1234u );
Reload();
auto m2 = ml->media( m->id() );
ASSERT_EQ( m2->releaseDate(), 1234u );
}
......@@ -53,21 +53,6 @@ TEST_F( Movies, Fetch )
ASSERT_EQ( m2->title(), "movie" );
}
TEST_F( Movies, SetReleaseDate )
{
auto media = ml->addFile( "movie.mkv" );
auto m = ml->createMovie( *media, "movie" );
ASSERT_EQ( m->releaseDate(), 0u );
m->setReleaseDate( 1234 );
ASSERT_EQ( m->releaseDate(), 1234u );
Reload();
auto m2 = ml->movie( "movie" );
ASSERT_EQ( m2->releaseDate(), 1234u );
}
TEST_F( Movies, SetShortSummary )
{
auto media = ml->addFile( "movie.mkv" );
......
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