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

Add a Stream media type

parent 4b72828b
...@@ -64,6 +64,12 @@ class IMedia ...@@ -64,6 +64,12 @@ class IMedia
* playback history. * playback history.
*/ */
External, External,
/**
* Represent a stream, which is a specific kind of External media.
* This type of media is also intended to be inserted manually by
* the user.
*/
Stream,
}; };
enum class SubType : uint8_t enum class SubType : uint8_t
{ {
......
...@@ -264,6 +264,13 @@ class IMediaLibrary ...@@ -264,6 +264,13 @@ class IMediaLibrary
* The media can be fetched using media( std::string ) afterward. * The media can be fetched using media( std::string ) afterward.
*/ */
virtual MediaPtr addExternalMedia( const std::string& mrl ) = 0; virtual MediaPtr addExternalMedia( const std::string& mrl ) = 0;
/**
* @brief addStream Create an external media of type IMedia::Type::Stream
*
* This is equivalent to addExternalMedia, except for the resulting
* new media's type
*/
virtual MediaPtr addStream( const std::string& mrl ) = 0;
virtual Query<IMedia> audioFiles( const QueryParameters* params = nullptr ) const = 0; virtual Query<IMedia> audioFiles( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> videoFiles( const QueryParameters* params = nullptr ) const = 0; virtual Query<IMedia> videoFiles( const QueryParameters* params = nullptr ) const = 0;
virtual AlbumPtr album( int64_t id ) const = 0; virtual AlbumPtr album( int64_t id ) const = 0;
......
...@@ -627,10 +627,10 @@ Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title, ...@@ -627,10 +627,10 @@ Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
" WHERE " + policy::MediaTable::Name + "Fts MATCH '*' || ? || '*')" " WHERE " + policy::MediaTable::Name + "Fts MATCH '*' || ? || '*')"
" AND f.is_present = 1" " AND f.is_present = 1"
" AND f.type = ?" " AND f.type = ?"
" AND m.type != ?"; " AND m.type != ? AND m.type != ?";
req += sortRequest( params ); req += sortRequest( params );
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main, return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main,
Media::Type::External ); Media::Type::External, Media::Type::Stream );
} }
Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title, Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
......
...@@ -435,13 +435,13 @@ MediaPtr MediaLibrary::media( const std::string& mrl ) const ...@@ -435,13 +435,13 @@ MediaPtr MediaLibrary::media( const std::string& mrl ) const
return file->media(); return file->media();
} }
MediaPtr MediaLibrary::addExternalMedia( const std::string& mrl ) MediaPtr MediaLibrary::addExternalMedia( const std::string& mrl, IMedia::Type type )
{ {
try try
{ {
return sqlite::Tools::withRetries( 3, [this, &mrl]() -> MediaPtr { return sqlite::Tools::withRetries( 3, [this, &mrl, type]() -> MediaPtr {
auto t = m_dbConnection->newTransaction(); auto t = m_dbConnection->newTransaction();
auto media = Media::create( this, IMedia::Type::External, utils::file::fileName( mrl ) ); auto media = Media::create( this, type, utils::file::fileName( mrl ) );
if ( media == nullptr ) if ( media == nullptr )
return nullptr; return nullptr;
if ( media->addExternalMrl( mrl, IFile::Type::Main ) == nullptr ) if ( media->addExternalMrl( mrl, IFile::Type::Main ) == nullptr )
...@@ -457,6 +457,16 @@ MediaPtr MediaLibrary::addExternalMedia( const std::string& mrl ) ...@@ -457,6 +457,16 @@ MediaPtr MediaLibrary::addExternalMedia( const std::string& mrl )
} }
} }
MediaPtr MediaLibrary::addExternalMedia( const std::string& mrl )
{
return addExternalMedia( mrl, IMedia::Type::External );
}
MediaPtr MediaLibrary::addStream( const std::string& mrl )
{
return addExternalMedia( mrl, IMedia::Type::Stream );
}
Query<IMedia> MediaLibrary::audioFiles( const QueryParameters* params ) const Query<IMedia> MediaLibrary::audioFiles( const QueryParameters* params ) const
{ {
return Media::listAll( this, IMedia::Type::Audio, params ); return Media::listAll( this, IMedia::Type::Audio, params );
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "Settings.h" #include "Settings.h"
#include "medialibrary/IDeviceLister.h" #include "medialibrary/IDeviceLister.h"
#include "medialibrary/IMedia.h"
namespace medialibrary namespace medialibrary
{ {
...@@ -73,6 +74,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb ...@@ -73,6 +74,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual MediaPtr media( int64_t mediaId ) const override; virtual MediaPtr media( int64_t mediaId ) const override;
virtual MediaPtr media( const std::string& mrl ) const override; virtual MediaPtr media( const std::string& mrl ) const override;
virtual MediaPtr addExternalMedia( const std::string& mrl ) override; virtual MediaPtr addExternalMedia( const std::string& mrl ) override;
virtual MediaPtr addStream( const std::string& mrl ) override;
virtual Query<IMedia> audioFiles( const QueryParameters* params ) const override; virtual Query<IMedia> audioFiles( const QueryParameters* params ) const override;
virtual Query<IMedia> videoFiles( const QueryParameters* params ) const override; virtual Query<IMedia> videoFiles( const QueryParameters* params ) const override;
...@@ -206,6 +208,8 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb ...@@ -206,6 +208,8 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
bool onDeviceChanged( fs::IFileSystemFactory& fsFactory, Device& device ); bool onDeviceChanged( fs::IFileSystemFactory& fsFactory, Device& device );
bool createThumbnailFolder( const std::string& thumbnailPath ) const; bool createThumbnailFolder( const std::string& thumbnailPath ) const;
MediaPtr addExternalMedia( const std::string& mrl, IMedia::Type type );
protected: protected:
virtual void addLocalFsFactory(); virtual void addLocalFsFactory();
......
...@@ -685,6 +685,31 @@ TEST_F( Medias, SortFilename ) ...@@ -685,6 +685,31 @@ TEST_F( Medias, SortFilename )
ASSERT_EQ( m3->id(), media[0]->id() ); ASSERT_EQ( m3->id(), media[0]->id() );
} }
TEST_F( Medias, CreateStream )
{
auto m1 = ml->addStream( "http://foo.bar/media.mkv" );
ASSERT_EQ( IMedia::Type::Stream, m1->type() );
}
TEST_F( Medias, SearchExternal )
{
auto m1 = std::static_pointer_cast<Media>( ml->addExternalMedia( "localfile.mkv" ) );
m1->setTitle( "local otter" );
auto m2 = std::static_pointer_cast<Media>( ml->addStream( "http://remote.file/media.asf" ) );
m2->setTitle( "remote otter" );
auto media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 0u, media.size() );
m1->setType( IMedia::Type::Video );
m1->save();
m2->setType( IMedia::Type::Video );
m2->save();
media = ml->searchMedia( "otter", nullptr )->all();
ASSERT_EQ( 2u, media.size() );
}
class FetchMedia : public Tests class FetchMedia : public Tests
{ {
protected: protected:
......
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