Media.h 5.06 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/DatabaseHelpers.h"
31

32

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

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

39
40
41
42
43
namespace sqlite
{
class Row;
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
44
45
namespace policy
{
46
struct MediaTable
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
47
48
{
    static const std::string Name;
49
    static const std::string PrimaryKeyColumn;
50
    static unsigned int Media::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
51
52
53
};
}

54
class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
55
56
{
    public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
57
58
59
60
        // 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...
61
        Media(DBConnection dbConnection , sqlite::Row& row);
62
        Media(const fs::IFile* file, unsigned int folderId, const std::string &title, Type type);
63

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

67
        virtual unsigned int id() const override;
68
        virtual Type type() override;
69
        void setType( Type type );
70
        virtual const std::string& title() override;
71
        void setTitle( const std::string& title );
72
73
        virtual AlbumTrackPtr albumTrack() override;
        bool setAlbumTrack( AlbumTrackPtr albumTrack );
74
        virtual const std::string& artist() const override;
75
        void setArtist( const std::string& artist );
76
        virtual int64_t duration() const override;
77
        void setDuration( int64_t duration);
78
        virtual std::shared_ptr<IShowEpisode> showEpisode() override;
79
        void setShowEpisode( ShowEpisodePtr showEpisode );
80
81
        virtual bool addLabel( LabelPtr label ) override;
        virtual bool removeLabel( LabelPtr label ) override;
82
        virtual std::vector<LabelPtr> labels() override;
83
        virtual int playCount() const  override;
84
        virtual void increasePlayCount() override;
85
86
        virtual const std::string& mrl() const override;
        virtual MoviePtr movie() override;
87
        void setMovie( MoviePtr movie );
88
        bool addVideoTrack( const std::string& codec, unsigned int width,
89
                                    unsigned int height, float fps );
90
        virtual std::vector<VideoTrackPtr> videoTracks() override;
91
92
        bool addAudioTrack(const std::string& codec, unsigned int bitrate, unsigned int sampleRate,
                           unsigned int nbChannels, const std::string& language, const std::string& desc );
93
        virtual std::vector<AudioTrackPtr> audioTracks() override;
94
        virtual const std::string& snapshot() override;
95
        virtual unsigned int insertionDate() const override;
96
        virtual bool isAvailable() const override;
97
98
        void setSnapshot( const std::string& snapshot );
        bool save();
99

100
101
        bool isStandAlone();
        unsigned int lastModificationDate();
102

103
104
105
        /// 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.
106
        void markParsed();
107
        bool isParsed() const;
108

109
    private:
110
        DBConnection m_dbConnection;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
111

112
113
114
        // DB fields:
        unsigned int m_id;
        Type m_type;
115
        int64_t m_duration;
116
        unsigned int m_playCount;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
117
        unsigned int m_showEpisodeId;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
118
        std::string m_mrl;
119
        std::string m_artist;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
120
        unsigned int m_movieId;
121
        unsigned int m_folderId;
122
        unsigned int m_lastModificationDate;
123
        unsigned int m_insertionDate;
124
        std::string m_snapshot;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
125
        bool m_isParsed;
126
        std::string m_title;
127
128

        // Auto fetched related properties
129
        AlbumTrackPtr m_albumTrack;
130
        ShowEpisodePtr m_showEpisode;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
131
        MoviePtr m_movie;
132
        bool m_changed;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
133

134
        friend struct policy::MediaTable;
135
136
137
};

#endif // FILE_H