Media.h 5.14 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
#include "utils/Cache.h"
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

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

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

59
        static std::shared_ptr<Media> create( DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId, bool isRemovable );
60
        static bool createTable( DBConnection connection );
61

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

94
95
        bool isStandAlone();
        unsigned int lastModificationDate();
96

97
98
99
        /// 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.
100
        void markParsed();
101
        bool isParsed() const;
102

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

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

        // Auto fetched related properties
125
        AlbumTrackPtr m_albumTrack;
126
        ShowEpisodePtr m_showEpisode;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
127
        MoviePtr m_movie;
128
        bool m_changed;
129
        mutable Cache<std::string> m_fullPath;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
130

131
        friend struct policy::MediaTable;
132
133
134
};

#endif // FILE_H