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

File: Don't expose External as a type but as a property

This way we can have a file which type is anything AND it's an external
file
parent 772c45fa
......@@ -48,8 +48,6 @@ public:
Soundtrack,
/// External subtitles
Subtitles,
/// External stream, unmanaged by the medialibrary
External,
};
virtual ~IFile() = default;
......@@ -58,6 +56,10 @@ public:
virtual Type type() const = 0;
virtual unsigned int lastModificationDate() const = 0;
virtual unsigned int size() const = 0;
///
/// \brief isExternal returns true if this stream isn't managed by the medialibrary
///
virtual bool isExternal() const = 0;
};
}
......@@ -48,7 +48,8 @@ File::File( MediaLibraryPtr ml, sqlite::Row& row )
>> m_parserSteps
>> m_folderId
>> m_isPresent
>> m_isRemovable;
>> m_isRemovable
>> m_isExternal;
}
File::File( MediaLibraryPtr ml, int64_t mediaId, Type type, const fs::IFile& file, int64_t folderId, bool isRemovable )
......@@ -63,6 +64,7 @@ File::File( MediaLibraryPtr ml, int64_t mediaId, Type type, const fs::IFile& fil
, m_folderId( folderId )
, m_isPresent( true )
, m_isRemovable( isRemovable )
, m_isExternal( false )
{
}
......@@ -78,6 +80,7 @@ File::File(MediaLibraryPtr ml, int64_t mediaId, IFile::Type type, const std::str
, m_folderId( 0 )
, m_isPresent( true )
, m_isRemovable( false )
, m_isExternal( true )
, m_fullPath( mrl )
{
}
......@@ -117,6 +120,11 @@ unsigned int File::size() const
return m_size;
}
bool File::isExternal() const
{
return m_isExternal;
}
void File::markStepCompleted( ParserStep step )
{
m_parserSteps = static_cast<ParserStep>( static_cast<uint8_t>( m_parserSteps ) |
......@@ -164,6 +172,7 @@ bool File::createTable( DBConnection dbConnection )
"folder_id UNSIGNED INTEGER,"
"is_present BOOLEAN NOT NULL DEFAULT 1,"
"is_removable BOOLEAN NOT NULL,"
"is_external BOOLEAN NOT NULL,"
"FOREIGN KEY (media_id) REFERENCES " + policy::MediaTable::Name
+ "(id_media) ON DELETE CASCADE,"
"FOREIGN KEY (folder_id) REFERENCES " + policy::FolderTable::Name
......@@ -186,7 +195,7 @@ std::shared_ptr<File> File::create( MediaLibraryPtr ml, int64_t mediaId, Type ty
{
auto self = std::make_shared<File>( ml, mediaId, type, fileFs, folderId, isRemovable );
static const std::string req = "INSERT INTO " + policy::FileTable::Name +
"(media_id, mrl, type, folder_id, last_modification_date, size, is_removable) VALUES(?, ?, ?, ?, ?, ?, ?)";
"(media_id, mrl, type, folder_id, last_modification_date, size, is_removable, is_external) VALUES(?, ?, ?, ?, ?, ?, ?, 0)";
if ( insert( ml, self, req, mediaId, self->m_mrl, type, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, self->m_size, isRemovable ) == false )
......@@ -199,7 +208,7 @@ std::shared_ptr<File> File::create( MediaLibraryPtr ml, int64_t mediaId, IFile::
{
auto self = std::make_shared<File>( ml, mediaId, type, mrl );
static const std::string req = "INSERT INTO " + policy::FileTable::Name +
"(media_id, mrl, type, folder_id, is_removable) VALUES(?, ?, ?, NULL, 0)";
"(media_id, mrl, type, folder_id, is_removable, is_external) VALUES(?, ?, ?, NULL, 0, 1)";
if ( insert( ml, self, req, mediaId, mrl, type ) == false )
return nullptr;
......
......@@ -66,6 +66,7 @@ public:
virtual Type type() const override;
virtual unsigned int lastModificationDate() const override;
virtual unsigned int size() const override;
virtual bool isExternal() const override;
/*
* We need to decouple the current parser state and the saved one.
* For instance, metadata extraction won't save anything in DB, so while
......@@ -112,6 +113,7 @@ private:
int64_t m_folderId;
bool m_isPresent;
bool m_isRemovable;
bool m_isExternal;
mutable Cache<std::string> m_fullPath;
mutable Cache<std::weak_ptr<Media>> m_media;
......
......@@ -308,7 +308,7 @@ MediaPtr MediaLibrary::addMedia( const std::string& mrl )
auto media = Media::create( this, IMedia::Type::Unknown, utils::file::fileName( mrl ) );
if ( media == nullptr )
return nullptr;
media->addExternalMrl( mrl, IFile::Type::External );
media->addExternalMrl( mrl, IFile::Type::Main );
return media;
}
......
......@@ -56,6 +56,12 @@ TEST_F( Medias, Create )
ASSERT_EQ( m->showEpisode(), nullptr );
ASSERT_EQ( m->duration(), -1 );
ASSERT_NE( 0u, m->insertionDate() );
auto files = m->files();
ASSERT_EQ( 1u, files.size() );
auto f = files[0];
ASSERT_FALSE( f->isExternal() );
ASSERT_EQ( File::Type::Entire, f->type() );
}
TEST_F( Medias, Fetch )
......@@ -497,6 +503,12 @@ TEST_F( Medias, ExternalMrl )
auto m2 = ml->media( "https://foo.bar/sea-otters.mkv" );
ASSERT_NE( nullptr, m2 );
ASSERT_EQ( m->id(), m2->id() );
auto files = m2->files();
ASSERT_EQ( 1u, files.size() );
auto f = files[0];
ASSERT_TRUE( f->isExternal() );
ASSERT_EQ( File::Type::Main, f->type() );
}
class FetchMedia : public Tests
......
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