Skip to content

Commit

Permalink
Merge branch 'release/2.7.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
SoneeJohn committed Jul 2, 2019
2 parents cb87e63 + afaf65a commit 6db8069
Show file tree
Hide file tree
Showing 23 changed files with 606 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
XcodeCoverage
RELEASE_NOTES.md
.DS_Store
*.xcuserstate
4 changes: 2 additions & 2 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ source_directory: XCDYouTubeKit
framework_root: .
umbrella_header: XCDYouTubeKit/XCDYouTubeKit.h
module: XCDYouTubeKit
module_version: 2.7.6
module_version: 2.7.7

author: Cédric Luthi
author_url: https://twitter.com/0xced

readme: README.md
github_url: https://github.com/0xced/XCDYouTubeKit
github_file_prefix: https://github.com/0xced/XCDYouTubeKit/tree/2.7.6/XCDYouTubeKit
github_file_prefix: https://github.com/0xced/XCDYouTubeKit/tree/2.7.7/XCDYouTubeKit
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### Version 2.7.7

* Add another player script regular expression (#438)

#### Version 2.7.6

* Adaptation to YouTube API change. (#437)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 2.7.6;
CURRENT_PROJECT_VERSION = 2.7.7;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand Down Expand Up @@ -804,7 +804,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 2.7.6;
CURRENT_PROJECT_VERSION = 2.7.7;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
Binary file removed XCDYouTubeKit Tests/Cookies/minorUserCookieData
Binary file not shown.
3 changes: 3 additions & 0 deletions XCDYouTubeKit Tests/VCRURLConnection/VCRURLConnection/VCR.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,7 @@
*/
+ (void)save:(NSString *)path;

+ (NSArray<NSHTTPCookie *>*)cookies;
+ (void)setCookies:(NSArray<NSHTTPCookie *>*)cookies;

@end
14 changes: 14 additions & 0 deletions XCDYouTubeKit Tests/VCRURLConnection/VCRURLConnection/VCR.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

static BOOL _VCRIsRecording;
static BOOL _VCRIsReplaying;
static NSArray *_VCRCookies;


@implementation VCR
Expand Down Expand Up @@ -76,6 +77,9 @@ + (void)start {
}

+ (void)stop {
for (NSHTTPCookie *cookie in [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage]deleteCookie:cookie];
}
[self setRecording:NO];
[self setReplaying:NO];
}
Expand All @@ -84,6 +88,16 @@ + (void)save:(NSString *)path {
return [[VCRCassetteManager defaultManager] save:path];
}

+ (NSArray<NSHTTPCookie *> *)cookies {
return _VCRCookies;
}

+ (void)setCookies:(NSArray<NSHTTPCookie *> *)cookies {
if (_VCRCookies != cookies) {
_VCRCookies = cookies;
}
}

@end


Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ + (BOOL)canInitWithRequest:(NSURLRequest *)request {
}

+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
for (NSHTTPCookie *cookie in [VCR cookies]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage]setCookie:cookie];
}
return request;
}

Expand Down
2 changes: 2 additions & 0 deletions XCDYouTubeKit Tests/XCDYouTubeKitTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
#import "VCRCassetteManager.h"

@interface XCDYouTubeKitTestCase : XCTestCase
- (void) setUpTestWithSelector:(SEL)selector;
@property NSArray<NSHTTPCookie *>*cookies;
@end
1 change: 1 addition & 0 deletions XCDYouTubeKit Tests/XCDYouTubeKitTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ + (NSArray *) testInvocations
- (void) setUpTestWithSelector:(SEL)selector
{
[super setUpTestWithSelector:selector];
[VCR setCookies:self.cookies];

BOOL onlineTests = [[[[NSProcessInfo processInfo] environment] objectForKey:@"ONLINE_TESTS"] boolValue];

Expand Down
156 changes: 32 additions & 124 deletions XCDYouTubeKit Tests/XCDYouTubeProtectedVideosTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#import "XCDYouTubeVideo+Private.h"

@interface XCDYouTubeProtectedVideosTestCase : XCDYouTubeKitTestCase
extern NSArray <NSHTTPCookie *>* XCDYouTubeProtectedVideosAdultUserCookies(void);
extern NSArray <NSHTTPCookie *>* XCDYouTubeProtectedVideosMinorUserCookies(void);
extern NSArray <NSHTTPCookie *>* XCDYouTubeProtectedVideosCookies(void);
@end

@implementation XCDYouTubeProtectedVideosTestCase

NSArray <NSHTTPCookie *>* XCDYouTubeProtectedVideosMinorUserCookies()
NSArray <NSHTTPCookie *>* XCDYouTubeProtectedVideosCookies()
{
NSURL *cookieURL = [[NSBundle bundleForClass:[XCDYouTubeProtectedVideosTestCase class]]URLForResource:@"minorUserCookieData" withExtension:nil subdirectory:@"Cookies"];
NSURL *cookieURL = [[NSBundle bundleForClass:[XCDYouTubeProtectedVideosTestCase class]]URLForResource:@"UserCookieData" withExtension:nil subdirectory:@"Cookies"];

NSCAssert(cookieURL != nil, @"Cookie data could not be found!");
NSData *cookieData = [NSData dataWithContentsOfURL:cookieURL];
Expand All @@ -29,71 +28,25 @@ @implementation XCDYouTubeProtectedVideosTestCase
return cookies;
}

NSArray <NSHTTPCookie *>* XCDYouTubeProtectedVideosAdultUserCookies()
- (void)tearDown
{
NSURL *cookieURL = [[NSBundle bundleForClass:[XCDYouTubeProtectedVideosTestCase class]]URLForResource:@"adultUserCookieData" withExtension:nil subdirectory:@"Cookies"];

NSCAssert(cookieURL != nil, @"Cookie data could not be found!");
NSData *cookieData = [NSData dataWithContentsOfURL:cookieURL];
NSCAssert(cookieData != nil, @"Cookie data could not be found!");
NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc]initForReadingFromData:cookieData error:nil];
unArchiver.requiresSecureCoding = NO;
NSSet *codingClasses = [NSSet setWithArray:@[ [NSArray classForCoder],[NSHTTPCookie classForCoder] ]];
NSArray <NSHTTPCookie *>*cookies = [unArchiver decodeObjectOfClasses:codingClasses forKey:NSKeyedArchiveRootObjectKey];
NSCAssert(cookies.count != 0, @"No cookies found!");
return cookies;
self.cookies = nil;
[super tearDown];
}

