Skip to content

Commit

Permalink
Merge pull request #39 from lilfaf/development
Browse files Browse the repository at this point in the history
Development 'merge' v1.1.0
  • Loading branch information
SoneeJohn committed Feb 7, 2016
2 parents 9c15fbd + 21f42c8 commit b124f37
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 29 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Version 1.1.0

* The `streamURLs` and `thumbnailURLs` are now dictionaries that contain NSURLs ([e179efc](https://github.com/lilfaf/YTVimeoExtractor/commit/e179efc395ea8f287a9a9acb1b4b1398e92e24ce), [385ae37](https://github.com/lilfaf/YTVimeoExtractor/commit/385ae372660f52a0061b3c73f7d5df0cd5b33cc3))
* Add support for Objective-C generics
* Add two methods to easily retrieve certain URLs from the `streamURLs` dictionary:
* `- highestQualityStreamURL` & `- lowestQualityStreamURL` ([d80f87b](https://github.com/lilfaf/YTVimeoExtractor/commit/d80f87b5e3f51dca8dbf8395278f5f706c2ad2a8))

### Version 1.0.0
* Intial version
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ YTVimeoExtractor extracts the MP4 streams of Vimeo videos, which then can be use
|---------------|----------------|
| `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.|
|`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. Generally, you should not initialize this class, instead use the two main methods of the `YTVimeoExtractor` class.|

## Installation
Expand Down Expand Up @@ -74,23 +74,30 @@ Use the two block methods in the `YTVimeoExtractor` class. Both methods will cal

if (video) {

NSDictionary *streamURLs = video.streamURLs;
[self.titleTextField setStringValue:video.title];

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

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


AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:url]];
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
Expand All @@ -101,13 +108,15 @@ Use the two block methods in the `YTVimeoExtractor` class. Both methods will cal
if (video) {
NSDictionary *streamURLs = video.streamURLs;
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.
NSString *url = streamURLs[@(YTVimeoVideoQualityHD1080)] ?: streamURLs[@(YTVimeoVideoQualityHD720)] ?: streamURLs [@(YTVimeoVideoQualityMedium480)]?: streamURLs[@(YTVimeoVideoQualityMedium360)]?:streamURLs[@(YTVimeoVideoQualityLow270)];
NSURL *highQualityURL = [video highestQualityStreamURL];
NSURL *movieURL = [NSURL URLWithString:url];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc]initWithContentURL:highQualityURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
}else{
Expand All @@ -132,12 +141,13 @@ If the Vimeo video has domain-level restrictions and can only be played from par

if (video) {

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

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

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

[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ - (IBAction)playAction:(id)sender {

[self.titleTextField setStringValue:video.title];

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

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


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

self.playerView.player = player;
self.playerView.videoGravity = AVLayerVideoGravityResizeAspectFill;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ -(IBAction)playVideoAction:(id)sender{
if (video) {

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

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

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

[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
}else{
Expand Down
4 changes: 2 additions & 2 deletions YTVimeoExtractor.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "YTVimeoExtractor"
s.version = "1.0.0"
s.version = "1.1.0"
s.summary = "Fetches Vimeo's mp4 URLs for iOS."
s.description = <<-DESC
YTVimeoExtractor is a class which lets you get the iOS
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.homepage = "https://github.com/lilfaf/YTVimeoExtractor"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { "Louis Larpin" => "[email protected]" }
s.source = { :git => "https://github.com/lilfaf/YTVimeoExtractor.git", :tag => "1.0.0" }
s.source = { :git => "https://github.com/lilfaf/YTVimeoExtractor.git", :tag => "1.1.0" }

s.ios.deployment_target = '7.0'
s.osx.deployment_target = '10.9'
Expand Down
4 changes: 2 additions & 2 deletions YTVimeoExtractor/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<string>1.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>1.1.0</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 Louis Larpin. All rights reserved.</string>
<key>NSPrincipalClass</key>
Expand Down
18 changes: 16 additions & 2 deletions YTVimeoExtractor/YTVimeoVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,29 @@ typedef NS_ENUM(NSUInteger, YTVimeoVideoQuality) {
* A `NSDictionary` object that contains the various stream URLs.
* @see YTVimeoVideoQuality
*/
@property (nonatomic, readonly) NSDictionary *__nullable streamURLs;
@property (nonatomic, readonly) NSDictionary<id, NSURL *> *__nullable streamURLs;
/**
* A `NSDictionary` object that contains the various thumbnail URLs.
* @see YTVimeoVideoThumbnailQuality
*/
@property (nonatomic, readonly) NSDictionary *__nullable thumbnailURLs;
@property (nonatomic, readonly) NSDictionary<id, NSURL *> *__nullable thumbnailURLs;
/**
* A `NSDictionary` object that contains all the metadata about the video.
*/
@property (nonatomic, readonly) NSDictionary *__nullable metaData;
/**
* Get the highest quality stream URL.
*
* @see YTVimeoVideoQuality
* @return The highest quality stream URL.
*/
-(NSURL *__nullable)highestQualityStreamURL;
/**
* Get the lowest quality stream URL.
*
* @see YTVimeoVideoQuality
* @return The lowest quality stream URL.
*/
-(NSURL *__nullable)lowestQualityStreamURL;

@end
20 changes: 18 additions & 2 deletions YTVimeoExtractor/YTVimeoVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ - (void)extractVideoInfoWithCompletionHandler:(void (^)(NSError *error))completi

NSInteger quality = [[info valueForKey:@"quality"]integerValue];
NSString *urlString = info[@"url"];
NSURL *url = [NSURL URLWithString:urlString];

//Only if the file is playable on OS X or iOS natively
if([urlString rangeOfString:@".mp4"].location != NSNotFound){

streamURLs[@(quality)] = urlString;
streamURLs[@(quality)] = url;

}
}
Expand All @@ -97,7 +98,8 @@ - (void)extractVideoInfoWithCompletionHandler:(void (^)(NSError *error))completi
for (NSString *key in thumbnailsInfo) {

NSInteger thumbnailquality = [key integerValue];
NSString *thumbnailURL = thumbnailsInfo[key];
NSString *thumbnailString = thumbnailsInfo[key];
NSURL *thumbnailURL = [NSURL URLWithString:thumbnailString];
thumbnailURLs [@(thumbnailquality)] = thumbnailURL;
}

Expand All @@ -108,6 +110,20 @@ - (void)extractVideoInfoWithCompletionHandler:(void (^)(NSError *error))completi
});
}

#pragma mark -
-(NSURL *)highestQualityStreamURL{

NSURL *url = self.streamURLs[@(YTVimeoVideoQualityHD1080)] ?: self.streamURLs[@(YTVimeoVideoQualityHD720)] ?: self.streamURLs [@(YTVimeoVideoQualityMedium480)]?: self.streamURLs[@(YTVimeoVideoQualityMedium360)]?:self.streamURLs[@(YTVimeoVideoQualityLow270)];

return url;
}

-(NSURL *)lowestQualityStreamURL{

NSURL *url = self.streamURLs[@(YTVimeoVideoQualityLow270)] ?: self.streamURLs[@(YTVimeoVideoQualityMedium360)] ?: self.streamURLs [@(YTVimeoVideoQualityMedium480)]?: self.streamURLs[@(YTVimeoVideoQualityHD720)]?:self.streamURLs[@(YTVimeoVideoQualityHD1080)];

return url;
}

#pragma mark - NSObject
- (NSString *) description
Expand Down
29 changes: 29 additions & 0 deletions YTVimeoExtractorTests/YTVimeoVideoTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ -(void)testThumbnails{
[self waitForExpectationsWithTimeout:15 handler:nil];
}

-(void)testConvenienceMethods{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];

NSString *filePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"testdata.plist"];

NSData *buffer = [NSData dataWithContentsOfFile:filePath];
NSDictionary *myDictionary = (NSDictionary*) [NSKeyedUnarchiver unarchiveObjectWithData:buffer];

YTVimeoVideo *video = [[YTVimeoVideo alloc]initWithIdentifier:@"147318819" info:myDictionary];

[video extractVideoInfoWithCompletionHandler:^(NSError * _Nullable error) {

XCTAssertNotNil(video.streamURLs);

NSURL *highestURL = video.streamURLs[@(YTVimeoVideoQualityHD1080)] ?: video.streamURLs[@(YTVimeoVideoQualityHD720)] ?: video.streamURLs [@(YTVimeoVideoQualityMedium480)]?: video.streamURLs[@(YTVimeoVideoQualityMedium360)]?:video.streamURLs[@(YTVimeoVideoQualityLow270)];

NSURL *lowestURL = video.streamURLs[@(YTVimeoVideoQualityLow270)] ?: video.streamURLs[@(YTVimeoVideoQualityMedium360)] ?: video.streamURLs[@(YTVimeoVideoQualityMedium480)]?: video.streamURLs[@(YTVimeoVideoQualityHD720)]?:video.streamURLs[@(YTVimeoVideoQualityHD1080)];

XCTAssertEqual(highestURL, [video highestQualityStreamURL]);

XCTAssertEqual(lowestURL, [video lowestQualityStreamURL]);


[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:15 handler:nil];
}

/*
-(void)testUnsuitableStreamThatAlsoHasSuitableStreams{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
Expand Down

0 comments on commit b124f37

Please sign in to comment.