]> git.sur5r.net Git - minitube/blob - src/video.h
d48a848c47ce93e8946d840066f05badb05a75da
[minitube] / src / video.h
1 #ifndef VIDEO_H
2 #define VIDEO_H
3
4 #include <QtGui>
5 #include <QtNetwork>
6
7 class Video : public QObject {
8
9     Q_OBJECT
10
11 public:
12     Video();
13     Video* clone();
14
15     const QString title() const { return m_title; }
16     void setTitle( QString title ) { m_title = title; }
17
18     const QString description() const { return m_description; }
19     void setDescription( QString description ) { m_description = description; }
20
21     const QString author() const { return m_author; }
22     void setAuthor( QString author ) { m_author = author; }
23
24     const QString authorUri() const { return m_authorUri; }
25     void setAuthorUri( QString authorUri ) { m_authorUri = authorUri; }
26
27     const QUrl webpage() const { return m_webpage; }
28     void setWebpage( QUrl webpage ) { m_webpage = webpage; }
29
30     QList<QUrl> thumbnailUrls() const { return m_thumbnailUrls; }
31     void addThumbnailUrl(QUrl url) {
32         m_thumbnailUrls << url;
33     }
34
35     void preloadThumbnail();
36     const QImage thumbnail() const;
37
38     int duration() const { return m_duration; }
39     void setDuration( int duration ) { m_duration = duration; }
40
41     int viewCount() const { return m_viewCount; }
42     void setViewCount( int viewCount ) { m_viewCount = viewCount; }
43
44     const QDateTime published() const { return m_published; }
45     void setPublished( QDateTime published ) { m_published = published; }
46
47     int getDefinitionCode() const { return definitionCode; }
48
49     void loadStreamUrl();
50     QUrl getStreamUrl() { return m_streamUrl; }
51
52     QString id() { return videoId; }
53
54 public slots:
55     void setThumbnail(QByteArray bytes);
56
57 signals:
58     void gotThumbnail();
59     void gotStreamUrl(QUrl streamUrl);
60     void errorStreamUrl(QString message);
61
62 private slots:
63     void gotVideoInfo(QByteArray);
64     void errorVideoInfo(QNetworkReply*);
65     void scrapeWebPage(QByteArray);
66     void gotHeadHeaders(QNetworkReply*);
67
68 private:
69     void getVideoInfo();
70     void findVideoUrl(int definitionCode);
71     void foundVideoUrl(QString videoToken, int definitionCode);
72
73     QString m_title;
74     QString m_description;
75     QString m_author;
76     QString m_authorUri;
77     QUrl m_webpage;
78     QUrl m_streamUrl;
79     QImage m_thumbnail;
80     QList<QUrl> m_thumbnailUrls;
81     int m_duration;
82     QDateTime m_published;
83     int m_viewCount;
84
85     // The YouTube video id
86     // This is needed by the gotVideoInfo callback
87     QString videoId;
88
89     QString videoToken;
90     int definitionCode;
91
92     // current index for the elTypes list
93     // needed to iterate on elTypes
94     int elIndex;
95     
96     bool loadingStreamUrl;
97 };
98
99 // This is required in order to use QPointer<Video> as a QVariant
100 // as used by the Model/View playlist
101 typedef QPointer<Video> VideoPointer;
102 Q_DECLARE_METATYPE(VideoPointer)
103
104 #endif // VIDEO_H