从 DailyMotion Videos 和其他网站获取可下载 URL(资源 URL)?

Get downloadable URL(Resource URL) from DailyMotion Videos & other sites?

我需要从在线视频托管网站(即 YouTube、DailyMotion、vimeo 等)下载视频到我的 iOS 应用程序。

最近,当用户尝试播放其中的任何视频时,我从 UIWebView 获得了视频 URL。在获得资源 url(url 的视频保存在一些在线路径)并尝试下载它。

我是通过以下方式在 YouTube 上完成的:

NSString *resourceUrlStr ;
NSString *urlStr  = @"function getURL() { return document.getElementsByTagName('VIDEO')[0].src; } getURL();";

 resourceUrlStr = [myWebViewObject stringByEvaluatingJavaScriptFromString: urlStr];

此内容仅适用于 YouTube 视频,其中 resourceUrlStr 为我提供了 url 的视频资源。

但是当我为 DailyMotion 和其他视频托管网站尝试这些东西时,return 我没有资源视频 url。

有什么猜测吗?或者想法?

有几种技术可以执行它。

我喜欢的技术是, 当 Player in WebView 开始播放视频时需要设置以下代码通知:

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:YES];


   [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(myVideoPlayedInFullscreenFirstTime:)
                                                 name:@"AVPlayerItemBecameCurrentNotification"
                                               object:nil];
}


-(void)myVideoPlayedInFullscreenFirstTime:(NSNotification*)aNotification {

    AVPlayerItem *playerItem = [aNotification object];
    if(playerItem == nil) return;
    // Break down the AVPlayerItem to get to the path
    AVURLAsset *asset = (AVURLAsset*)[playerItem asset];
    NSURL *downloadebaleVideoUrl = [asset URL];

/* now, You can download video by above URL.
In some cases it will give you “.m3u” file location. 
You can go through it & get All videos from that list.
For DailyMotion there is one library on GitHub:
[For DailyMotion](https://github.com/oikyn/ExtractVideoURLManager)

*/
}

Swift #KunalParekh 建议的解决方案版本是:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(true)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.myVideoPlayedInFullscreenFirstTime), name: "AVPlayerItemBecameCurrentNotification", object: nil)
}

func myVideoPlayedInFullscreenFirstTime(aNotification: NSNotification) {
    var playerItem = aNotification.object
    if playerItem == nil {
        return
    }

    let asset:AVURLAsset = playerItem?.asset as! AVURLAsset
    var downloadebaleVideoUrl = asset.URL
    print("downloadable video url is: \(downloadebaleVideoUrl)")
}

记得导入 AVFoundation