Skip to content

Commit

Permalink
Merge pull request #34 from SoneeJohn/master
Browse files Browse the repository at this point in the history
Version 1.0.0 Pull Request.
  • Loading branch information
lilfaf committed Dec 25, 2015
2 parents 4673590 + 9e074fc commit ffb8222
Show file tree
Hide file tree
Showing 63 changed files with 4,218 additions and 2,091 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ build/*
!default.mode2v3
*.perspectivev3
!default.perspectivev3
*.xcworkspace
!default.xcworkspace
xcuserdata
profile
*.moved-aside
.DS_Store
.DS_Store
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: objective-c
osx_image: xcode7.1
before_install:
- brew update
script: xctool -project YTVimeoExtractor.xcodeproj -scheme YTVimeoExtractor test
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013 Louis Larpin
Copyright (c) 2013 - 2015 Louis Larpin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
167 changes: 106 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
## YTVimeoExtractor

YTVimeoExtractor helps you get mp4 urls which can be use in iOS's native player. You can even choose between mobile, standard and high definition quality.
[![Build Status](https://travis-ci.org/SoneeJohn/YTVimeoExtractor.svg?branch=v1.0.0-develop)](https://travis-ci.org/SoneeJohn/YTVimeoExtractor)

YTVimeoExtractor doesn't use UIWebView which makes it fast and clean.
YTVimeoExtractor extracts the MP4 streams of Vimeo videos, which then can be used to play via a `MPMoviePlayerViewController` or `AVPlayerView`.

## Install
<img src="Screenshots/iphone_screenshot.PNG" width="600" height="331">

## 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 sole 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. Generally, you should not initialize this class, instead use the two main methods of the `YTVimeoExtractor` class.|

## Installation

The preferred way of installation is via [CocoaPods](http://cocoapods.org). Just add to your Podfile

Expand All @@ -22,75 +38,104 @@ Alternatively you can just copy the YTVimeoExtractor folder to your project.

## Usage

Use the block based methods and pass it the video url and the desired quality

```objc
[YTVimeoExtractor fetchVideoURLFromURL:@"http://vimeo.com/58600663"
quality:YTVimeoVideoQualityHD1080
completionHandler:^(NSURL *videoURL, NSError *error, YTVimeoVideoQuality quality) {
if (error) {
// handle error
NSLog(@"Video URL: %@", [videoURL absoluteString]);
} else {
// run player
dispatch_async (dispatch_get_main_queue(), ^{
self.playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self.playerViewController.moviePlayer prepareToPlay];
[self presentViewController:self.playerViewController animated:YES completion:nil];
});
}
}];
```
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.

or create an instance of YTVimeoExtractor.
### OS X Example

```objc
self.extractor = [[YTVimeoExtractor alloc] initWithURL:@"http://vimeo.com/58600663" quality:YTVimeoVideoQualityHD1080];
self.extractor.delegate = self;
[self.extractor start];
```

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

if (video) {

NSDictionary *streamURLs = video.streamURLs;
//Will get the highest available quality.
NSString *url = streamURLs[@(YTVimeoVideoQualityHD1080)] ?: streamURLs[@(YTVimeoVideoQualityHD720)] ?: streamURLs [@(YTVimeoVideoQualityMedium480)]?: streamURLs[@(YTVimeoVideoQualityMedium360)]?:streamURLs[@(YTVimeoVideoQualityLow270)];

AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:url]];

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

}else{
[[NSAlert alertWithError:error]runModal];
}
}];

```objc
- (void)vimeoExtractor:(YTVimeoExtractor *)extractor didSuccessfullyExtractVimeoURL:(NSURL *)videoURL withQuality:(YTVimeoVideoQuality)quality
{
// handle success
}

- (void)vimeoExtractor:(YTVimeoExtractor *)extractor failedExtractingVimeoURLWithError:(NSError *)error;
{
// handle error
}
```
If the Vimeo videos have domain-level restrictions and can only be played from particular domains, it's easy to add a referer:
### iOS Example
```objc
[YTVimeoExtractor fetchVideoURLFromURL:@"http://vimeo.com/58600663"
quality:YTVimeoVideoQualityHD1080
referer:@"http://www.mywebsite.com"
completionHandler:^(NSURL *videoURL, NSError *error, YTVimeoVideoQuality quality) {
if (error) {
// handle error
NSLog(@"Video URL: %@", [videoURL absoluteString]);
} else {
// run player
dispatch_async (dispatch_get_main_queue(), ^{
self.playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self.playerViewController.moviePlayer prepareToPlay];
[self presentViewController:self.playerViewController animated:YES completion:nil];
});
}
}];
```
Check the sample application for more details.
[[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:nil completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {
if (video) {
NSDictionary *streamURLs = video.streamURLs;
//Will get the highest available quality.
NSString *url = streamURLs[@(YTVimeoVideoQualityHD1080)] ?: streamURLs[@(YTVimeoVideoQualityHD720)] ?: streamURLs [@(YTVimeoVideoQualityMedium480)]?: streamURLs[@(YTVimeoVideoQualityMedium360)]?:streamURLs[@(YTVimeoVideoQualityLow270)];
NSURL *movieURL = [NSURL URLWithString:url];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
[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:

## Requirements
```objc

YTVimeoExtractor requires iOS 7.0 and above as it is deployed for an ARC environment.
[[YTVimeoExtractor sharedExtractor]fetchVideoWithVimeoURL:@"https://vimeo.com/channels/staffpicks/147876560" withReferer:@"http://www.mywebsite.com" completionHandler:^(YTVimeoVideo * _Nullable video, NSError * _Nullable error) {

if (video) {

NSDictionary *streamURLs = video.streamURLs;
//Will get the highest available quality.
NSString *url = streamURLs[@(YTVimeoVideoQualityHD1080)] ?: streamURLs[@(YTVimeoVideoQualityHD720)] ?: streamURLs [@(YTVimeoVideoQualityMedium480)]?: streamURLs[@(YTVimeoVideoQualityMedium360)]?:streamURLs[@(YTVimeoVideoQualityLow270)];

NSURL *movieURL = [NSURL URLWithString:url];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];

[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](https://github.com/lilfaf)
* Reorganization, documentation, and Unit Tests were done by [Soneé John](https://github.com/SoneeJohn)
* Special thanks to all who [contributed](https://github.com/lilfaf/YTVimeoExtractor/graphs/contributors) to the project.
## License
YTVimeoExtractor is licensed under the MIT License. See the LICENSE file for details.
YTVimeoExtractor is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.
--------
###### YTVimeoExtractor is against the Vimeo [Terms of Service](https://vimeo.com/terms).
13 changes: 0 additions & 13 deletions Sample/MacSample/AppDelegate.h

This file was deleted.

31 changes: 0 additions & 31 deletions Sample/MacSample/AppDelegate.m

This file was deleted.

Loading

0 comments on commit ffb8222

Please sign in to comment.