TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Jan 2017 |
Maintained by Louis Larpin, Soneé John.
YTVimeoExtractor extracts the MP4 streams of Vimeo videos, which then can be used to play via a MPMoviePlayerViewController
or AVPlayerView
.
Class | Purpose |
---|---|
YTVimeoExtractor |
The YTVimeoExtractor is the main class and its sole purpose is to fetch information about Vimeo videos. Use the two main methods fetchVideoWithIdentifier:withReferer:completionHandler: or fetchVideoWithVimeoURL:withReferer:completionHandler: to obtain video information. |
YTVimeoExtractorOperation |
YTVimeoExtractorOperation is a subclass of NSOperation and is used to fetch and parse out information about Vimeo videos. This a low level class. Generally speaking, you should use the higher level YTVimeoExtractor class. |
YTVimeoURLParser |
YTVimeoURLParser is used to validate and parse put Vimeo URLs. The main purpose of the class is to check if a given URL can be handled by the YTVimeoExtractor class. |
YTVimeoVideo |
YTVimeoVideo represents a Vimeo video. Use this class to access information about a particular video. Do not manually initialize a YTVimeoVideo object. Using the -init method will throw an exception, instead use the two main methods of the YTVimeoExtractor class to obtain a YTVimeoVideo object. |
Use the two block methods in the YTVimeoExtractor
class. Both methods will call a completionHandler which is executed on the main thread. If the completion handler is nil, an exception will be thrown. The completionHandler has, two parameters a YTVimeoVideo
object, if the operation was completed successfully, and a NSError
object describing the network or parsing error that may have occurred.
[[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];
}
}];
[[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];
}
}];
If the Vimeo video has domain-level restrictions and can only be played from particular domains, it's easy to add a referer:
[[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 is licensed under the MIT License. See the LICENSE file for more information.