从youtube objective c下载视频

时间:2016-01-28 11:52:20

标签: ios objective-c youtube downloading

我正在尝试从youtube下载视频但收到错误。

代码中提到错误

我的代码

-(void)downloadVideo{
LBYouTubeExtractor *extractor = [[LBYouTubeExtractor alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:(@"https://www.youtube.com/watch?v=%@"), videoIdToDownload ]] quality:LBYouTubeVideoQualityLarge];
[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), ^{

            NSError* error = nil;
            NSData* data1 = [NSData dataWithContentsOfURL:videoURL options:NSDataReadingUncached error:&error]; //data1 is nill
            if (error) { //Error Domain=NSCocoaErrorDomain Code=256 "The file “3gpp;+codecs="mp4v.20.3,+mp4a.40.2"&fallback_host=tc.v8.cache4.googlevideo.com&itag=36” couldn’t be opened."
                NSLog(@"error=%@", error);
            }else{
            NSString *filename = [NSString stringWithFormat:(@"video_%@.mp4"), videoIdToDownload ];
            [data1 writeToFile:[dirPath stringByAppendingPathComponent:filename] atomically:YES];
            NSLog(@"File %@ successfully saved", filename);
            }
        });
    } else {
        NSLog(@"Failed extracting video URL using block due to error:%@", error);
    }
}];

}

使用这个lib https://github.com/larcus94/LBYouTubeView

如果有人现在解决方案,请帮助我。

由于

0 个答案:

没有答案