问题描述:

I searched for many solutions to play Youtube videos on iOS.

At the moment i just use a webview to show only the player and then press the play button (only embed the video in the webview).

But I know there is a javascript solution to get an mp4 link for the youtube video.

This is the javascript:

http://userscripts.org/scripts/show/25105

The script searches for the video element and grabs all informations and finally make it possible to download the mp4.

Im not good in javascript, so i dont know if there is an possibility to write that code, that it just works with http://myurl.com/getvideo?id=VIDEOID .

I would try it myself, but i dont know if it is possible to grab all these informations the script uses without the player element.

Maybe you can help me ;)

(im using iOS 5 btw)

My english is not the best, so if u have problems to understand something, just ask.

网友答案:

you can check PSYouTubeExtractor that allows you to retrieve the mp4 version of a YouTube video, it is pretty easy to use.

网友答案:

Late answer but i found an easy solution for it. no need for 3rd party library.

open any Youtube video in UIWebView, & on download button do below stuff :

 -(IBAction)downloadPressed:(id)sender{
        NSString *getURL = @"";
        NSString *str  = @"function getURL() { return document.getElementsByTagName('VIDEO')[0].src; } getURL();";
        getURL = [self.myWebViewObject stringByEvaluatingJavaScriptFromString:str];

        // Your code for download video from upper URL.
}

Here getURL NSString Object give you appropriate url that you looking for download. Now, you can download any video on YouTube(restricted also) by download file on upper URL.

But keep in mind that download YouTube video is against terms & condition of YouTube. Though there are apps on AppStore that let users to download videos from YouTube, We will not able to upload app on AppStore which allows download from YouTube!!

相关阅读:
Top