]> git.sur5r.net Git - minitube/blob - src/video.h
Imported Upstream version 2.3
[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 Video : public QObject {
31
32     Q_OBJECT
33
34 public:
35     Video();
36     Video* clone();
37
38     enum License {
39         LicenseYouTube = 1,
40         LicenseCC
41     };
42
43     const QString & title() const { return m_title; }
44     void setTitle( QString title ) { m_title = title; }
45
46     const QString & description() const { return m_description; }
47     void setDescription( QString description ) { m_description = description; }
48
49     const QString & author() const { return m_author; }
50     void setAuthor( QString author ) { m_author = author; }
51
52     const QString & userId() const { return m_userId; }
53     void setUserId( QString userId ) { m_userId = userId; }
54
55     const QUrl & webpage() const { return m_webpage; }
56     void setWebpage(QUrl webpage);
57
58     void loadThumbnail();
59     const QPixmap & thumbnail() const { return m_thumbnail; }
60
61     const QString & thumbnailUrl() { return m_thumbnailUrl; }
62     void setThumbnailUrl(QString url) { m_thumbnailUrl = url; }
63
64     void loadMediumThumbnail();
65     const QString & mediumThumbnailUrl() { return m_mediumThumbnailUrl; }
66     void setMediumThumbnailUrl(QString url) { m_mediumThumbnailUrl = url; }
67
68     int duration() const { return m_duration; }
69     void setDuration( int duration ) { m_duration = duration; }
70     QString formattedDuration() const;
71
72     int viewCount() const { return m_viewCount; }
73     void setViewCount( int viewCount ) { m_viewCount = viewCount; }
74
75     const QDateTime & published() const { return m_published; }
76     void setPublished( QDateTime published ) { m_published = published; }
77
78     int getDefinitionCode() const { return definitionCode; }
79
80     void loadStreamUrl();
81     const QUrl & getStreamUrl() { return m_streamUrl; }
82
83     void setId(QString id) { videoId = id; }
84     const QString & id() const { return videoId; }
85
86     void setLicense(License license) { m_license = license; }
87     License license() const { return m_license; }
88
89 signals:
90     void gotThumbnail();
91     void gotMediumThumbnail(QByteArray bytes);
92     void gotStreamUrl(QUrl streamUrl);
93     void errorStreamUrl(QString message);
94
95 private slots:
96     void setThumbnail(QByteArray bytes);
97     void gotVideoInfo(QByteArray);
98     void errorVideoInfo(QNetworkReply*);
99     void scrapeWebPage(QByteArray);
100     void gotHeadHeaders(QNetworkReply*);
101     void parseJsPlayer(QByteArray bytes);
102     void parseDashManifest(QByteArray bytes);
103
104 private:
105     void getVideoInfo();
106     void findVideoUrl(int definitionCode);
107     void foundVideoUrl(QString videoToken, int definitionCode);
108     void parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage = false);
109     void captureFunction(const QString &name, const QString &js);
110     void captureObject(const QString &name, const QString &js);
111     QString decryptSignature(const QString &s);
112
113     QString m_title;
114     QString m_description;
115     QString m_author;
116     QString m_userId;
117     QUrl 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