IMediaLibrary.h 9.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
 *
 * Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23 24 25 26 27 28
#ifndef IMEDIALIBRARY_H
#define IMEDIALIBRARY_H

#include <vector>
#include <string>

29
#include "Types.h"
30

31 32 33 34
namespace medialibrary
{
    static constexpr auto UnknownArtistID = 1u;
    static constexpr auto VariousArtistID = 2u;
35

36 37 38 39 40 41 42 43
    struct MediaSearchAggregate
    {
        std::vector<MediaPtr> episodes;
        std::vector<MediaPtr> movies;
        std::vector<MediaPtr> others;
        std::vector<MediaPtr> tracks;
    };

44 45 46 47
    struct SearchAggregate
    {
        std::vector<AlbumPtr> albums;
        std::vector<ArtistPtr> artists;
48
        std::vector<GenrePtr> genres;
49
        MediaSearchAggregate media;
50 51
        std::vector<PlaylistPtr> playlists;
    };
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

    enum class SortingCriteria
    {
        /*
         * Default depends on the entity type:
         * - By track number (and disc number) for album tracks
         * - Alphabetical order for others
         */
        Default,
        Alpha,
        Duration,
        InsertionDate,
        LastModificationDate,
        ReleaseDate,
    };
67 68
}

69
class IMediaLibraryCb
70
{
71
public:
72
    virtual ~IMediaLibraryCb() = default;
73
    /**
74
     * @brief onFileAdded Will be called when some media get added.
75 76
     * Depending if the media is being restored or was just discovered,
     * the media type might be a best effort guess. If the media was freshly
77 78
     * discovered, it is extremely likely that no metadata will be
     * available yet.
79
     * The number of media is undefined, but is guaranteed to be at least 1.
80
     */
81
    virtual void onMediaAdded( std::vector<MediaPtr> media ) = 0;
82 83
    /**
     * @brief onFileUpdated Will be called when a file metadata gets updated.
84
     */
85
    virtual void onMediaUpdated( std::vector<MediaPtr> media ) = 0;
86

87 88
    virtual void onMediaDeleted( std::vector<int64_t> ids ) = 0;

89 90 91
    virtual void onArtistsAdded( std::vector<ArtistPtr> artists ) = 0;
    virtual void onArtistsModified( std::vector<ArtistPtr> artist ) = 0;
    virtual void onArtistsDeleted( std::vector<int64_t> ids ) = 0;
92

93 94 95
    virtual void onAlbumsAdded( std::vector<AlbumPtr> albums ) = 0;
    virtual void onAlbumsModified( std::vector<AlbumPtr> albums ) = 0;
    virtual void onAlbumsDeleted( std::vector<int64_t> ids ) = 0;
96 97 98 99
    /**
     * @brief onTrackAdded Called when a media gets detected as an album track
     * and after it has been added to the album representation
     */
100 101 102
    virtual void onTracksAdded( std::vector<AlbumTrackPtr> tracks ) = 0;
    // Tracks are never modified after their creation, so there is no tracksModified event
    virtual void onTracksDeleted( std::vector<int64_t> trackIds ) = 0;
103

104 105
    virtual void onDiscoveryStarted( const std::string& entryPoint ) = 0;
    virtual void onDiscoveryCompleted( const std::string& entryPoint ) = 0;
106 107
    virtual void onReloadStarted( const std::string& entryPoint ) = 0;
    virtual void onReloadCompleted( const std::string& entryPoint ) = 0;
108 109 110
    /**
     * @brief onParsingStatsUpdated Called when the parser statistics are updated
     *
111 112
     * There is no waranty about how often this will be called.
     * @param percent The progress percentage [0,100]
113 114
     *
     */
115
    virtual void onParsingStatsUpdated( uint32_t percent) = 0;
116 117
};

118
class IMediaLibrary
119 120
{
    public:
121
        virtual ~IMediaLibrary() = default;
122
        ///
123 124 125
        /// \brief  initialize Initializes the media library.
        ///         This will use the provided discoverer to search for new media asynchronously.
        ///
126 127 128
        /// \param dbPath       Path to the database
        /// \return true in case of success, false otherwise
        ///
129
        virtual bool initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* metadataCb ) = 0;
130
        virtual void setVerbosity( LogLevel v ) = 0;
