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

IMediaLibrary: Allow audio or video media to be searched

parent a5c453a5
......@@ -313,8 +313,28 @@ class IMediaLibrary
/**
* Search
*/
/**
* @brief searchMedia, searchAudio, and searchVideo search for some media, based on a pattern.
* @param pattern A 3 character or more pattern that will be matched against the media's title
* or filename if no title was set for this media.
* @param params Some query parameters. Valid sorting criteria are:
* - Duration
* - InsertionDate
* - ReleaseDate
* - PlayCount
* - Filename
* - LastModificationDate
* - FileSize
* Default sorting parameter uses the media's title.
* Passing nullptr will default to default ascending sort
* @return
*/
virtual MediaSearchAggregate searchMedia( const std::string& pattern,
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> searchAudio( const std::string& pattern, const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> searchVideo( const std::string& pattern, const QueryParameters* params = nullptr ) const = 0;
virtual Query<IPlaylist> searchPlaylists( const std::string& name,
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IAlbum> searchAlbums( const std::string& pattern,
......
......@@ -691,6 +691,21 @@ Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main, subType );
}
Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
Media::Type type, const QueryParameters* params )
{
std::string req = "FROM " + policy::MediaTable::Name + " m "
" INNER JOIN " + policy::FileTable::Name + " f ON m.id_media = f.media_id"
" WHERE"
" m.id_media IN (SELECT rowid FROM " + policy::MediaTable::Name + "Fts"
" WHERE " + policy::MediaTable::Name + "Fts MATCH '*' || ? || '*')"
" AND f.is_present = 1"
" AND f.type = ?"
" AND m.type = ?";
req += sortRequest( params );
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main, type );
}
Query<IMedia> Media::fetchHistory( MediaLibraryPtr ml )
{
static const std::string req = "FROM " + policy::MediaTable::Name + " WHERE last_played_date IS NOT NULL"
......
......@@ -127,6 +127,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
static Query<IMedia> search( MediaLibraryPtr ml, const std::string& title,
Media::SubType subType, const QueryParameters* params );
static Query<IMedia> search( MediaLibraryPtr ml, const std::string& title,
Media::Type type, const QueryParameters* params );
static Query<IMedia> fetchHistory( MediaLibraryPtr ml );
static void clearHistory( MediaLibraryPtr ml );
......
......@@ -723,6 +723,20 @@ MediaSearchAggregate MediaLibrary::searchMedia( const std::string& title,
return res;
}
Query<IMedia> MediaLibrary::searchAudio( const std::string& pattern, const QueryParameters* params ) const
{
if ( validateSearchPattern( pattern ) == false )
return {};
return Media::search( this, pattern, IMedia::Type::Audio, params );
}
Query<IMedia> MediaLibrary::searchVideo( const std::string& pattern, const QueryParameters* params ) const
{
if ( validateSearchPattern( pattern ) == false )
return {};
return Media::search( this, pattern, IMedia::Type::Audio, params );
}
Query<IPlaylist> MediaLibrary::searchPlaylists( const std::string& name,
const QueryParameters* params ) const
{
......
......@@ -118,6 +118,10 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual MediaSearchAggregate searchMedia( const std::string& title,
const QueryParameters* params ) const override;
virtual Query<IMedia> searchAudio( const std::string& pattern,
const QueryParameters* params = nullptr ) const override;
virtual Query<IMedia> searchVideo( const std::string& pattern,
const QueryParameters* params = nullptr ) const override;
virtual Query<IPlaylist> searchPlaylists( const std::string& name,
const QueryParameters* params ) const override;
virtual Query<IAlbum> searchAlbums( const std::string& pattern,
......
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