| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2013 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_
|
|---|
| 20 | #define _RETRIEVEYOUTUBEURL_
|
|---|
| 21 |
|
|---|
| 22 | #include <QNetworkAccessManager>
|
|---|
| 23 | #include <QNetworkReply>
|
|---|
| 24 | #include <QMap>
|
|---|
| 25 |
|
|---|
| 26 | #define YT_GET_VIDEOINFO
|
|---|
| 27 | //#define YT_DASH_SUPPORT
|
|---|
| 28 |
|
|---|
| 29 | class RetrieveYoutubeUrl : public QObject
|
|---|
| 30 | {
|
|---|
| 31 | Q_OBJECT
|
|---|
| 32 |
|
|---|
| 33 | public:
|
|---|
| 34 | enum Quality { FLV_240p = 5, MP4_360p = 18, MP4_720p = 22, FLV_360p = 34,
|
|---|
| 35 | FLV_480p = 35, MP4_1080p = 37, WEBM_360p = 43,
|
|---|
| 36 | WEBM_480p = 44, WEBM_720p = 45, WEBM_1080p = 46,
|
|---|
| 37 | DASH_AUDIO_MP4_48 = 139, DASH_AUDIO_MP4_128 = 140, DASH_AUDIO_MP4_256 = 141,
|
|---|
| 38 | DASH_AUDIO_WEBM_128 = 171, DASH_AUDIO_WEBM_192 = 172,
|
|---|
| 39 | DASH_VIDEO_1080p = 137, DASH_VIDEO_720p = 136,
|
|---|
| 40 | DASH_VIDEO_480p = 135, DASH_VIDEO_360p = 134,
|
|---|
| 41 | DASH_VIDEO_240p = 133 };
|
|---|
| 42 |
|
|---|
| 43 | RetrieveYoutubeUrl( QObject* parent = 0 );
|
|---|
| 44 | ~RetrieveYoutubeUrl();
|
|---|
| 45 |
|
|---|
| 46 | void fetchPage(const QString & url);
|
|---|
| 47 | void close();
|
|---|
| 48 |
|
|---|
| 49 | static void setUserAgent(const QString & s) { user_agent = s; };
|
|---|
| 50 | static QString userAgent() { return user_agent; };
|
|---|
| 51 |
|
|---|
| 52 | void setPreferredQuality(Quality q) { preferred_quality = q; }
|
|---|
| 53 | Quality preferredQuality() { return preferred_quality; }
|
|---|
| 54 |
|
|---|
| 55 | static QString findPreferredUrl(const QMap<int, QString>& urlMap, Quality q);
|
|---|
| 56 | QString findPreferredUrl();
|
|---|
| 57 |
|
|---|
| 58 | #ifdef YT_DASH_SUPPORT
|
|---|
| 59 | static QString findBestAudio(const QMap<int, QString>& urlMap);
|
|---|
| 60 | #endif
|
|---|
| 61 |
|
|---|
| 62 | QString urlTitle() { return url_title; }
|
|---|
| 63 | QString latestPreferredUrl() { return latest_preferred_url; }
|
|---|
| 64 | QString origUrl() { return orig_url; }
|
|---|
| 65 |
|
|---|
| 66 | bool isUrlSupported(const QString & url);
|
|---|
| 67 | QString fullUrl(const QString & url);
|
|---|
| 68 |
|
|---|
| 69 | static void setUseHttpsMain(bool b) { use_https_main = b; };
|
|---|
| 70 | static void setUseHttpsVi(bool b) { use_https_vi = b; };
|
|---|
| 71 | static bool useHttpsMain() { return use_https_main; };
|
|---|
| 72 | static bool useHttpsVi() { return use_https_vi; };
|
|---|
| 73 |
|
|---|
| 74 | signals:
|
|---|
| 75 | void gotUrls(const QMap<int, QString>&);
|
|---|
| 76 | void gotPreferredUrl(const QString &);
|
|---|
| 77 | void gotEmptyList();
|
|---|
| 78 | #ifdef YT_GET_VIDEOINFO
|
|---|
| 79 | void gotVideoInfo(const QMap<int, QString>&, QString, QString);
|
|---|
| 80 | #endif
|
|---|
| 81 |
|
|---|
| 82 | void connecting(QString host);
|
|---|
| 83 | void errorOcurred(int error_number, QString error_str);
|
|---|
| 84 |
|
|---|
| 85 | void signatureNotFound(const QString & title);
|
|---|
| 86 |
|
|---|
| 87 | protected slots:
|
|---|
| 88 | void gotResponse();
|
|---|
| 89 | void parse(QByteArray text);
|
|---|
| 90 | #ifdef YT_GET_VIDEOINFO
|
|---|
| 91 | void gotVideoInfoResponse();
|
|---|
| 92 | void parseVideoInfo(QByteArray text);
|
|---|
| 93 | void fetchVideoInfoPage(QString url = QString::null);
|
|---|
| 94 | #endif
|
|---|
| 95 |
|
|---|
| 96 | protected:
|
|---|
| 97 | static QString sanitizeForUnicodePoint(QString string);
|
|---|
| 98 | static void htmlDecode(QString& string);
|
|---|
| 99 | QString getVideoID(QString video_url);
|
|---|
| 100 |
|
|---|
| 101 | QMap<int, QString> urlMap;
|
|---|
| 102 | QString url_title;
|
|---|
| 103 | QString orig_url;
|
|---|
| 104 | QString latest_preferred_url;
|
|---|
| 105 |
|
|---|
| 106 | Quality preferred_quality;
|
|---|
| 107 | static QString user_agent;
|
|---|
| 108 | static bool use_https_main;
|
|---|
| 109 | static bool use_https_vi;
|
|---|
| 110 |
|
|---|
| 111 | #ifdef YT_GET_VIDEOINFO
|
|---|
| 112 | QString video_id;
|
|---|
| 113 | #endif
|
|---|
| 114 |
|
|---|
| 115 | private:
|
|---|
| 116 | QNetworkAccessManager* manager;
|
|---|
| 117 | QNetworkReply* reply;
|
|---|
| 118 | };
|
|---|
| 119 |
|
|---|
| 120 | #endif
|
|---|