source: smplayer/trunk/src/youtube/retrieveyoutubeurl.h

Last change on this file was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

File size: 4.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#ifndef RETRIEVEYOUTUBEURL_H
20#define RETRIEVEYOUTUBEURL_H
21
22#include <QNetworkAccessManager>
23#include <QMap>
24#include "loadpage.h"
25
26#ifdef YT_USE_SIG
27#include "sig.h"
28#endif
29
30class QSettings;
31
32#define YT_GET_VIDEOINFO
33//#define YT_DASH_SUPPORT
34#define YT_LIVE_STREAM
35
36#ifdef YT_GET_VIDEOINFO
37#define YT_DISCARD_HTTPS
38#endif
39
40typedef QMap<int,QString> UrlMap;
41
42class RetrieveYoutubeUrl : public QObject
43{
44 Q_OBJECT
45
46public:
47 enum Quality { FLV_240p = 5, MP4_360p = 18, MP4_720p = 22, FLV_360p = 34,
48 FLV_480p = 35, MP4_1080p = 37, WEBM_360p = 43,
49 WEBM_480p = 44, WEBM_720p = 45, WEBM_1080p = 46,
50 DASH_AUDIO_MP4_48 = 139, DASH_AUDIO_MP4_128 = 140, DASH_AUDIO_MP4_256 = 141,
51 DASH_AUDIO_WEBM_128 = 171, DASH_AUDIO_WEBM_192 = 172,
52 DASH_VIDEO_1080p = 137, DASH_VIDEO_720p = 136,
53 DASH_VIDEO_480p = 135, DASH_VIDEO_360p = 134,
54 DASH_VIDEO_240p = 133 };
55
56 RetrieveYoutubeUrl( QObject* parent = 0 );
57 ~RetrieveYoutubeUrl();
58
59 void setPreferredQuality(Quality q) { preferred_quality = q; }
60 Quality preferredQuality() { return preferred_quality; }
61
62 void setUserAgent(const QString & s) { LoadPage::setDefaultUserAgent(s); };
63 QString userAgent() { return LoadPage::defaultUserAgent(); };
64
65 void fetchPage(const QString & url);
66
67#ifdef YT_USE_SIG
68 void setSettings(QSettings * settings);
69#endif
70
71#ifdef YT_DASH_SUPPORT
72 static int findBestAudio(const QMap<int, QString>& url_map); // Returns the itag
73#endif
74
75 QString urlTitle() { return url_title; }
76 QString origUrl() { return yt_url; }
77
78 QString latestPreferredUrl() { return latest_preferred_url; }
79
80 bool isUrlSupported(const QString & url);
81 QString fullUrl(const QString & url);
82
83 void setUseHttpsMain(bool b) { use_https_main = b; };
84 void setUseHttpsVi(bool b) { use_https_vi = b; };
85 bool useHttpsMain() { return use_https_main; };
86 bool useHttpsVi() { return use_https_vi; };
87
88 static int findPreferredUrl(const UrlMap & url_map, Quality q); // Returns the itag
89 static QString extensionForItag(int itag);
90
91 void close() { /* FIXME: do something */ };
92
93signals:
94 void gotUrls(const QMap<int, QString>&);
95 //void gotPreferredUrl(const QString &);
96 void gotPreferredUrl(const QString & url, int itag);
97 void gotEmptyList();
98 void connecting(QString host);
99 void errorOcurred(int error_number, QString error_str);
100 void signatureNotFound(const QString & title);
101 void noSslSupport();
102
103protected slots:
104 void videoPageLoaded(QByteArray page);
105#ifdef YT_GET_VIDEOINFO
106 void videoInfoPageLoaded(QByteArray page);
107#endif
108#ifdef YT_USE_SIG
109 void playerPageLoaded(QByteArray page);
110#endif
111#ifdef YT_LIVE_STREAM
112 void streamPageLoaded(QByteArray page);
113#endif
114
115 void processVideoPage();
116
117protected:
118 void fetchVideoPage(const QString & url);
119#ifdef YT_GET_VIDEOINFO
120 void fetchVideoInfoPage(const QString & url);
121#endif
122#ifdef YT_USE_SIG
123 void fetchPlayerPage(const QString & player_name);
124#endif
125#ifdef YT_LIVE_STREAM
126 void fetchStreamPage(const QString & url);
127#endif
128
129 QString getVideoID(QString video_url);
130 UrlMap extractURLs(QString fmtArray, bool allow_https, bool use_player);
131
132 void finish(const UrlMap & url_map);
133
134#ifdef YT_USE_SCRIPT
135 QString aclara(const QString & text, const QString & player = "");
136#endif
137
138 static QString sanitizeForUnicodePoint(QString string);
139
140private:
141 QNetworkAccessManager* manager;
142 LoadPage * dl_video_page;
143
144#ifdef YT_GET_VIDEOINFO
145 LoadPage * dl_video_info_page;
146#endif
147
148#ifdef YT_USE_SIG
149 LoadPage * dl_player_page;
150 Sig sig;
151 QSettings * set;
152#else
153 QString html5_player;
154#endif
155
156#ifdef YT_LIVE_STREAM
157 LoadPage * dl_stream_page;
158#endif
159
160 QString video_page;
161 QString url_title;
162
163 Quality preferred_quality;
164 bool use_https_main;
165 bool use_https_vi;
166
167 QString yt_url;
168 QString video_id;
169
170 QString latest_preferred_url;
171
172 bool failed_to_decrypt_signature;
173};
174
175#endif
176
Note: See TracBrowser for help on using the repository browser.