131

132
        virtual LabelPtr createLabel( const std::string& label ) = 0;
133
        virtual bool deleteLabel( LabelPtr label ) = 0;
134 135
        virtual std::vector<MediaPtr> audioFiles( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
        virtual std::vector<MediaPtr> videoFiles( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
136
        virtual AlbumPtr album( int64_t id ) const = 0;
137
        virtual std::vector<AlbumPtr> albums( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
138 139
        virtual ShowPtr show( const std::string& name ) const = 0;
        virtual MoviePtr movie( const std::string& title ) const = 0;
140
        virtual ArtistPtr artist( int64_t id ) const = 0;
141 142 143 144 145 146 147
        /**
         * @brief artists List all artists that have at least an album.
         * Artists that only appear on albums as guests won't be listed from here, but will be
         * returned when querying an album for all its appearing artists
         * @param sort A sorting criteria. So far, this is ignored, and artists are sorted by lexial order
         * @param desc If true, the provided sorting criteria will be reversed.
         */
148
        virtual std::vector<ArtistPtr> artists( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
149 150 151 152 153
        /**
         * @brief genres Return the list of music genres
         * @param sort A sorting criteria. So far, this is ignored, and artists are sorted by lexial order
         * @param desc If true, the provided sorting criteria will be reversed.
         */
154
        virtual std::vector<GenrePtr> genres( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
155
        virtual GenrePtr genre( int64_t id ) const = 0;
156 157 158 159
        /***
         *  Playlists
         */
        virtual PlaylistPtr createPlaylist( const std::string& name ) = 0;
160
        virtual std::vector<PlaylistPtr> playlists( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) = 0;
161
        virtual PlaylistPtr playlist( int64_t id ) const = 0;
162
        virtual bool deletePlaylist( int64_t playlistId ) = 0;
163

164 165 166 167
        /**
         * History
         */
        virtual bool addToHistory( const std::string& mrl ) = 0;
168 169
        virtual std::vector<HistoryPtr> lastStreamsPlayed() const = 0;
        virtual std::vector<MediaPtr> lastMediaPlayed() const = 0;
170

171 172 173
        /**
         * Search
         */
174
        virtual medialibrary::MediaSearchAggregate searchMedia( const std::string& pattern ) const = 0;
175
        virtual std::vector<PlaylistPtr> searchPlaylists( const std::string& name ) const = 0;
176
        virtual std::vector<AlbumPtr> searchAlbums( const std::string& pattern ) const = 0;
177
        virtual std::vector<GenrePtr> searchGenre( const std::string& genre ) const = 0;
178
        virtual std::vector<ArtistPtr> searchArtists( const std::string& name ) const = 0;
179
        virtual medialibrary::SearchAggregate search( const std::string& pattern ) const = 0;
180

181 182
        /**
         * @brief discover Launch a discovery on the provided entry point.
183
         * The actuall discovery will run asynchronously, meaning this method will immediatly return.
184 185 186 187
         * Depending on which discoverer modules where provided, this might or might not work
         * @param entryPoint What to discover.
         */
        virtual void discover( const std::string& entryPoint ) = 0;
188
        /**
189
         * @brief banFolder will blacklist a folder for discovery
190
         */
191
        virtual bool banFolder( const std::string& path ) = 0;
192
        virtual bool unbanFolder( const std::string& path ) = 0;
193
        virtual const std::string& thumbnailPath() const = 0;
194
        virtual void setLogger( ILogger* logger ) = 0;
195 196 197 198 199 200 201 202 203 204 205
        /**
         * @brief pauseBackgroundOperations Will stop potentially CPU intensive background
         * operations, until resumeBackgroundOperations() is called.
         * If an operation is currently running, it will finish before pausing.
         */
        virtual void pauseBackgroundOperations() = 0;
        /**
         * @brief resumeBackgroundOperations Resumes background tasks, previously
         * interrupted by pauseBackgroundOperations().
         */
        virtual void resumeBackgroundOperations() = 0;
206
        virtual void reload() = 0;
207
        virtual void reload( const std::string& entryPoint ) = 0;
208 209
};

210
extern "C"
211
{
212 213
    IMediaLibrary* NewMediaLibrary();
}
214

215
#endif // IMEDIALIBRARY_H