From ddd01cc5588aef83bdc11d80521a619071e6de16 Mon Sep 17 00:00:00 2001 From: nextime <nextime@nexlab.it> Date: Thu, 28 Feb 2013 02:14:13 +0100 Subject: [PATCH] Fake user agent on youtube requests on Mac OSX --- src/mainwin.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/mainwin.cpp b/src/mainwin.cpp index bc82eb1..97834cd 100644 --- a/src/mainwin.cpp +++ b/src/mainwin.cpp @@ -47,6 +47,27 @@ #define SENDER "maingui" + +#if defined(Q_OS_MAC) +/* + * For some reason youtube think that the default user agent + * on OSX doesn't support HTML5 videos, + * so, we change it faking the Linux one + */ +class QWebPageForMac : public QWebPage +{ + Q_OBJECT + public: + QString userAgentForUrl(const QUrl &url) const; +}; + +QString QWebPageForMac::userAgentForUrl(const QUrl &url) const +{ + return "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) skylivex Safari/537.21"; +} + +#endif + MainWin::MainWin(QString &htmlfile) : SkylivexWin(htmlfile) { @@ -145,7 +166,11 @@ void MainWin::handle_youtubevideo(SKMessage &msg) { yt = new WebWin(); yt_is_open=true; + #if defined(Q_OS_MAC) + QWebPageForMac *newWeb = new QWebPageForMac(yt); + #else QWebPage *newWeb = new QWebPage(yt); + #endif yt->setPage(newWeb); yt->setAttribute(Qt::WA_DeleteOnClose, true); -- 2.18.1