View Single Post
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#325
Originally Posted by MohammadAG View Post
marxian, any ideas on how to get the cookie (then pass it)?, I've looked at cutetube and it doesn't seem to be doing that.
As things stand, I have no need to use cookies in cuteTube-QML. Videos play fine using any of the external media players. I'm only guessing that the solution for QMediaPlayer is to pass a YouTube cookie when making the HTTP request to play the video. I can't think of any other reason why it doesn't work. When using QMediaPlayer, the YouTube server must be aware that the origin of the request is different from that when the video webpage was downloaded, but this problem doesn't exist when using other media players.

However, I was able to get the cookies for the videoUrl:

Code:
void YouTube::getVideoUrl(const QString &videoId) {
    QString playerUrl = "http://www.youtube.com/get_video_info?&video_id=" + videoId + "&el=detailpage&ps=default&eurl=&gl=US&hl=en";
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    QNetworkRequest request;
    request.setUrl(QUrl(playerUrl));
    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(parseVideoPage(QNetworkReply*)));
    manager->get(request);
}

void YouTube::parseVideoPage(QNetworkReply *reply) {
    QNetworkAccessManager *manager = qobject_cast<QNetworkAccessManager*>(sender());
    qDebug() << manager->cookieJar()->cookiesForUrl(reply->request().url());

...
This last line returned

Code:
(QNetworkCookie("use_hitbox=72c46ff6cbcdb7c5585c36411b6b334edAEAAAAw; domain=.youtube.com; path=/") ,  QNetworkCookie("VISITOR_INFO1_LIVE=-DzhOBbT2vs; expires=Tue, 17-Jan-2012 13:49:30 GMT; domain=.youtube.com; path=/") ,  QNetworkCookie("GEO=a2731021266fb55d211af8f75b6cb61fcwsAAAAzR0JShPI6TdkUag==; domain=.youtube.com; path=/") ,  QNetworkCookie("s_gl=18f5cd48020458e865a469a7155238dacwIAAABVUw==; domain=.youtube.com; path=/") )
So, hopefully you can just pass this list of cookies to the QNetworkRequest used by QMediaPlayer (maybe emit the cookie list along with the url as part of the gotVideoUrl() signal).

I will have a little play around and see if I can get it to work.

EDIT: No need to set the cookie jar to a new instance of QNetworkCookieJar. The constructor of QNetworkAccessManager must do this already.
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub

Last edited by marxian; 2011-05-22 at 14:15.
 

The Following 6 Users Say Thank You to marxian For This Useful Post: