I need to Download videos from online video hosting sites(i.e. YouTube, DailyMotion, vimeo etc.) to my iOS application.
Recently i am getting video URL from UIWebView
as user try to play any video in it. And after getting resource url(url of video which saved at some online path) and try to download it.
i had done it in YouTube by below stuff:
NSString *resourceUrlStr ;
NSString *urlStr = @"function getURL() { return document.getElementsByTagName('VIDEO')[0].src; } getURL();";
resourceUrlStr = [myWebViewObject stringByEvaluatingJavaScriptFromString: urlStr];
This stuff only works for YouTube videos, Where resourceUrlStr provide me url of video resource.
But when i try this stuff for DailyMotion & other video hosting websites, It doesn't return me resource video url.
Any guesses? Or idea?
There are several techniques to perform it.
My prefered technique is, When Player in WebView start playing a Video You need to set below code for notification :
-(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)
*/
}