]> git.sur5r.net Git - minitube/blob - src/video.h
Upload 2.5.1-1 to unstable
[minitube] / src / video.h
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #ifndef VIDEO_H
22 #define VIDEO_H
23
24 #include <QtGui>
25 #if QT_VERSION >= 0x050000
26 #include <QtWidgets>
27 #endif
28 #include <QtNetwork>
29
30 class VideoDefinition;
31
32 class Video : public QObject {
33
34     Q_OBJECT
35
36 public:
37     Video();
38     Video* clone();
39
40     enum License {
41         LicenseYouTube = 1,
42         LicenseCC
43     };
44
45     const QString &title() const { return m_title; }
46     void setTitle(const QString &value) { m_title = value; }
47
48     const QString &description() const { return m_description; }
49     void setDescription(const QString &value) { m_description = value; }
50
51     const QString &channelTitle() const { return m_channelTitle; }
52     void setChannelTitle(const QString &value) { m_channelTitle = value; }
53
54     const QString &channelId() const { return m_channelId; }
55     void setChannelId(const QString &value ) { m_channelId = value; }
56
57     const QString &webpage();
58     void setWebpage(const QString &value);
59
60     void loadThumbnail();
61     const QPixmap &thumbnail() const { return m_thumbnail; }
62
63     const QString &thumbnailUrl() { return m_thumbnailUrl; }
64     void setThumbnailUrl(const QString &value) { m_thumbnailUrl = value; }
65
66     const QString &mediumThumbnailUrl() { return m_mediumThumbnailUrl; }
67     void setMediumThumbnailUrl(const QString &value) { m_mediumThumbnailUrl = value; }
68
69     const QString &largeThumbnailUrl() { return m_largeThumbnailUrl; }
70     void setLargeThumbnailUrl(const QString &value) { m_largeThumbnailUrl = value; }
71
72     int duration() const { return m_duration; }
73     void setDuration(int value) { m_duration = value; }
74     QString formattedDuration() const;
75
76     int viewCount() const { return m_viewCount; }
77     void setViewCount(int viewCount) { m_viewCount = viewCount; }
78
79     const QDateTime &published() const { return m_published; }
80     void setPublished(const QDateTime &value) { m_published = value; }
81
82     int getDefinitionCode() const { return definitionCode; }
83
84     void loadStreamUrl();
85     const QUrl &getStreamUrl() { return m_streamUrl; }
86
87     void setId(const QString &value) { videoId = value; }
88     const QString &id() const { return videoId; }
89
90     void setLicense(License value) { m_license = value; }
91     License license() const { return m_license; }
92
93 signals:
94     void gotThumbnail();
95     void gotMediumThumbnail(const QByteArray &bytes);
96     void gotLargeThumbnail(const QByteArray &bytes);
97     void gotStreamUrl(const QUrl &streamUrl);
98     void errorStreamUrl(const QString &message);
99
100 private slots:
101     void setThumbnail(const QByteArray &bytes);
102     void gotVideoInfo(const QByteArray &bytes);
103     void errorVideoInfo(QNetworkReply *reply);
104     void scrapeWebPage(const QByteArray &bytes);
105     void parseJsPlayer(const QByteArray &bytes);
106     void parseDashManifest(const QByteArray &bytes);
107
108 private:
109     void getVideoInfo();
110     void parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage = false);
111     void captureFunction(const QString &name, const QString &js);
112     void captureObject(const QString &name, const QString &js);
113     QString decryptSignature(const QString &s);
114     void saveDefinitionForUrl(const QString &url, const VideoDefinition &definition);
115
116     QString m_title;
117     QString m_description;
118     QString m_channelTitle;
119     QString m_channelId;
120     QString m_webpage;
121     QUrl m_streamUrl;
122     QPixmap m_thumbnail;
123     QString m_thumbnailUrl;
124     QString m_mediumThumbnailUrl;
125     QString m_largeThumbnailUrl;
126     int m_duration;
127     QDateTime m_published;
128     int m_viewCount;
129     License m_license;
130     QString videoId;
131     QString videoToken;
132     int definitionCode;
133
134     // current index for the elTypes list
135     // needed to iterate on elTypes
136     int elIndex;
137     bool ageGate;
138     
139     bool loadingStreamUrl;
140     bool loadingThumbnail;
141
142     QString fmtUrlMap;
143     QString sigFuncName;
144     QHash<QString, QString> sigFunctions;
145     QHash<QString, QString> sigObjects;
146
147     QString dashManifestUrl;
148 };
149
150 // This is required in order to use QPointer<Video> as a QVariant
151 // as used by the Model/View playlist
152 typedef QPointer<Video> VideoPointer;
153 Q_DECLARE_METATYPE(VideoPointer)
154
155 #endif // VIDEO_H