/YTVimeoExtractor

Fetches Vimeo's mp4 URLs for iOS

Primary LanguageObjective-CMIT LicenseMIT

YTVimeoExtractor

Build Status Carthage compatible codecov.io GitHub release CocoaPods Platform Status CocoaPods Docs

YTVimeoExtractor extracts the MP4 streams of Vimeo videos, which then can be used to play via a MPMoviePlayerViewController or AVPlayerView.

Requirements

  • Runs on iOS 7.0 and later
  • Runs on OS X 10.9 and later
  • Runs on tvOS 9.0 and later

Overview of Library

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.

Installation

CocoaPods

The preferred way of installation is via CocoaPods. Just add to your Podfile

pod 'YTVimeoExtractor'

and run pod install.

Alternatively you can just copy the YTVimeoExtractor folder to your project.

#import "YTVimeoExtractor.h"

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate YTVimeoExtractor into your Xcode project using Carthage, specify it in your Cartfile:

github "lilfaf/YTVimeoExtractor"

Run carthage to build the framework and drag the built YTVimeoExtractor.framework into your Xcode project.

Usage

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.

OS X Example

[[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 Example

 [[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 Example

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

Acknowledgments

  • YTVimeoExtractor was originally created by Louis Larpin
  • Reorganization, documentation, and Unit Tests were done by Soneé John
  • Special thanks to all who contributed to the project.

License

YTVimeoExtractor is licensed under the MIT License. See the LICENSE file for more information.


YTVimeoExtractor is against the Vimeo Terms of Service.