MediaLibrary.h 3.3 KB
Newer Older
1
2
3
#ifndef MEDIALIBRARY_H
#define MEDIALIBRARY_H

4
5
class Parser;

6
7
8
#include <sqlite3.h>

#include "IMediaLibrary.h"
9
#include "IDiscoverer.h"
10
#include "logging/Logger.h"
11

12
class MediaLibrary : public IMediaLibrary, public IDiscovererCb
13
14
15
{
    public:
        MediaLibrary();
16
        ~MediaLibrary();
17
        virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, IMediaLibraryCb* metadataCb );
18
        virtual void setFsFactory( std::shared_ptr<factory::IFileSystem> fsFactory ) override;
19

20
        virtual std::vector<FilePtr> files() override;
21
22
        virtual std::vector<FilePtr> audioFiles() override;
        virtual std::vector<FilePtr> videoFiles() override;
23
24
25
26
        virtual FilePtr file( const std::string& path ) override;
        virtual FilePtr addFile( const std::string& path ) override;
        virtual bool deleteFile( const std::string& mrl ) override;
        virtual bool deleteFile( FilePtr file ) override;
27
28

        virtual FolderPtr folder( const std::string& path ) override;
29
        virtual bool deleteFolder( FolderPtr folder ) override;
30

31
32
33
        virtual LabelPtr createLabel( const std::string& label ) override;
        virtual bool deleteLabel(const std::string& text ) override;
        virtual bool deleteLabel( LabelPtr label ) override;
34

35
36
        virtual AlbumPtr album( const std::string& title ) override;
        virtual AlbumPtr createAlbum( const std::string& title ) override;
37

38
39
        virtual ShowPtr show( const std::string& name ) override;
        virtual ShowPtr createShow( const std::string& name ) override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
40

41
42
        virtual MoviePtr movie( const std::string& title ) override;
        virtual MoviePtr createMovie( const std::string& title ) override;
43

44
45
46
47
48
        virtual void discover( const std::string& entryPoint ) override;
        // IDiscovererCb implementation
        virtual FolderPtr onNewFolder( const fs::IDirectory* directory, FolderPtr parent ) override;
        virtual FilePtr onNewFile(const fs::IFile* file, FolderPtr parent ) override;

49
        virtual const std::string& snapshotPath() const override;
50
        virtual void setLogger( ILogger* logger ) override;
51

52
    private:
53
54
        static const std::vector<std::string> supportedVideoExtensions;
        static const std::vector<std::string> supportedAudioExtensions;
55

56
57
58
    private:
        bool loadFolders();
        bool checkSubfolders( fs::IDirectory* folder, unsigned int parentId );
59
        void checkFiles( fs::IDirectory* folder, unsigned int parentId );
60
        FilePtr addFile( const fs::IFile* file, unsigned int folderId );
61
        void addMetadataService( std::unique_ptr<IMetadataService> service );
62

63
    private:
64
        std::shared_ptr<sqlite3> m_dbConnection;
65
        std::shared_ptr<factory::IFileSystem> m_fsFactory;
66
        std::vector<std::unique_ptr<IDiscoverer>> m_discoverers;
67
        std::string m_snapshotPath;
68
        IMediaLibraryCb* m_callback;
69
70
71
72
73
74
75

        // 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;
76
77
};
#endif // MEDIALIBRARY_H