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

Media: Don't store extension entity IDs in Media

Instead, have a FOREIGN KEY in those extension tables
This also mandates a media to be provided when creating a
movie/showepisode, and constify the extension getters
parent 82644fe5
......@@ -46,12 +46,12 @@ class IMedia
virtual unsigned int id() const = 0;
virtual Type type() = 0;
virtual const std::string& title() = 0;
virtual AlbumTrackPtr albumTrack() = 0;
virtual AlbumTrackPtr albumTrack() const = 0;
/**
* @brief duration Returns the file duration in ms
*/
virtual int64_t duration() const = 0;
virtual std::shared_ptr<IShowEpisode> showEpisode() = 0;
virtual ShowEpisodePtr showEpisode() const = 0;
virtual int playCount() const = 0;
virtual void increasePlayCount() = 0;
virtual const std::string& mrl() const = 0;
......@@ -70,7 +70,7 @@ class IMedia
virtual void setRating( int rating ) = 0;
virtual bool addLabel( LabelPtr label ) = 0;
virtual bool removeLabel( LabelPtr label ) = 0;
virtual MoviePtr movie() = 0;
virtual MoviePtr movie() const = 0;
virtual std::vector<LabelPtr> labels() = 0;
virtual std::vector<VideoTrackPtr> videoTracks() = 0;
virtual std::vector<AudioTrackPtr> audioTracks() = 0;
......
......@@ -149,8 +149,7 @@ std::shared_ptr<AlbumTrack> Album::addTrack( Media& media, unsigned int trackNb,
auto track = AlbumTrack::create( m_dbConnection, m_id, media.id(), trackNb, discNumber );
if ( track == nullptr )
return nullptr;
if ( media.setAlbumTrack( track ) == false )
return nullptr;
media.setAlbumTrack( track );
static const std::string req = "UPDATE " + policy::AlbumTable::Name +
" SET nb_tracks = nb_tracks + 1 WHERE id_album = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, m_id ) == false )
......
......@@ -31,7 +31,7 @@ const std::string policy::AlbumTrackTable::Name = "AlbumTrack";
const std::string policy::AlbumTrackTable::PrimaryKeyColumn = "id_track";
unsigned int AlbumTrack::* const policy::AlbumTrackTable::PrimaryKey = &AlbumTrack::m_id;
AlbumTrack::AlbumTrack(DBConnection dbConnection, sqlite::Row& row )
AlbumTrack::AlbumTrack( DBConnection dbConnection, sqlite::Row& row )
: m_dbConnection( dbConnection )
{
row >> m_id
......@@ -123,6 +123,13 @@ std::shared_ptr<AlbumTrack> AlbumTrack::create( DBConnection dbConnection, unsig
return self;
}
AlbumTrackPtr AlbumTrack::fromMedia( DBConnection dbConnection, unsigned int mediaId )
{
static const std::string req = "SELECT * FROM " + policy::AlbumTrackTable::Name +
" WHERE media_id = ?";
return fetch( dbConnection, req, mediaId );
}
const std::string& AlbumTrack::genre()
{
return m_genre;
......
......@@ -66,6 +66,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<AlbumTrack> create( DBConnection dbConnection, unsigned int albumId,
unsigned int mediaId, unsigned int trackNb , unsigned int discNumber );
static AlbumTrackPtr fromMedia( DBConnection dbConnection, unsigned int mediaId );
private:
DBConnection m_dbConnection;
......
......@@ -54,9 +54,7 @@ Media::Media( DBConnection dbConnection, sqlite::Row& row )
>> m_playCount
>> m_progress
>> m_rating
>> m_showEpisodeId
>> m_mrl
>> m_movieId
>> m_folderId
>> m_lastModificationDate
>> m_insertionDate
......@@ -74,9 +72,7 @@ Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& t
, m_playCount( 0 )
, m_progress( .0f )
, m_rating( -1 )
, m_showEpisodeId( 0 )
, m_mrl( isRemovable == true ? file->name() : file->fullPath() )
, m_movieId( 0 )
, m_folderId( folderId )
, m_lastModificationDate( file->lastModificationDate() )
, m_insertionDate( time( nullptr ) )
......@@ -102,21 +98,19 @@ std::shared_ptr<Media> Media::create( DBConnection dbConnection, Type type, cons
return self;
}
AlbumTrackPtr Media::albumTrack()
AlbumTrackPtr Media::albumTrack() const
{
if ( m_albumTrack == nullptr )
{
std::string req = "SELECT * FROM " + policy::AlbumTrackTable::Name +
" WHERE media_id = ?";
m_albumTrack = AlbumTrack::fetch( m_dbConnection, req, m_id );
}
return m_albumTrack;
auto lock = m_albumTrack.lock();
if ( m_albumTrack.isCached() == false )
m_albumTrack = AlbumTrack::fromMedia( m_dbConnection, m_id );
return m_albumTrack.get();
}
bool Media::setAlbumTrack( AlbumTrackPtr albumTrack )
void Media::setAlbumTrack( AlbumTrackPtr albumTrack )
{
auto lock = m_albumTrack.lock();
m_albumTrack = albumTrack;
return true;
}
int64_t Media::duration() const
......@@ -132,22 +126,19 @@ void Media::setDuration( int64_t duration )
m_changed = true;
}
std::shared_ptr<IShowEpisode> Media::showEpisode()
ShowEpisodePtr Media::showEpisode() const
{
if ( m_showEpisode == nullptr && m_showEpisodeId != 0 )
{
m_showEpisode = ShowEpisode::fetch( m_dbConnection, m_showEpisodeId );
}
return m_showEpisode;
auto lock = m_showEpisode.lock();
if ( m_showEpisode.isCached() == false )
m_showEpisode = ShowEpisode::fromMedia( m_dbConnection, m_id );
return m_showEpisode.get();
}
void Media::setShowEpisode( ShowEpisodePtr showEpisode )
void Media::setShowEpisode( ShowEpisodePtr episode )
{
if ( showEpisode == nullptr || m_showEpisodeId == showEpisode->id() )
return;
m_showEpisodeId = showEpisode->id();
m_showEpisode = showEpisode;
m_changed = true;
auto lock = m_showEpisode.lock();
m_showEpisode = episode;
}
std::vector<LabelPtr> Media::labels()
......@@ -210,22 +201,19 @@ const std::string& Media::mrl() const
return m_fullPath;
}
MoviePtr Media::movie()
MoviePtr Media::movie() const
{
if ( m_movie == nullptr && m_movieId != 0 )
{
m_movie = Movie::fetch( m_dbConnection, m_movieId );
}
return m_movie;
auto lock = m_movie.lock();
if ( m_movie.isCached() == false )
m_movie = Movie::fromMedia( m_dbConnection, m_id );
return m_movie.get();
}
void Media::setMovie( MoviePtr movie )
void Media::setMovie(MoviePtr movie)
{
if ( movie == nullptr || m_movieId == movie->id() )
return;
auto lock = m_movie.lock();
m_movie = movie;
m_movieId = movie->id();
m_changed = true;
}
bool Media::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps)
......@@ -275,15 +263,13 @@ void Media::setThumbnail(const std::string& thumbnail )
bool Media::save()
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
"type = ?, duration = ?, play_count = ?, progress = ?, rating = ?, show_episode_id = ?,"
"movie_id = ?, last_modification_date = ?, thumbnail = ?, parsed = ?,"
"type = ?, duration = ?, play_count = ?, progress = ?, rating = ?,"
"last_modification_date = ?, thumbnail = ?, parsed = ?,"
"title = ? WHERE id_media = ?";
if ( m_changed == false )
return true;
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, m_type, m_duration, m_playCount,
m_progress, m_rating,
sqlite::ForeignKey{ m_showEpisodeId },
sqlite::ForeignKey{ m_movieId }, m_lastModificationDate,
m_progress, m_rating, m_lastModificationDate,
m_thumbnail, m_isParsed, m_title, m_id ) == false )
{
return false;
......@@ -350,9 +336,7 @@ bool Media::createTable( DBConnection connection )
"play_count UNSIGNED INTEGER,"
"progress REAL,"
"rating INTEGER DEFAULT -1,"
"show_episode_id UNSIGNED INTEGER,"
"mrl TEXT,"
"movie_id UNSIGNED INTEGER,"
"folder_id UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER,"
"insertion_date UNSIGNED INTEGER,"
......@@ -361,10 +345,6 @@ bool Media::createTable( DBConnection connection )
"title TEXT,"
"is_present BOOLEAN NOT NULL DEFAULT 1,"
"is_removable BOOLEAN NOT NULL,"
"FOREIGN KEY (show_episode_id) REFERENCES " + policy::ShowEpisodeTable::Name
+ "(id_episode) ON DELETE CASCADE,"
"FOREIGN KEY (movie_id) REFERENCES " + policy::MovieTable::Name
+ "(id_movie) ON DELETE CASCADE,"
"FOREIGN KEY (folder_id) REFERENCES " + policy::FolderTable::Name
+ "(id_folder) ON DELETE CASCADE,"
"UNIQUE( mrl, folder_id ) ON CONFLICT FAIL"
......
......@@ -64,12 +64,13 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
void setType( Type type );
virtual const std::string& title() override;
void setTitle( const std::string& title );
virtual AlbumTrackPtr albumTrack() override;
bool setAlbumTrack( AlbumTrackPtr albumTrack );
virtual AlbumTrackPtr albumTrack() const override;
void setAlbumTrack( AlbumTrackPtr albumTrack );
virtual int64_t duration() const override;
void setDuration( int64_t duration);
virtual std::shared_ptr<IShowEpisode> showEpisode() override;
void setShowEpisode( ShowEpisodePtr showEpisode );
virtual ShowEpisodePtr showEpisode() const override;
// Used to cache the episode only. This doesn't update anything in DB
void setShowEpisode( ShowEpisodePtr episode );
virtual bool addLabel( LabelPtr label ) override;
virtual bool removeLabel( LabelPtr label ) override;
virtual std::vector<LabelPtr> labels() override;
......@@ -80,7 +81,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual int rating() const override;
virtual void setRating( int rating ) override;
virtual const std::string& mrl() const override;
virtual MoviePtr movie() override;
virtual MoviePtr movie() const override;
// Used to cache the movie only. This doesn't update anything in DB
void setMovie( MoviePtr movie );
bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps );
......@@ -111,9 +113,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
unsigned int m_playCount;
float m_progress;
int m_rating;
unsigned int m_showEpisodeId;
std::string m_mrl;
unsigned int m_movieId;
unsigned int m_folderId;
unsigned int m_lastModificationDate;
unsigned int m_insertionDate;
......@@ -124,9 +124,9 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
bool m_isRemovable;
// Auto fetched related properties
AlbumTrackPtr m_albumTrack;
ShowEpisodePtr m_showEpisode;
MoviePtr m_movie;
mutable Cache<AlbumTrackPtr> m_albumTrack;
mutable Cache<ShowEpisodePtr> m_showEpisode;
mutable Cache<MoviePtr> m_movie;
bool m_changed;
mutable Cache<std::string> m_fullPath;
......
......@@ -308,9 +308,11 @@ MoviePtr MediaLibrary::movie( const std::string& title )
return Movie::fetch( m_dbConnection.get(), req, title );
}
std::shared_ptr<Movie> MediaLibrary::createMovie( const std::string& title )
std::shared_ptr<Movie> MediaLibrary::createMovie( Media& media, const std::string& title )
{
return Movie::create( m_dbConnection.get(), title );
auto movie = Movie::create( m_dbConnection.get(), media.id(), title );
media.setMovie( movie );
return movie;
}
ArtistPtr MediaLibrary::artist(unsigned int id)
......
......@@ -71,7 +71,7 @@ class MediaLibrary : public IMediaLibrary
std::shared_ptr<Show> createShow( const std::string& name );
virtual MoviePtr movie( const std::string& title ) override;
std::shared_ptr<Movie> createMovie( const std::string& title );
std::shared_ptr<Movie> createMovie( Media& media, const std::string& title );
virtual ArtistPtr artist( unsigned int id ) override;
ArtistPtr artist( const std::string& name );
......
......@@ -32,6 +32,7 @@ Movie::Movie(DBConnection dbConnection, sqlite::Row& row )
: m_dbConnection( dbConnection )
{
row >> m_id
>> m_mediaId
>> m_title
>> m_releaseDate
>> m_summary
......@@ -39,14 +40,14 @@ Movie::Movie(DBConnection dbConnection, sqlite::Row& row )
>> m_imdbId;
}
Movie::Movie( const std::string& title )
Movie::Movie( unsigned int mediaId, const std::string& title )
: m_id( 0 )
, m_mediaId( mediaId )
, m_title( title )
, m_releaseDate( 0 )
{
}
unsigned int Movie::id() const
{
return m_id;
......@@ -72,7 +73,7 @@ bool Movie::setReleaseDate( time_t date )
return true;
}
const std::string&Movie::shortSummary() const
const std::string& Movie::shortSummary() const
{
return m_summary;
}
......@@ -129,22 +130,31 @@ bool Movie::createTable( DBConnection dbConnection )
static const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MovieTable::Name
+ "("
"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"
"imdb_id TEXT,"
"FOREIGN KEY(media_id) REFERENCES " + policy::MediaTable::Name
+ "(id_media) ON DELETE CASCADE"
")";
return sqlite::Tools::executeRequest( dbConnection, req );
}
std::shared_ptr<Movie> Movie::create(DBConnection dbConnection, const std::string& title )
std::shared_ptr<Movie> Movie::create( DBConnection dbConnection, unsigned int mediaId, const std::string& title )
{
auto movie = std::make_shared<Movie>( title );
auto movie = std::make_shared<Movie>( mediaId, title );
static const std::string req = "INSERT INTO " + policy::MovieTable::Name
+ "(title) VALUES(?)";
if ( insert( dbConnection, movie, req, title ) == false )
+ "(media_id, title) VALUES(?, ?)";
if ( insert( dbConnection, movie, req, mediaId, title ) == false )
return nullptr;
movie->m_dbConnection = dbConnection;
return movie;
}
MoviePtr Movie::fromMedia( DBConnection dbConnection, unsigned int mediaId )
{
static const std::string req = "SELECT * FROM " + policy::MovieTable::Name + " WHERE media_id = ?";
return fetch( dbConnection, req, mediaId );
}
......@@ -43,7 +43,7 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
{
public:
Movie( DBConnection dbConnection, sqlite::Row& row );
Movie( const std::string& title );
Movie( unsigned int mediaId, const std::string& title );
virtual unsigned int id() const override;
virtual const std::string& title() const override;
......@@ -58,11 +58,13 @@ class Movie : public IMovie, public DatabaseHelpers<Movie, policy::MovieTable>
virtual std::vector<MediaPtr> files() override;
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<Movie> create( DBConnection dbConnection, const std::string& title );
static std::shared_ptr<Movie> create( DBConnection dbConnection, unsigned int mediaId, const std::string& title );
static MoviePtr fromMedia( DBConnection dbConnection, unsigned int mediaId );
private:
DBConnection m_dbConnection;
unsigned int m_id;
unsigned int m_mediaId;
std::string m_title;
time_t m_releaseDate;
std::string m_summary;
......
......@@ -21,7 +21,10 @@
*****************************************************************************/
#include "Show.h"
#include "Media.h"
#include "ShowEpisode.h"
#include "database/SqliteTools.h"
const std::string policy::ShowTable::Name = "Show";
......@@ -116,9 +119,11 @@ bool Show::setTvdbId( const std::string& tvdbId )
return true;
}
std::shared_ptr<ShowEpisode> Show::addEpisode(const std::string& title, unsigned int episodeNumber)
std::shared_ptr<ShowEpisode> Show::addEpisode( Media& media, const std::string& title, unsigned int episodeNumber)
{
return ShowEpisode::create( m_dbConnection, title, episodeNumber, m_id );
auto episode = ShowEpisode::create( m_dbConnection, media.id(), title, episodeNumber, m_id );
media.setShowEpisode( episode );
return episode;
}
std::vector<ShowEpisodePtr> Show::episodes()
......
......@@ -29,6 +29,7 @@
#include "IMediaLibrary.h"
#include "IShow.h"
class Media;
class Show;
class ShowEpisode;
......@@ -58,7 +59,7 @@ class Show : public IShow, public DatabaseHelpers<Show, policy::ShowTable>
bool setArtworkMrl( const std::string& artworkMrl );
virtual const std::string& tvdbId() override;
bool setTvdbId( const std::string& summary );
std::shared_ptr<ShowEpisode> addEpisode( const std::string& title, unsigned int episodeNumber );
std::shared_ptr<ShowEpisode> addEpisode( Media& media, const std::string& title, unsigned int episodeNumber );
virtual std::vector<ShowEpisodePtr> episodes() override;
static bool createTable( DBConnection dbConnection );
......
......@@ -33,6 +33,7 @@ ShowEpisode::ShowEpisode(DBConnection dbConnection, sqlite::Row& row )
: m_dbConnection( dbConnection )
{
row >> m_id
>> m_mediaId
>> m_artworkMrl
>> m_episodeNumber
>> m_name
......@@ -42,8 +43,9 @@ ShowEpisode::ShowEpisode(DBConnection dbConnection, sqlite::Row& row )
>> m_showId;
}
ShowEpisode::ShowEpisode( const std::string& name, unsigned int episodeNumber, unsigned int showId )
ShowEpisode::ShowEpisode( unsigned int mediaId, const std::string& name, unsigned int episodeNumber, unsigned int showId )
: m_id( 0 )
, m_mediaId( mediaId )
, m_episodeNumber( episodeNumber )
, m_name( name )
, m_seasonNumber( 0 )
......@@ -147,6 +149,7 @@ bool ShowEpisode::createTable( DBConnection dbConnection )
const std::string req = "CREATE TABLE IF NOT EXISTS " + policy::ShowEpisodeTable::Name
+ "("
"id_episode INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id UNSIGNED INTEGER NOT NULL,"
"artwork_mrl TEXT,"
"episode_number UNSIGNED INT,"
"title TEXT,"
......@@ -154,18 +157,26 @@ bool ShowEpisode::createTable( DBConnection dbConnection )
"episode_summary TEXT,"
"tvdb_id TEXT,"
"show_id UNSIGNED INT,"
"FOREIGN KEY(media_id) REFERENCES " + policy::MediaTable::Name
+ "(id_media) ON DELETE CASCADE,"
"FOREIGN KEY(show_id) REFERENCES " + policy::ShowTable::Name + "(id_show)"
")";
return sqlite::Tools::executeRequest( dbConnection, req );
}
std::shared_ptr<ShowEpisode> ShowEpisode::create( DBConnection dbConnection, const std::string& title, unsigned int episodeNumber, unsigned int showId )
std::shared_ptr<ShowEpisode> ShowEpisode::create( DBConnection dbConnection, unsigned int mediaId, const std::string& title, unsigned int episodeNumber, unsigned int showId )
{
auto episode = std::make_shared<ShowEpisode>( title, episodeNumber, showId );
auto episode = std::make_shared<ShowEpisode>( mediaId, title, episodeNumber, showId );
static const std::string req = "INSERT INTO " + policy::ShowEpisodeTable::Name
+ "(episode_number, title, show_id) VALUES(? , ?, ?)";
if ( insert( dbConnection, episode, req, episodeNumber, title, showId ) == false )
+ "(media_id, episode_number, title, show_id) VALUES(?, ? , ?, ?)";
if ( insert( dbConnection, episode, req, mediaId, episodeNumber, title, showId ) == false )
return nullptr;
episode->m_dbConnection = dbConnection;
return episode;
}
ShowEpisodePtr ShowEpisode::fromMedia( DBConnection dbConnection, unsigned int mediaId )
{
static const std::string req = "SELECT * FROM " + policy::ShowEpisodeTable::Name + " WHERE media_id = ?";
return fetch( dbConnection, req, mediaId );
}
......@@ -47,7 +47,7 @@ class ShowEpisode : public IShowEpisode, public DatabaseHelpers<ShowEpisode, pol
{
public:
ShowEpisode( DBConnection dbConnection, sqlite::Row& row );
ShowEpisode(const std::string& name, unsigned int episodeNumber, unsigned int showId );
ShowEpisode( unsigned int mediaId, const std::string& name, unsigned int episodeNumber, unsigned int showId );
virtual unsigned int id() const override;
virtual const std::string& artworkMrl() const override;
......@@ -64,11 +64,13 @@ class ShowEpisode : public IShowEpisode, public DatabaseHelpers<ShowEpisode, pol
virtual std::vector<MediaPtr> files() override;
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<ShowEpisode> create( DBConnection dbConnection, const std::string& title, unsigned int episodeNumber, unsigned int showId );
static std::shared_ptr<ShowEpisode> create( DBConnection dbConnection, unsigned int mediaId, const std::string& title, unsigned int episodeNumber, unsigned int showId );
static ShowEpisodePtr fromMedia( DBConnection dbConnection, unsigned int mediaId );
private:
DBConnection m_dbConnection;
unsigned int m_id;
unsigned int m_mediaId;
std::string m_artworkMrl;
unsigned int m_episodeNumber;
std::string m_name;
......
......@@ -172,7 +172,7 @@ bool VLCMetadataService::parseVideoFile( std::shared_ptr<Media> file, VLC::Media
return true;
}
std::shared_ptr<Show> s = std::static_pointer_cast<Show>( show );
s->addEpisode( title, episodeId );
s->addEpisode( *file, title, episodeId );
}
}
else
......
......@@ -32,14 +32,16 @@ class Movies : public Tests
TEST_F( Movies, Create )
{
auto m = ml->createMovie( "movie" );
auto media = ml->addFile( "movie.mkv" );
auto m = ml->createMovie( *media, "movie" );
ASSERT_NE( m, nullptr );
ASSERT_EQ( m->title(), "movie" );
}
TEST_F( Movies, Fetch )
{
auto m = ml->createMovie( "movie" );
auto media = ml->addFile( "movie.mkv" );
auto m = ml->createMovie( *media, "movie" );
auto m2 = ml->movie( "movie" );
ASSERT_EQ( m, m2 );
......@@ -53,7 +55,9 @@ TEST_F( Movies, Fetch )
TEST_F( Movies, SetReleaseDate )
{
auto m = ml->createMovie( "movie" );
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 );
......@@ -66,7 +70,9 @@ TEST_F( Movies, SetReleaseDate )
TEST_F( Movies, SetShortSummary )
{
auto m = ml->createMovie( "movie" );
auto media = ml->addFile( "movie.mkv" );
auto m = ml->createMovie( *media, "movie" );
ASSERT_EQ( m->shortSummary().length(), 0u );
m->setShortSummary( "great movie" );
ASSERT_EQ( m->shortSummary(), "great movie" );
......@@ -79,7 +85,9 @@ TEST_F( Movies, SetShortSummary )
TEST_F( Movies, SetArtworkMrl )
{
auto m = ml->createMovie( "movie" );
auto media = ml->addFile( "movie.mkv" );
auto m = ml->createMovie( *media, "movie" );
ASSERT_EQ( m->artworkMrl().length(), 0u );
m->setArtworkMrl( "artwork" );
ASSERT_EQ( m->artworkMrl(), "artwork" );
......@@ -92,7 +100,9 @@ TEST_F( Movies, SetArtworkMrl )
TEST_F( Movies, SetImdbId )
{
auto m = ml->createMovie( "movie" );
auto media = ml->addFile( "movie.mkv" );
auto m = ml->createMovie( *media, "movie" );
ASSERT_EQ( m->imdbId().length(), 0u );
m->setImdbId( "id" );
ASSERT_EQ( m->imdbId(), "id" );
......@@ -106,11 +116,10 @@ TEST_F( Movies, SetImdbId )
TEST_F( Movies, AssignToFile )
{
auto f = ml->addFile( "file.avi" );
auto m = ml->createMovie( "movie" );
ASSERT_EQ( f->movie(), nullptr );
f->setMovie( m );
f->save();
auto m = ml->createMovie( *f, "movie" );
ASSERT_EQ( f->movie(), m );
Reload();
......
......@@ -114,7 +114,8 @@ TEST_F( Shows, SetTvdbId )
TEST_F( Shows, AddEpisode )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
auto media = ml->addFile( "episode.avi" );
auto e = show->addEpisode( *media, "episode 1", 1 );
ASSERT_NE( e, nullptr );
ASSERT_EQ( e->episodeNumber(), 1u );
......@@ -129,9 +130,8 @@ TEST_F( Shows, AddEpisode )
TEST_F( Shows, FetchShowFromEpisode )
{
auto s = ml->createShow( "show" );
auto e = s->addEpisode( "episode 1", 1 );
auto f = ml->addFile( "file.avi" );
f->setShowEpisode( e );
auto e = s->addEpisode( *f, "episode 1", 1 );
f->save();
auto e2 = f->showEpisode();
......@@ -151,7 +151,8 @@ TEST_F( Shows, FetchShowFromEpisode )
TEST_F( Shows, SetEpisodeArtwork )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
auto media = ml->addFile( "episode.mkv" );
auto e = show->addEpisode( *media, "episode 1", 1 );
bool res = e->setArtworkMrl( "path-to-art" );
ASSERT_TRUE( res );
ASSERT_EQ( e->artworkMrl(), "path-to-art" );
......@@ -166,7 +167,8 @@ TEST_F( Shows, SetEpisodeArtwork )
TEST_F( Shows, SetEpisodeSeasonNumber )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
auto media = ml->addFile( "episode.mkv" );
auto e = show->addEpisode( *media, "episode 1", 1 );
bool res = e->setSeasonNumber( 42 );
ASSERT_TRUE( res );
ASSERT_EQ( e->seasonNumber(), 42u );
......@@ -181,7 +183,8 @@ TEST_F( Shows, SetEpisodeSeasonNumber )
TEST_F( Shows, SetEpisodeSummary )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
auto media = ml->addFile( "episode.mkv" );
auto e = show->addEpisode( *media, "episode 1", 1 );
bool res = e->setShortSummary( "Insert spoilers here" );
ASSERT_TRUE( res );
ASSERT_EQ( e->shortSummary(), "Insert spoilers here" );
......@@ -196,7 +199,8 @@ TEST_F( Shows, SetEpisodeSummary )
TEST_F( Shows, SetEpisodeTvdbId )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
auto media = ml->addFile( "episode.mkv" );
auto e = show->addEpisode( *media, "episode 1", 1 );
bool res = e->setTvdbId( "TVDBID" );
ASSERT_TRUE( res );
ASSERT_EQ( e->tvdbId(), "TVDBID" );
......@@ -215,17 +219,16 @@ TEST_F( Shows, SetEpisodeTvdbId )
TEST_F( Shows, FileSetShowEpisode )
{
auto show = ml->createShow( "show" );
auto e = show->addEpisode( "episode 1", 1 );
auto f = ml->addFile( "file.avi" );
ASSERT_EQ( f->showEpisode(), nullptr );
f->setShowEpisode( e );
f->save();
auto e = show->addEpisode( *f, "episode 1", 1 );
ASSERT_EQ( f->showEpisode(), e );
Reload();
f = std::static_pointer_cast<Media>( ml->media( f->id() ) );
f = ml->media( f->id() );
auto e2 = f->showEpisode();
ASSERT_NE( e2, nullptr );
ASSERT_EQ( e2->name(), "episode 1" );
......
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