]> git.sur5r.net Git - minitube/blob - src/video.h
Big 2.1 commit
[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     const QString & title() const { return m_title; }
36     void setTitle( QString title ) { m_title = title; }
37
38     const QString & description() const { return m_description; }
39     void setDescription( QString description ) { m_description = description; }
40
41     const QString & author() const { return m_author; }
42     void setAuthor( QString author ) { m_author = author; }
43
44     const QString & userId() const { return m_userId; }
45     void setUserId( QString userId ) { m_userId = userId; }
46
47     const QUrl & webpage() const { return m_webpage; }
48     void setWebpage(QUrl webpage);
49
50     void loadThumbnail();
51     const QPixmap & thumbnail() const { return m_thumbnail; }
52
53     const QString & thumbnailUrl() { return m_thumbnailUrl; }
54     void setThumbnailUrl(QString url) { m_thumbnailUrl = url; }
55
56     void loadMediumThumbnail();
57     const QString & mediumThumbnailUrl() { return m_mediumThumbnailUrl; }
58     void setMediumThumbnailUrl(QString url) { m_mediumThumbnailUrl = url; }
59
60     int duration() const { return m_duration; }
61     void setDuration( int duration ) { m_duration = duration; }
62     QString formattedDuration() const;
63
64     int viewCount() const { return m_viewCount; }
65     void setViewCount( int viewCount ) { m_viewCount = viewCount; }
66
67     const QDateTime & published() const { return m_published; }
68     void setPublished( QDateTime published ) { m_published = published; }
69
70     int getDefinitionCode() const { return definitionCode; }
71
72     void loadStreamUrl();
73     const QUrl & getStreamUrl() { return m_streamUrl; }
74
75     void setId(QString id) { videoId = id; }
76     const QString & id() const { return videoId; }
77
78 signals:
79     void gotThumbnail();
80     void gotMediumThumbnail(QByteArray bytes);
81     void gotStreamUrl(QUrl streamUrl);
82     void errorStreamUrl(QString message);
83
84 private slots:
85     void setThumbnail(QByteArray bytes);
86     void gotVideoInfo(QByteArray);
87     void errorVideoInfo(QNetworkReply*);
88     void scrapeWebPage(QByteArray);
89     void gotHeadHeaders(QNetworkReply*);
90
91 private:
92     void getVideoInfo();
93     void findVideoUrl(int definitionCode);
94     void foundVideoUrl(QString videoToken, int definitionCode);
95     void parseFmtUrlMap(QString fmtUrlMap, bool fromWebPage = false);
96
97     QString m_title;
98     QString m_description;
99     QString m_author;
100     QString m_userId;
101     QUrl m_webpage;
102     QUrl m_streamUrl;
103     QPixmap m_thumbnail;
104     QString m_thumbnailUrl;
105     QString m_mediumThumbnailUrl;
106     int m_duration;
107     QDateTime m_published;
108     int m_viewCount;
109
110     QString videoId;
111     QString videoToken;
112     int definitionCode;
113
114     // current index for the elTypes list
115     // needed to iterate on elTypes
116     int elIndex;
117     
118     bool loadingStreamUrl;
119 };
120
121 // This is required in order to use QPointer<Video> as a QVariant
122 // as used by the Model/View playlist
123 typedef QPointer<Video> VideoPointer;
124 Q_DECLARE_METATYPE(VideoPointer)
125
126 #endif // VIDEO_H