Giter Site home page Giter Site logo

ytvimeoextractor's Introduction

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.

ytvimeoextractor's People

Contributors

soneejohn avatar lilfaf avatar nourahassan avatar pratik948 avatar modnovolyk avatar runmad avatar brianvanderwal avatar pixelkind avatar cstigler avatar kmonaghan avatar sbl avatar tjmaynes avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.