]> git.sur5r.net Git - minitube/blob - src/video.h
Imported Upstream version 2.2
[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 #include <QtNetwork>
26
27 class Video : public QObject {
28
29     Q_OBJECT
30
31 public:
32     Video();
33     Video* clone();
34
35     enum License {
36         LicenseYouTube = 1,
37         LicenseCC
38     };
39
40     const QString & title() const { return m_title; }
41     void setTitle( QString title ) { m_title = title; }
42
43     const QString & description() const { return m_description; }
44     void setDescription( QString description ) { m_description = description; }
45
46     const QString & author() const { return m_author; }
47     void setAuthor( QString author ) { m_author = author; }
48
49     const QString & userId() const { return m_userId; }
50     void setUserId( QString userId ) { m_userId = userId; }
51
52     const QUrl & webpage() const { return m_webpage; }
53     void setWebpage(QUrl webpage);
54
55     void loadThumbnail();
56     const QPixmap & thumbnail() const { return m_thumbnail; }
57
58     const QString & thumbnailUrl() { return m_thumbnailUrl; }
59     void setThumbnailUrl(QString url) { m_thumbnailUrl = url; }
60
61     void loadMediumThumbnail();
62     const QString & mediumThumbnailUrl() { return m_mediumThumbnailUrl; }
63     void setMediumThumbnailUrl(QString url) { m_mediumThumbnailUrl = url; }
64
65     int duration() const { return m_duration; }
66     void setDuration( int duration ) { m_duration = duration; }
67     QString formattedDuration() const;
68
69     int viewCount() const { return m_viewCount; }
70     void setViewCount( int viewCount ) { m_viewCount = viewCount; }
71
72     const QDateTime & published() const { return m_published; }
73     void setPublished( QDateTime published ) { m_published = published; }
74
75     int getDefinitionCode() const { return definitionCode; }
76
77     void loadStreamUrl();
78     const QUrl & getStreamUrl() { return m_streamUrl; }
79
80     void setId(QString id) { videoId = id; }
81     const QString & id() const { return videoId; }
82
83     void setLicense(License license) { m_license = license; }
84     License license() const { return m_license; }
85
86 signals:
87     void gotThumbnail();
88     void gotMediumThumbnail(QByteArray bytes);
89     void gotStreamUrl(QUrl streamUrl);
90     void errorStreamUrl(QString message);
91
92 private slots:
93     void setThumbnail(QByteArray bytes);
94     void gotVideoInfo(QByteArray);
95     void errorVideoInfo(QNetworkReply*);
96     void scrapeWebPage(QByteArray);
97     void gotHeadHeaders(QNetworkReply*);
98     void parseJsPlayer(QByteArray);
99
100 private:
101     void getVideoInfo();
102     void findVideoUrl(int definitionCode);
103     void foundVideoUrl(QString videoToken, int definitionCode);
104     void parseFmtUrlMap(const QString &fmtUrlMap, bool fromWebPage = false);
105     void captureFunction(const QString &name, const QString &js);
106     void captureObject(const QString &name, const QString &js);
107     QString decryptSignature(const QString &s);
108
109     QString m_title;
110     QString m_description;
111     QString m_author;
112     QString m_userId;
113     QUrl m_webpage;
114     QUrl m_streamUrl;
115     QPixmap m_thumbnail;
116     QString m_thumbnailUrl;
117     QString m_mediumThumbnailUrl;
118     int m_duration;
119     QDateTime m_published;
120     int m_viewCount;
121     License m_license;
122     QString videoId;
123     QString videoToken;
124     int definitionCode;
125
126     // current index for the elTypes list
127     // needed to iterate on elTypes
128     int elIndex;
129     bool ageGate;
130     
131     bool loadingStreamUrl;
132     bool loadingThumbnail;
133
134     QString fmtUrlMap;
135     QString sigFuncName;
136     QHash<QString, QString> sigFunctions;
137     QHash<QString, QString> sigObjects;
138 };
139
140 // This is required in order to use QPointer<Video> as a QVariant
141 // as used by the Model/View playlist
142 typedef QPointer<Video> VideoPointer;
143 Q_DECLARE_METATYPE(VideoPointer)
144
145 #endif // VIDEO_H