MediaLibrary.h 3.57 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
#include "vlcpp/vlc.hpp"
12

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

21
        virtual std::vector<FilePtr> files() override;
22
23
        virtual std::vector<FilePtr> audioFiles() override;
        virtual std::vector<FilePtr> videoFiles() override;
24
25
26
27
        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;
28
29

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

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

36
37
        virtual AlbumPtr album( const std::string& title ) override;
        virtual AlbumPtr createAlbum( const std::string& title ) override;
38
        virtual std::vector<AlbumPtr> albums() override;
39

40
41
        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
42

43
44
        virtual MoviePtr movie( const std::string& title ) override;
        virtual MoviePtr createMovie( const std::string& title ) override;
45

46
47
48
49
50
        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;

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

54
    private:
55
56
        static const std::vector<std::string> supportedVideoExtensions;
        static const std::vector<std::string> supportedAudioExtensions;
57

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

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

72
73
74
75
        // 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;

76
77
78
79
80
81
        // 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;
82
83
};
#endif // MEDIALIBRARY_H