gpt4 book ai didi

iphone - YouTube和iPhone SDK

转载 作者:行者123 更新时间:2023-12-03 05:52:33 25 4
gpt4 key购买 nike

有谁能从标准youtube链接返回的页面中提取直接电影的网址?

最佳答案


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

关于iphone - YouTube和iPhone SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1724167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com