Search code examples
qtvideodownloadvimeodailymotion-api

Qt FrameWork - Download video from vimeo, dailymotion


How i can download videos from vimeo or dailymotion using Qt FrameWork. Here is my code, but its not working:

downloadManager = new QNetworkAccessManager(this);
QNetworkRequest request;
request.setUrl(QUrl("https://www.dailymotion.com/cdn/H264-1280x720/video/x5e553p.mp4?auth=1489424955-2562-4nmhj8lt-a840543181f17a50d614a6ff23ad5c07")); 

QSslConfiguration configSsl = QSslConfiguration::defaultConfiguration();    
configSsl.setProtocol(QSsl::AnyProtocol);
request.setSslConfiguration(configSsl);
replyn = downloadManager->get(request);

This url https://www.dailymotion.com/cdn/H264-1280x720/video/x5e553p.mp4?auth=1489424955-2562-4nmhj8lt-a840543181f17a50d614a6ff23ad5c07 redirect to https://proxy-058.dc3.dailymotion.com/video/793/580/326085397_mp4_h264_aac_hd.mp4?auth=1489259396-6658-s68i24c0-6b97977318a7dbd81ef264afc469ffa1#cell=core&hls_heuristic=1&hls_startFragPrefetch=1


Solution

  • QNetworkAccessManager does not handle HTTP redirection. You will have to handle it yourself by sending a new QNetworkRequest.

    The new URL should be in the HTTP Location header. To get it you can use QNetworkReply::header(QNetworkRequest::LocationHeader).

    QUrl newUrl = replyn->header(QNetworkRequest::LocationHeader).toUrl();
    QNetworkRequest request;
    request.setUrl(newUrl);
    ...
    

    Note that I have used QVariant::toUrl() to convert the QVariant to a QUrl, but you might need to convert the QVariant to a QString and then to an QUrl.