[121] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[121] | 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 |
|
---|
[176] | 19 | #ifndef RETRIEVEYOUTUBEURL_H
|
---|
| 20 | #define RETRIEVEYOUTUBEURL_H
|
---|
[121] | 21 |
|
---|
[156] | 22 | #include <QNetworkAccessManager>
|
---|
[121] | 23 | #include <QMap>
|
---|
[176] | 24 | #include "loadpage.h"
|
---|
[121] | 25 |
|
---|
[176] | 26 | #ifdef YT_USE_SIG
|
---|
| 27 | #include "sig.h"
|
---|
| 28 | #endif
|
---|
| 29 |
|
---|
| 30 | class QSettings;
|
---|
| 31 |
|
---|
[165] | 32 | #define YT_GET_VIDEOINFO
|
---|
[170] | 33 | //#define YT_DASH_SUPPORT
|
---|
[176] | 34 | #define YT_LIVE_STREAM
|
---|
[165] | 35 |
|
---|
[176] | 36 | #ifdef YT_GET_VIDEOINFO
|
---|
| 37 | #define YT_DISCARD_HTTPS
|
---|
| 38 | #endif
|
---|
| 39 |
|
---|
| 40 | typedef QMap<int,QString> UrlMap;
|
---|
| 41 |
|
---|
[156] | 42 | class RetrieveYoutubeUrl : public QObject
|
---|
[121] | 43 | {
|
---|
| 44 | Q_OBJECT
|
---|
| 45 |
|
---|
| 46 | public:
|
---|
| 47 | enum Quality { FLV_240p = 5, MP4_360p = 18, MP4_720p = 22, FLV_360p = 34,
|
---|
[170] | 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 };
|
---|
[121] | 55 |
|
---|
| 56 | RetrieveYoutubeUrl( QObject* parent = 0 );
|
---|
| 57 | ~RetrieveYoutubeUrl();
|
---|
| 58 |
|
---|
| 59 | void setPreferredQuality(Quality q) { preferred_quality = q; }
|
---|
| 60 | Quality preferredQuality() { return preferred_quality; }
|
---|
| 61 |
|
---|
[176] | 62 | void setUserAgent(const QString & s) { LoadPage::setDefaultUserAgent(s); };
|
---|
| 63 | QString userAgent() { return LoadPage::defaultUserAgent(); };
|
---|
[121] | 64 |
|
---|
[176] | 65 | void fetchPage(const QString & url);
|
---|
| 66 |
|
---|
| 67 | #ifdef YT_USE_SIG
|
---|
| 68 | void setSettings(QSettings * settings);
|
---|
| 69 | #endif
|
---|
| 70 |
|
---|
[170] | 71 | #ifdef YT_DASH_SUPPORT
|
---|
[176] | 72 | static int findBestAudio(const QMap<int, QString>& url_map); // Returns the itag
|
---|
[170] | 73 | #endif
|
---|
| 74 |
|
---|
[121] | 75 | QString urlTitle() { return url_title; }
|
---|
[176] | 76 | QString origUrl() { return yt_url; }
|
---|
| 77 |
|
---|
[121] | 78 | QString latestPreferredUrl() { return latest_preferred_url; }
|
---|
| 79 |
|
---|
[165] | 80 | bool isUrlSupported(const QString & url);
|
---|
| 81 | QString fullUrl(const QString & url);
|
---|
| 82 |
|
---|
[176] | 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; };
|
---|
[170] | 87 |
|
---|
[176] | 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 |
|
---|
[121] | 93 | signals:
|
---|
| 94 | void gotUrls(const QMap<int, QString>&);
|
---|
[176] | 95 | //void gotPreferredUrl(const QString &);
|
---|
| 96 | void gotPreferredUrl(const QString & url, int itag);
|
---|
[121] | 97 | void gotEmptyList();
|
---|
[156] | 98 | void connecting(QString host);
|
---|
| 99 | void errorOcurred(int error_number, QString error_str);
|
---|
| 100 | void signatureNotFound(const QString & title);
|
---|
[176] | 101 | void noSslSupport();
|
---|
[156] | 102 |
|
---|
[121] | 103 | protected slots:
|
---|
[176] | 104 | void videoPageLoaded(QByteArray page);
|
---|
[165] | 105 | #ifdef YT_GET_VIDEOINFO
|
---|
[176] | 106 | void videoInfoPageLoaded(QByteArray page);
|
---|
[165] | 107 | #endif
|
---|
[176] | 108 | #ifdef YT_USE_SIG
|
---|
| 109 | void playerPageLoaded(QByteArray page);
|
---|
| 110 | #endif
|
---|
| 111 | #ifdef YT_LIVE_STREAM
|
---|
| 112 | void streamPageLoaded(QByteArray page);
|
---|
| 113 | #endif
|
---|
[121] | 114 |
|
---|
[176] | 115 | void processVideoPage();
|
---|
| 116 |
|
---|
[121] | 117 | protected:
|
---|
[176] | 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 |
|
---|
[165] | 129 | QString getVideoID(QString video_url);
|
---|
[176] | 130 | UrlMap extractURLs(QString fmtArray, bool allow_https, bool use_player);
|
---|
[121] | 131 |
|
---|
[176] | 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 |
|
---|
| 140 | private:
|
---|
| 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;
|
---|
[121] | 161 | QString url_title;
|
---|
| 162 |
|
---|
| 163 | Quality preferred_quality;
|
---|
[176] | 164 | bool use_https_main;
|
---|
| 165 | bool use_https_vi;
|
---|
[156] | 166 |
|
---|
[176] | 167 | QString yt_url;
|
---|
[165] | 168 | QString video_id;
|
---|
| 169 |
|
---|
[176] | 170 | QString latest_preferred_url;
|
---|
| 171 |
|
---|
| 172 | bool failed_to_decrypt_signature;
|
---|
[121] | 173 | };
|
---|
| 174 |
|
---|
| 175 | #endif
|
---|
[176] | 176 |
|
---|