开发者

Youtube And the iphone sdk

开发者 https://www.devze.com 2022-12-11 10:40 出处:网络
does anyone have a way of extracting the d开发者_StackOverflow中文版irect movie url from the page returned by a standard youtube link?

does anyone have a way of extracting the d开发者_StackOverflow中文版irect movie url from the page returned by a standard youtube link?


NSString *pageString = @"www.youtube.com/watch?v=MOST VIDEOS ARE SUPPORTED"; NSString *agentString = @"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1"; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString:pageString]]; [request setValue:agentString forHTTPHeaderField:@"User-Agent"]; NSData *data = [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ];

NSString *page = [[NSString alloc] initWithBytes: [data bytes] length:[data length] encoding: NSUTF8StringEncoding];

NSRange range1 = [page rangeOfString:@"ajax?v="];
NSRange range2 = [page rangeOfString:@"&action_get_comments"];


NSUInteger lok = range1.location + range1.length;
NSRange finRange = NSMakeRange(lok, range2.location - lok);
NSString *subString3 = [page substringWithRange:finRange];


range1 = [page rangeOfString:@"\"t\": \""];// "t":"
range2 = [page rangeOfString:@"\", \"rv.6.id\":"];// ", "rv.6.id":

lok = range1.location + range1.length;
finRange = NSMakeRange(lok, range2.location - lok);
NSString *subString4 = [page substringWithRange:finRange];


NSString *demoURL = [NSString stringWithFormat:@"http://www.youtube.com/get_video?video_id=%@&t=%@&fmt=18",subString3,subString4];

player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:demoURL]];
[[NSNotificationCenter defaultCenter]
 addObserver: self
 selector: @selector(myMovieFinishedCallback:)
 name: MPMoviePlayerPlaybackDidFinishNotification
 object: player];

[player play];


If there's no standard supported API you can try to figure it out by looking at how one of the numerous sites (e.g. kipvid) does it. But this may change with time of course.

0

精彩评论

暂无评论...
验证码 换一张
取 消