Qt FrameWork - 从vimeo,dailymotion下载视频

时间:2017-03-11 17:10:37

标签: qt video download vimeo dailymotion-api

如何使用Qt FrameWork从vimeo或dailymotion下载视频。这是我的代码,但它不起作用:

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);

此网址https://www.dailymotion.com/cdn/H264-1280x720/video/x5e553p.mp4?auth=1489424955-2562-4nmhj8lt-a840543181f17a50d614a6ff23ad5c07重定向到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

1 个答案:

答案 0 :(得分:1)

QNetworkAccessManager不处理HTTP重定向。您必须通过发送新的QNetworkRequest来自行处理。

新网址应位于HTTP Location标头中。要获得它,您可以使用QNetworkReply::header(QNetworkRequest::LocationHeader)

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

请注意,我已使用QVariant::toUrl()将QVariant转换为QUrl,但您可能需要将QVariant转换为QString,然后转换为QUrl。