MediaLibrary.h 6.28 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
#ifndef MEDIALIBRARY_H
#define MEDIALIBRARY_H

26
class Parser;
27
class ParserService;
28
class DiscovererWorker;
29
class SqliteConnection;
30

31
#include "IMediaLibrary.h"
32
#include "IDiscoverer.h"
33
#include "logging/Logger.h"
34
#include "vlcpp/vlc.hpp"
35
#include "Settings.h"
36

37
38
class Album;
class Artist;
39
class Media;
40
41
class Movie;
class Show;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
42
class Device;
43
class Folder;
44
class Genre;
45

46
class MediaLibrary : public IMediaLibrary
47
48
49
{
    public:
        MediaLibrary();
50
        ~MediaLibrary();
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
51
        virtual bool initialize( const std::string& dbPath, const std::string& thumbnailPath, IMediaLibraryCb* metadataCb ) override;
52
        virtual void setVerbosity( LogLevel v ) override;
53
        virtual void setFsFactory( std::shared_ptr<factory::IFileSystem> fsFactory ) override;
54

55
        std::vector<MediaPtr> files();
56
57
        virtual std::vector<MediaPtr> audioFiles() override;
        virtual std::vector<MediaPtr> videoFiles() override;
58
        std::shared_ptr<Media> addFile( const std::string& path, Folder& parentFolder, fs::IDirectory& parentFolderFs );
59

60
        bool deleteFolder(const Folder& folder );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
61
        std::shared_ptr<Device> device( const std::string& uuid );
62

63
64
        virtual LabelPtr createLabel( const std::string& label ) override;
        virtual bool deleteLabel( LabelPtr label ) override;
65

66
        virtual AlbumPtr album( unsigned int id ) override;
67
        std::shared_ptr<Album> createAlbum( const std::string& title );
68
        virtual std::vector<AlbumPtr> albums() override;
69

70
71
        virtual std::vector<GenrePtr> genres() const override;

72
        virtual ShowPtr show( const std::string& name ) override;
73
        std::shared_ptr<Show> createShow( const std::string& name );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
74

75
        virtual MoviePtr movie( const std::string& title ) override;
76
        std::shared_ptr<Movie> createMovie( Media& media, const std::string& title );
77

78
79
        virtual ArtistPtr artist( unsigned int id ) override;
        ArtistPtr artist( const std::string& name );
80
        std::shared_ptr<Artist> createArtist( const std::string& name );
81
        virtual std::vector<ArtistPtr> artists() const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
82

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
83
84
85
86
        virtual PlaylistPtr createPlaylist( const std::string& name ) override;
        virtual std::vector<PlaylistPtr> playlists() override;
        virtual bool deletePlaylist( unsigned int playlistId ) override;

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
87
88
89
90
        virtual bool addToHistory( MediaPtr media );
        virtual bool addToHistory( const std::string& mrl );
        virtual std::vector<HistoryPtr> history() const;

91
        virtual medialibrary::MediaSearchAggregate searchMedia( const std::string& title ) const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
92
        virtual std::vector<PlaylistPtr> searchPlaylists( const std::string& name ) const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
93
        virtual std::vector<AlbumPtr> searchAlbums( const std::string& pattern ) const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
94
        virtual std::vector<GenrePtr> searchGenre( const std::string& genre ) const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
95
        virtual std::vector<ArtistPtr> searchArtists( const std::string& name ) const override;
96
        virtual medialibrary::SearchAggregate search( const std::string& pattern ) const override;
97

98
        virtual void discover( const std::string& entryPoint ) override;
99
        bool banFolder( const std::string& path ) override;
100
        bool unbanFolder( const std::string& path ) override;
101

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
102
        virtual const std::string& thumbnailPath() const override;
103
        virtual void setLogger( ILogger* logger ) override;
104
105
        //Temporarily public, move back to private as soon as we start monitoring the FS
        virtual void reload() override;
106
        virtual void reload( const std::string& entryPoint ) override;
107

108
109
110
        virtual void pauseBackgroundOperations() override;
        virtual void resumeBackgroundOperations() override;

111
112
113
    public:
        static const uint32_t DbModelVersion;

114
    private:
115
116
        static const std::vector<std::string> supportedVideoExtensions;
        static const std::vector<std::string> supportedAudioExtensions;
117

118
    private:
119
120
        virtual void startParser();
        virtual void startDiscoverer();
121
        bool updateDatabaseModel( unsigned int previousVersion );
122
        bool createAllTables();
123
        static bool validateSearchPattern( const std::string& pattern );
124

125
    protected:
126
        std::unique_ptr<SqliteConnection> m_dbConnection;
127
        std::shared_ptr<factory::IFileSystem> m_fsFactory;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
128
        std::string m_thumbnailPath;
129
        IMediaLibraryCb* m_callback;
130

131
132
133
134
        // This probably qualifies as a work around, but we need to keep the VLC::Instance
        // alive to be able to use the logging wrapper lambda
        VLC::Instance m_vlcInstance;

135
136
137
138
139
140
        // Keep the parser as last field.
        // The parser holds a (raw) pointer to the media library. When MediaLibrary's destructor gets called
        // it might still finish a few operations before exiting the parser thread. Those operations are
        // likely to require a valid MediaLibrary, which would be compromised if some fields have already been
        // deleted/destroyed.
        std::unique_ptr<Parser> m_parser;
141
142
143
        // Same reasoning applies here.
        //FIXME: Having to maintain a specific ordering sucks, let's use shared_ptr or something
        std::unique_ptr<DiscovererWorker> m_discoverer;
144
        LogLevel m_verbosity;
145
        Settings m_settings;
146
147
};
#endif // MEDIALIBRARY_H