Media.h 4.98 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 FILE_H
#define FILE_H

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
26

27 28
#include <sqlite3.h>

29
#include "IMedia.h"
30
#include "database/Cache.h"
31

32 33 34 35
class Album;
class ShowEpisode;
class AlbumTrack;

36
class Media;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
37 38 39

namespace policy
{
40
struct MediaTable
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
41 42 43
{
    static const std::string Name;
    static const std::string CacheColumn;
44
    static unsigned int Media::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
45
};
46
struct MediaCache
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
47 48
{
    typedef std::string KeyType;
49
    static const std::string& key(const std::shared_ptr<Media> self);
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
50 51 52 53
    static std::string key( sqlite3_stmt* stmt );
};
}

54
class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, policy::MediaCache>
55
{
56
    private:
57
        typedef Cache<Media, IMedia, policy::MediaTable, policy::MediaCache> _Cache;
58 59
    public:

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
60 61 62 63
        // Those should be private, however the standard states that the expression
        // ::new (pv) T(std::forward(args)...)
        // shall be well-formed, and private constructor would prevent that.
        // There might be a way with a user-defined allocator, but we'll see that later...
64 65
        Media(DBConnection dbConnection , sqlite3_stmt* stmt);
        Media(const fs::IFile* file, unsigned int folderId, const std::string &name, Type type);
66

67
        static std::shared_ptr<Media> create(DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId);
68
        static bool createTable( DBConnection connection );
69

70
        virtual unsigned int id() const;
71
        virtual Type type() override;
72
        virtual bool setType( Type type );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
73
        virtual const std::string& name() override;
74
        virtual bool setName( const std::string& name );
75 76
        virtual AlbumTrackPtr albumTrack();
        virtual bool setAlbumTrack( AlbumTrackPtr albumTrack );
77
        virtual int64_t duration() const;
78
        virtual bool setDuration( int64_t duration);
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
79
        virtual std::shared_ptr<IShowEpisode> showEpisode();
80
        virtual bool setShowEpisode( ShowEpisodePtr showEpisode );
81 82 83
        virtual bool addLabel( LabelPtr label );
        virtual bool removeLabel( LabelPtr label );
        virtual std::vector<std::shared_ptr<ILabel> > labels();
84 85
        virtual int playCount() const;
        virtual const std::string& mrl() const;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86 87
        virtual MoviePtr movie();
        virtual bool setMovie( MoviePtr movie );
88 89
        virtual bool addVideoTrack( const std::string& codec, unsigned int width,
                                    unsigned int height, float fps );
90
        virtual std::vector<VideoTrackPtr> videoTracks();
91
        virtual bool addAudioTrack(const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
92
        virtual std::vector<AudioTrackPtr> audioTracks();
93
        virtual const std::string& snapshot() override;
94
        virtual bool setSnapshot( const std::string& snapshot );
95

96 97
        virtual bool isStandAlone();
        virtual unsigned int lastModificationDate();
98

99 100 101 102 103
        /// Explicitely mark a file as fully parsed, meaning no metadata service needs to run anymore.
        //FIXME: This lacks granularity as we don't have a straight forward way to know which service
        //needs to run or not.
        virtual bool markParsed();
        virtual bool isParsed() const;
104

105
    private:
106
        DBConnection m_dbConnection;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
107

108 109 110
        // DB fields:
        unsigned int m_id;
        Type m_type;
111
        int64_t m_duration;
112
        unsigned int m_albumTrackId;
113
        unsigned int m_playCount;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
114
        unsigned int m_showEpisodeId;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
115
        std::string m_mrl;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
116
        unsigned int m_movieId;
117
        unsigned int m_folderId;
118
        unsigned int m_lastModificationDate;
119
        std::string m_snapshot;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
120
        bool m_isParsed;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
121
        std::string m_name;
122 123 124

        // Auto fetched related properties
        Album* m_album;
125
        AlbumTrackPtr m_albumTrack;
126
        ShowEpisodePtr m_showEpisode;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
127
        MoviePtr m_movie;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
128

129 130
        friend class Cache<Media, IMedia, policy::MediaTable, policy::MediaCache>;
        friend struct policy::MediaTable;
131 132 133
};

#endif // FILE_H