]> git.sur5r.net Git - minitube/blob - src/video.h
Imported Upstream version 2.3.1
[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 parseJsPlayer(QByteArray bytes);
101     void parseDashManifest(QByteArray bytes);
102
103 private:
104     void getVideoInfo();
105     void parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage = false);
106     void captureFunction(const QString &name, const QString &js);
107     void captureObject(const QString &name, const QString &js);
108     QString decryptSignature(const QString &s);
109
110     QString m_title;
111     QString m_description;
112     QString m_author;
113     QString m_userId;
114     QUrl m_webpage;
115     QUrl m_streamUrl;
116     QPixmap m_thumbnail;
117     QString m_thumbnailUrl;
118     QString m_mediumThumbnailUrl;
119     int m_duration;
120     QDateTime m_published;
121     int m_viewCount;
122     License m_license;
123     QString videoId;
124     QString videoToken;
125     int definitionCode;
126
127     // current index for the elTypes list
128     // needed to iterate on elTypes
129     int elIndex;
130     bool ageGate;
131     
132     bool loadingStreamUrl;
133     bool loadingThumbnail;
134
135     QString fmtUrlMap;
136     QString sigFuncName;
137     QHash<QString, QString> sigFunctions;
138     QHash<QString, QString> sigObjects;
139
140     QString dashManifestUrl;
141 };
142
143 // This is required in order to use QPointer<Video> as a QVariant
144 // as used by the Model/View playlist
145 typedef QPointer<Video> VideoPointer;
146 Q_DECLARE_METATYPE(VideoPointer)
147
148 #endif // VIDEO_H