- (void) testAgeRestrictedVideoThatRequiresCookiesWithAdultUserCookies_online
- (void)setUpTestWithSelector:(SEL)selector
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"vhG9_yBJmVE" cookies:XCDYouTubeProtectedVideosAdultUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
XCTAssertNotNil(video.expirationDate);
XCTAssertNotNil(video.thumbnailURL);
XCTAssertTrue(video.streamURLs.count > 0);
XCTAssertTrue(video.duration > 0);
[video.streamURLs enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSURL *streamURL, BOOL *stop)
{
XCTAssertTrue([streamURL.query rangeOfString:@"signature="].location != NSNotFound || [streamURL.query rangeOfString:@"sig="].location != NSNotFound);
}];
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void) testAgeRestrictedVideoThatRequiresCookiesWithAdultUserCookiesIsPlayable_online
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"vhG9_yBJmVE" cookies:XCDYouTubeProtectedVideosAdultUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
XCTAssertNotNil(video.expirationDate);
XCTAssertNotNil(video.thumbnailURL);
XCTAssertTrue(video.streamURLs.count > 0);
XCTAssertTrue(video.duration > 0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:video.streamURLs[@(XCDYouTubeVideoQualityMedium360)]];
request.HTTPMethod = @"HEAD";
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError)
{
XCTAssertEqual([(NSHTTPURLResponse *)response statusCode], 200);
[expectation fulfill];
}];

[dataTask resume];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
if ([NSStringFromSelector(selector) containsString:@"Cookies"])
{
self.cookies = XCDYouTubeProtectedVideosCookies();
}
[super setUpTestWithSelector:selector];
}

- (void) testAgeRestrictedVideoThatRequiresCookiesWithMinorUserCookies_online
- (void) testAgeRestrictedVideoThatRequiresCookiesWithUserCookies
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"vhG9_yBJmVE" cookies:XCDYouTubeProtectedVideosMinorUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"vhG9_yBJmVE" cookies:XCDYouTubeProtectedVideosCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
Expand All @@ -108,13 +61,13 @@ - (void) testAgeRestrictedVideoThatRequiresCookiesWithMinorUserCookies_online
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void) testAgeRestrictedVideoThatRequiresCookiesWithMinortUserCookiesIsPlayable_online
- (void) testAgeRestrictedVideoThatRequiresCookiesWithUserCookiesIsPlayable
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"vhG9_yBJmVE" cookies:XCDYouTubeProtectedVideosMinorUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"vhG9_yBJmVE" cookies:XCDYouTubeProtectedVideosCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
Expand All @@ -133,7 +86,7 @@ - (void) testAgeRestrictedVideoThatRequiresCookiesWithMinortUserCookiesIsPlayabl
[dataTask resume];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void) testAgeRestrictedVideoThatRequiresCookiesWithoutCookies
Expand Down Expand Up @@ -291,10 +244,10 @@ - (void) testDASHAudioWithRateBypassIsPlayable
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void) testAgeRestrictedVEVOVideoWithAdultUserCookies_online
- (void) testAgeRestrictedVEVOVideoWithUserCookies
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"07FYdnEawAQ" cookies:XCDYouTubeProtectedVideosAdultUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"07FYdnEawAQ" cookies:XCDYouTubeProtectedVideosCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
Expand All @@ -309,13 +262,13 @@ - (void) testAgeRestrictedVEVOVideoWithAdultUserCookies_online
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void) testAgeRestrictedVEVOVideoWithAdultUserCookiesIsPlayable_online
- (void) testAgeRestrictedVEVOVideoWithUserCookiesIsPlayable
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"07FYdnEawAQ" cookies:XCDYouTubeProtectedVideosAdultUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"07FYdnEawAQ" cookies:XCDYouTubeProtectedVideosCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
Expand All @@ -334,54 +287,9 @@ - (void) testAgeRestrictedVEVOVideoWithAdultUserCookiesIsPlayable_online
[dataTask resume];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void) testAgeRestrictedVEVOVideoWithMinorUserCookies_online
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"07FYdnEawAQ" cookies:XCDYouTubeProtectedVideosMinorUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
XCTAssertNotNil(video.expirationDate);
XCTAssertNotNil(video.thumbnailURL);
XCTAssertTrue(video.streamURLs.count > 0);
XCTAssertTrue(video.duration > 0);
[video.streamURLs enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, NSURL *streamURL, BOOL *stop)
{
XCTAssertTrue([streamURL.query rangeOfString:@"signature="].location != NSNotFound || [streamURL.query rangeOfString:@"sig="].location != NSNotFound);
}];
[expectation fulfill];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
}

