YTVimeoExtractor 1.2.0

YTVimeoExtractor 1.2.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年1月

Louis LarpinSoneé John维护。



  • Louis Larpin和Soneé John

YTVimeoExtractor提取Vimeo视频的MP4流,之后可以通过MPMoviePlayerViewControllerAVPlayerView来播放。

要求

  • 在iOS 7.0及以后版本上运行
  • 在OS X 10.9及以后版本上运行
  • 在tvOS 9.0及以后版本上运行

库概览

用途
YTVimeoExtractor YTVimeoExtractor是主类,其唯一目的是获取Vimeo视频的信息。使用两个主要方法fetchVideoWithIdentifier:withReferer:completionHandler:fetchVideoWithVimeoURL:withReferer:completionHandler:来获取视频信息。
YTVimeoExtractorOperation YTVimeoExtractorOperationNSOperation的子类,用于获取和解析Vimeo视频的信息。这是一个低级类。一般来说,您应使用高级YTVimeoExtractor类。
YTVimeoURLParser YTVimeoURLParser用于验证和解析Vimeo URL。该类的主要目的是检查给定的URL是否可以由YTVimeoExtractor类处理。
YTVimeoVideo YTVimeoVideo代表一个Vimeo视频。使用此类来访问特定视频的信息。不要手动初始化一个YTVimeoVideo对象。使用`-init`方法将抛出异常,而是使用`YTVimeoExtractor`类的两个主要方法来获取一个`YTVimeoVideo`对象。

用法

使用`YTVimeoExtractor`类中的两个块方法。这两个方法都会调用一个完成处理器,该处理器在主线程上执行。如果完成处理器为nil,则会抛出异常。完成处理器有两个参数:一个`YTVimeoVideo`对象,表示操作成功完成;以及一个`NSError`对象,描述可能发生的网络或解析错误。

OS X示例

[[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:nil completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {

        if (video) {

            [self.titleTextField setStringValue:video.title];

            //Will get the lowest available quality.
            //NSURL *lowQualityURL = [video lowestQualityStreamURL];

            //Will get the highest available quality.
            NSURL *highQualityURL = [video highestQualityStreamURL];


            AVPlayer *player = [[AVPlayer alloc]initWithURL:highQualityURL];

            self.playerView.player = player;
            self.playerView.videoGravity = AVLayerVideoGravityResizeAspectFill;
            [self.playerView.player play];
            [self.playerView becomeFirstResponder];

        }else{

            [[NSAlert alertWithError:error]runModal];
        }

    }];

iOS示例

 [[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:nil completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {

        if (video) {

            self.titleLabel.text = [NSString stringWithFormat:@"Video Title: %@",video.title];
            //Will get the lowest available quality.
            //NSURL *lowQualityURL = [video lowestQualityStreamURL];

            //Will get the highest available quality.
            NSURL *highQualityURL = [video highestQualityStreamURL];

            MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:highQualityURL];

            [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
        }else{

            UIAlertView *alertView = [[UIAlertView alloc]init];
            alertView.title = error.localizedDescription;
            alertView.message = error.localizedFailureReason;
            [alertView addButtonWithTitle:@"OK"];
            alertView.delegate = self;
            [alertView show];

        }

    }];

Referer示例

如果Vimeo视频有域名级别限制,并且只能从特定域名播放,添加引用者很简单。

 [[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:@"http://www.mywebsite.com" completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {

        if (video) {

            //Will get the lowest available quality.
            //NSURL *lowQualityURL = [video lowestQualityStreamURL];

            //Will get the highest available quality.
            NSURL *highQualityURL = [video highestQualityStreamURL];

            MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:highQualityURL];

            [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
        }else{

            UIAlertView *alertView = [[UIAlertView alloc]init];
            alertView.title = error.localizedDescription;
            alertView.message = error.localizedFailureReason;
            [alertView addButtonWithTitle:@"OK"];
            alertView.delegate = self;
            [alertView show];

        }

    }];

鸣谢

许可证

YTVimeoExtractor遵循MIT许可证。有关更多信息,请参阅LICENSE文件。


YTVimeoExtractor违反了Vimeo的服务条款