]> git.sur5r.net Git - minitube/blob - src/video.h
d502cb24d6dee94f1fa5287ccc5c09a60a257299
[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 &title) { m_title = title; }
47
48     const QString & description() const { return m_description; }
49     void setDescription(const QString &description) { m_description = description; }
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 &url) { m_thumbnailUrl = url; }
65
66     void loadMediumThumbnail();
67     const QString & mediumThumbnailUrl() { return m_mediumThumbnailUrl; }
68     void setMediumThumbnailUrl(const QString &url) { m_mediumThumbnailUrl = url; }
69
70     int duration() const { return m_duration; }
71     void setDuration( int duration ) { m_duration = duration; }
72     QString formattedDuration() const;
73
74     int viewCount() const { return m_viewCount; }
75     void setViewCount( int viewCount ) { m_viewCount = viewCount; }
76
77     const QDateTime & published() const { return m_published; }
78     void setPublished(const QDateTime &published ) { m_published = published; }
79
80     int getDefinitionCode() const { return definitionCode; }
81
82     void loadStreamUrl();
83     const QUrl & getStreamUrl() { return m_streamUrl; }
84
85     void setId(const QString &value) { videoId = value; }
86     const QString & id() const { return videoId; }
87
88     void setLicense(License license) { m_license = license; }
89     License license() const { return m_license; }
90
91 signals:
92     void gotThumbnail();
93     void gotMediumThumbnail(QByteArray bytes);
94     void gotStreamUrl(QUrl streamUrl);
95     void errorStreamUrl(QString message);
96
97 private slots:
98     void setThumbnail(QByteArray bytes);
99     void gotVideoInfo(QByteArray);
100     void errorVideoInfo(QNetworkReply*);
101     void scrapeWebPage(QByteArray);
102     void parseJsPlayer(QByteArray bytes);
103     void parseDashManifest(QByteArray bytes);
104
105 private:
106     void getVideoInfo();
107     void parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage = false);
108     void captureFunction(const QString &name, const QString &js);
109     void captureObject(const QString &name, const QString &js);
110     QString decryptSignature(const QString &s);
111     void saveDefinitionForUrl(const QString& url, const VideoDefinition& definition);
112
113     QString m_title;
114     QString m_description;
115     QString m_channelTitle;
116     QString m_channelId;
117     QString m_webpage;
118     QUrl m_streamUrl;
119     QPixmap m_thumbnail;
120     QString m_thumbnailUrl;
121     QString m_mediumThumbnailUrl;
122     int m_duration;
123     QDateTime m_published;
124     int m_viewCount;
125     License m_license;
126     QString videoId;
127     QString videoToken;
128     int definitionCode;
129
130     // current index for the elTypes list
131     // needed to iterate on elTypes
132     int elIndex;
133     bool ageGate;
134     
135     bool loadingStreamUrl;
136     bool loadingThumbnail;
137
138     QString fmtUrlMap;
139     QString sigFuncName;
140     QHash<QString, QString> sigFunctions;
141     QHash<QString, QString> sigObjects;
142
143     QString dashManifestUrl;
144 };
145
146 // This is required in order to use QPointer<Video> as a QVariant
147 // as used by the Model/View playlist
148 typedef QPointer<Video> VideoPointer;
149 Q_DECLARE_METATYPE(VideoPointer)
150
151 #endif // VIDEO_H