MediaLibrary.h 2.86 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

11
class MediaLibrary : public IMediaLibrary, public IDiscovererCb
12
13
14
{
    public:
        MediaLibrary();
15
        ~MediaLibrary();
16
        virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory );
17

18
        virtual std::vector<FilePtr> files();
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
19
20
        virtual FilePtr file( const std::string& path );
        virtual FilePtr addFile( const std::string& path );
21
22
        virtual bool deleteFile( const std::string& mrl );
        virtual bool deleteFile( FilePtr file );
23
24

        virtual FolderPtr folder( const std::string& path ) override;
25
        virtual bool deleteFolder( FolderPtr folder ) override;
26

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
27
28
29
        virtual LabelPtr createLabel( const std::string& label );
        virtual bool deleteLabel(const std::string& text );
        virtual bool deleteLabel( LabelPtr label );
30

31
32
        virtual AlbumPtr album( const std::string& title );
        virtual AlbumPtr createAlbum( const std::string& title );
33

34
35
36
        virtual ShowPtr show( const std::string& name );
        virtual ShowPtr createShow( const std::string& name );

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
37
38
39
        virtual MoviePtr movie( const std::string& title );
        virtual MoviePtr createMovie( const std::string& title );

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
40
        virtual void addMetadataService( std::unique_ptr<IMetadataService> service );
41
        virtual void parse( FilePtr file, IMetadataCb* cb );
42

43
44
45
46
47
        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;

48
49
        virtual const std::string& snapshotPath() const override;

50
51
52
    private:
        static const std::vector<std::string> supportedExtensions;

53
54
55
    private:
        bool loadFolders();
        bool checkSubfolders( fs::IDirectory* folder, unsigned int parentId );
56
        void checkFiles( fs::IDirectory* folder, unsigned int parentId );
57
        FilePtr addFile( const fs::IFile* file, unsigned int folderId );
58

59
    private:
60
        std::shared_ptr<sqlite3> m_dbConnection;
61
        std::shared_ptr<factory::IFileSystem> m_fsFactory;
62
        std::vector<std::unique_ptr<IDiscoverer>> m_discoverers;
63
64
65
66
67
68
69
70
        std::string m_snapshotPath;

        // 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;
71
72
};
#endif // MEDIALIBRARY_H