我使用某些格式的直接视频网址解析了“url_encoded_fmt_stream_map =”条目,例如(已解码):
http://r7---sn-2apm-f5f6.c.youtube.com/videoplayback?gcr=de&cp=U0hUTFVUUl9LUENONF9NTlZHOkpGR0NWdWtvSk15&source=youtube&ip=46.59.194.67&upn=KHmKgXE5di4&fexp=917000,906357,911115,916611,920704,912806,928001,922403,922405,929901,913605,929104,913546,913556,908496,920201,913302,919009,911116,901451,902556&ms=au&itag=45&mt=1357571596&sparams=cp,gcr,id,ip,ipbits,itag,ratebypass,source,upn,expire&id=e4b675c403014739&expire=1357594666&ipbits=8&mv=m&newshard=yes&ratebypass=yes&sver=3&key=yt1&signature=1C8204D1180CAB0B57E3B3331409BD055CBA25B1.73FBEC95E020BBCAC6485D62601E8CF05ACA72DE,quality=hd720&itag=22&fallback_host=tc.v23.cache2.c.youtube.com&type=video/mp4;+codecs="avc1.64001F,+mp4a.40.2"
但是我无法下载或查看它! VLC说:无法打开! Firefox保持空白(白色窗口,没有错误消息)! “url_encoded_fmt_stream_map =”之后的网址是否正确?
答案 0 :(得分:0)
在我的回答https://stackoverflow.com/a/14352995/307547中,我介绍了下载YouTube视频的解决方案。
LBYouTubeExtractor *extractor = [[[LBYouTubeExtractor alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:(@"http://www.youtube.com/watch?v=%@"), self.videoID ]] quality:LBYouTubeVideoQualityLarge] autorelease];
[extractor extractVideoURLWithCompletionBlock:^(NSURL *videoURL, NSError *error) {
if(!error) {
NSLog(@"Did extract video URL using completion block: %@", videoURL);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL: videoURL];
NSString *pathToDocs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [NSString stringWithFormat:(@"video_%@.mp4"), self.videoID ];
[data writeToFile:[pathTODocs stringByAppendingPathComponent:filename] atomically:YES];
NSLog(@"File %@ successfully saved", filename);
});
} else {
NSLog(@"Failed extracting video URL using block due to error:%@", error);
}
}];
您可以使用上述帖子中描述的技术显示下载进度。 您可以使用更适合您的方法替换dataWithContentsOfURL。