- (void) testAgeRestrictedVEVOVideoWithMinorUserCookiesIsPlayable_online
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"07FYdnEawAQ" cookies:XCDYouTubeProtectedVideosMinorUserCookies() completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
XCTAssertNotNil(video.expirationDate);
XCTAssertNotNil(video.thumbnailURL);
XCTAssertTrue(video.streamURLs.count > 0);
XCTAssertTrue(video.duration > 0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:video.streamURLs[@(XCDYouTubeVideoQualityMedium360)]];
request.HTTPMethod = @"HEAD";
NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError)
{
XCTAssertEqual([(NSHTTPURLResponse *)response statusCode], 200);
[expectation fulfill];
}];

[dataTask resume];
}];

[self waitForExpectationsWithTimeout:30 handler:nil];
}

// With Charles
// * Enable SSL proxying for *.youtube.com
Expand All @@ -397,7 +305,7 @@ - (void) testProtectedVideoWithWebPageConnectionError_offline
XCTAssertEqualObjects(error.localizedDescription, @"This video is unavailable.");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// With Charles: Tools -> Black List... -> Add host:www.youtube.com and path:yts/* to simulate connection error on the player script
Expand All @@ -412,7 +320,7 @@ - (void) testProtectedVideoWithPlayerScriptConnectionError_offline
XCTAssertEqualObjects(error.localizedDescription, @"This video is unavailable.");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// Edit testProtectedVideoWithoutSignatureFunction.json by replacing `c&&a.set(b,encodeURIComponent(Bv(` with `c.&&a.set(b,encodeURIComponent(Bv(` and
Expand All @@ -428,7 +336,7 @@ - (void) testProtectedVideoWithoutSignatureFunction_offline
XCTAssertEqualObjects(error.localizedDescription, @"This video is unavailable.");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// Edit testProtectedVideoWithBrokenSignatureFunction.json by returning null in the signature function
Expand All @@ -445,7 +353,7 @@ - (void) testProtectedVideoWithBrokenSignatureFunction_offline
XCTAssertEqualObjects(error.localizedDescription, @"This video is unavailable.");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// Edit testProtectedVideoWithoutJavaScriptPlayerURL.json by replacing `\"js\":` with `\"xs\":`
Expand All @@ -460,7 +368,7 @@ - (void) testProtectedVideoWithoutJavaScriptPlayerURL_offline
XCTAssertEqualObjects(error.localizedDescription, @"This video is unavailable.");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// Edit testProtectedVideoWithNonAnonymousJavaScriptPlayerFunction.json by replacing all `(function` with `(Xfunction`
Expand All @@ -476,7 +384,7 @@ - (void) testProtectedVideoWithNonAnonymousJavaScriptPlayerFunction_offline
XCTAssertEqualObjects(error.localizedDescription, @"This video is unavailable.");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// With Charles: Tools -> Black List... -> Add host:www.youtube.com and path:embed/* to simulate connection error on the web page
Expand All @@ -491,7 +399,7 @@ - (void) testAgeRestrictedVEVOVideoWithEmbedWebPageConnectionError_offline
XCTAssertEqualObjects(error.localizedDescription, @"Sign in to confirm your age");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// See https://github.com/0xced/XCDYouTubeKit/issues/431
Expand Down Expand Up @@ -528,7 +436,7 @@ - (void) testAgeRestrictedVideo1WithNoJavaScriptPlayerURL_offline
XCTAssertEqualObjects(error.localizedDescription, @"Sign in to confirm your age");
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:1 handler:nil];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

@end
Loading

0 comments on commit 6db8069

Please sign in to comment.