MediaLibrary.h 5.04 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 DiscovererWorker;
28
class SqliteConnection;
29

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

35
36
class Album;
class Artist;
37
class Media;
38
39
40
class Movie;
class Show;

41
class MediaLibrary : public IMediaLibrary
42
43
44
{
    public:
        MediaLibrary();
45
        ~MediaLibrary();
46
        virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, IMediaLibraryCb* metadataCb ) override;
47
        virtual void setVerbosity( LogLevel v ) override;
48
        virtual void setFsFactory( std::shared_ptr<factory::IFileSystem> fsFactory ) override;
49

50
        std::vector<MediaPtr> files();
51
52
53
54
        virtual std::vector<MediaPtr> audioFiles() override;
        virtual std::vector<MediaPtr> videoFiles() override;
        virtual MediaPtr file( const std::string& path ) override;
        std::shared_ptr<Media> addFile(const std::string& path , FolderPtr parentFolder);
55
        virtual bool deleteFile( const std::string& mrl ) override;
56
        virtual bool deleteFile( MediaPtr file ) override;
57
58

        virtual FolderPtr folder( const std::string& path ) override;
59
        virtual bool deleteFolder( FolderPtr folder ) override;
60

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

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

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

72
        virtual MoviePtr movie( const std::string& title ) override;
73
        std::shared_ptr<Movie> createMovie( const std::string& title );
74

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
75
        virtual ArtistPtr artist( const std::string& name ) override;
76
        virtual ArtistPtr unknownArtist() override;
77
        std::shared_ptr<Artist> createArtist( const std::string& name );
78
        virtual std::vector<ArtistPtr> artists() const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
79

80
81
        virtual void discover( const std::string& entryPoint ) override;

82
        virtual const std::string& snapshotPath() const override;
83
        virtual void setLogger( ILogger* logger ) override;
84
85
        //Temporarily public, move back to private as soon as we start monitoring the FS
        virtual void reload() override;
86

87
    private:
88
89
        static const std::vector<std::string> supportedVideoExtensions;
        static const std::vector<std::string> supportedAudioExtensions;
90

91
    private:
92
        void addMetadataService( std::unique_ptr<IMetadataService> service );
93

94
    private:
95
        std::unique_ptr<SqliteConnection> m_dbConnection;
96
        std::shared_ptr<factory::IFileSystem> m_fsFactory;
97
        std::string m_snapshotPath;
98
        IMediaLibraryCb* m_callback;
99
100
101
        // Unknown artist "cache". If a track has been parsed with an unknown artist, this
        // won't change (until we reload or detect a change)
        ArtistPtr m_unknownArtist;
102

103
104
105
106
        // 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;

107
108
109
110
111
112
        // 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;
113
114
115
        // 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;
116
        LogLevel m_verbosity;
117
118
};
#endif // MEDIALIBRARY_H