Skip to content

Commit

Permalink
Merge branch 'release/2.14.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
SoneeJohn committed May 12, 2020
2 parents d6f4b0e + 9699eda commit 2ee18c1
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 17 deletions.
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.13.0
module_version: 2.14.0

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.13.0/XCDYouTubeKit
github_file_prefix: https://github.com/0xced/XCDYouTubeKit/tree/2.14.0/XCDYouTubeKit
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#### Version 2.14.0

* Add new `XCDYouTubeErrorEmptyResponse` error (#479)
* Adaptation to YouTube API change. (a048776eb0d87de869c1636e244d78ffb311adc6)

#### Version 2.13.0

* Deprecated `-[XCDYouTubeVideo thumbnailURL]` use `-[XCDYouTubeVideo thumbnailURLs]` (#477)
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
.macOS(.v10_10)
],
products: [
.library(name: "XCDYouTubeKit" , targets: ["XCDYouTubeKit"])
.library(name: "XCDYouTubeKit", targets: ["XCDYouTubeKit"])
],
targets: [
.target(
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ XCDYouTubeKit is available through [CocoaPods](https://cocoapods.org/), [Carthag
CocoaPods:

```ruby
pod "XCDYouTubeKit", "~> 2.13"
pod "XCDYouTubeKit", "~> 2.14"
```

Carthage:

```objc
github "0xced/XCDYouTubeKit" ~> 2.13
github "0xced/XCDYouTubeKit" ~> 2.14
```

Swift Package Manager:
Expand All @@ -48,7 +48,7 @@ Add `XCDYouTubeKit` to the dependencies value of your `Package.swift`

```swift
dependencies: [
.package(url: "https://github.com/0xced/XCDYouTubeKit.git", from: "2.13.0")
.package(url: "https://github.com/0xced/XCDYouTubeKit.git", from: "2.14.0")
]
```

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.13.0;
CURRENT_PROJECT_VERSION = 2.14.0;
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.13.0;
CURRENT_PROJECT_VERSION = 2.14.0;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
"body" : "",
"headers" : {
"Content-Type" : "text\/javascript",
"Alt-Svc" : "h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
"Age" : "13776",
"Content-Encoding" : "gzip",
"Server" : "sffe",
"X-XSS-Protection" : "0",
"Expires" : "Tue, 11 May 2021 22:13:55 GMT",
"Cache-Control" : "public, max-age=31536000",
"Date" : "Mon, 11 May 2020 22:13:55 GMT",
"Content-Length" : "431582",
"X-Content-Type-Options" : "nosniff",
"Accept-Ranges" : "bytes",
"Vary" : "Accept-Encoding, Origin",
"Last-Modified" : "Thu, 07 May 2020 00:28:50 GMT"
},
"method" : "GET",
"status" : 200,
"uri" : "https:\/\/www.youtube.com\/s\/player\/0acb4375\/player_ias.vflset\/en_US\/base.js"
},
{
"body" : "",
"headers" : {
"Content-Type" : "application\/x-www-form-urlencoded",
"P3P" : "CP=\"This is not a P3P policy! See http:\/\/support.google.com\/accounts\/answer\/151657?hl=en for more info.\"",
"Alt-Svc" : "h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
"Content-Encoding" : "br",
"Server" : "YouTube Frontend Proxy",
"X-XSS-Protection" : "0",
"Transfer-Encoding" : "Identity",
"Expires" : "Tue, 27 Apr 1971 19:44:06 GMT",
"Cache-Control" : "no-store",
"Date" : "Tue, 12 May 2020 02:03:26 GMT",
"Strict-Transport-Security" : "max-age=31536000",
"X-Content-Type-Options" : "nosniff",
"X-Frame-Options" : "SAMEORIGIN"
},
"method" : "GET",
"status" : 200,
"uri" : "https:\/\/www.youtube.com\/get_video_info?el=embedded&hl=en&ps=default&video_id=HxaM6UJpAyg"
},
{
"body" : "",
"headers" : {
"Content-Type" : "text\/html; charset=utf-8",
"P3P" : "CP=\"This is not a P3P policy! See http:\/\/support.google.com\/accounts\/answer\/151657?hl=en for more info.\"",
"Alt-Svc" : "h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
"Content-Encoding" : "br",
"Server" : "YouTube Frontend Proxy",
"X-XSS-Protection" : "0",
"Transfer-Encoding" : "Identity",
"Expires" : "Tue, 27 Apr 1971 19:44:06 GMT",
"Set-Cookie" : "VISITOR_INFO1_LIVE=ci6MCaynJqU; path=\/; domain=.youtube.com; secure; expires=Sun, 08-Nov-2020 02:03:31 GMT; httponly; samesite=None, GPS=1; path=\/; domain=.youtube.com; expires=Tue, 12-May-2020 02:33:31 GMT, YSC=GwFOF9Lp9CY; path=\/; domain=.youtube.com; secure; httponly; samesite=None",
"Cache-Control" : "no-cache",
"Date" : "Tue, 12 May 2020 02:03:31 GMT",
"Strict-Transport-Security" : "max-age=31536000",
"X-Content-Type-Options" : "nosniff",
"X-Frame-Options" : "SAMEORIGIN"
},
"method" : "GET",
"status" : 200,
"uri" : "https:\/\/www.youtube.com\/watch?bpctr=9999999999&has_verified=1&hl=en&v=HxaM6UJpAyg"
}
]

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version='1.0' encoding='UTF-8' ?>
<?charles serialisation-version='2.0' ?>
<rewriteSet-array>
<rewriteSet>
<active>true</active>
<name>testAlternativeSignatureValue</name>
<hosts>
<locationPatterns>
<locationMatch>
<location>
<protocol>https</protocol>
<host>www.youtube.com</host>
<port>443</port>
</location>
<enabled>true</enabled>
</locationMatch>
</locationPatterns>
</hosts>
<rules>
<rewriteRule>
<active>true</active>
<ruleType>7</ruleType>
<matchValue>cipher</matchValue>
<matchHeaderRegex>false</matchHeaderRegex>
<matchValueRegex>true</matchValueRegex>
<matchRequest>false</matchRequest>
<matchResponse>true</matchResponse>
<newValue>signatureCipher</newValue>
<newHeaderRegex>false</newHeaderRegex>
<newValueRegex>false</newValueRegex>
<matchWholeValue>false</matchWholeValue>
<caseSensitive>false</caseSensitive>
<replaceType>2</replaceType>
</rewriteRule>
</rules>
</rewriteSet>
</rewriteSet-array>
13 changes: 13 additions & 0 deletions XCDYouTubeKit Tests/XCDYouTubeClientTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,19 @@ - (void) testInvalidVideoIdentifier
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void) testEmptyResponse_offline
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"HxaM6UJpAyg" completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(video);
XCTAssertEqualObjects(error.domain, XCDYouTubeVideoErrorDomain);
XCTAssertEqual(error.code, XCDYouTubeErrorEmptyResponse);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:nil];
}

- (void) testNonExistentVideoIdentifier
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
Expand Down
23 changes: 23 additions & 0 deletions XCDYouTubeKit Tests/XCDYouTubeProtectedVideosTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,29 @@ - (void) testProtectedVEVOVideo3
[self waitForExpectationsWithTimeout:5 handler:nil];
}

// See testAlternativeSignatureValue.xml for Charles Proxy Setting
// Import: Charles Proxy > Tools > Rewrite
- (void) testAlternativeSignatureValue_offline
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"rId6PKlDXeU" completionHandler:^(XCDYouTubeVideo *video, NSError *error)
{
XCTAssertNil(error);
XCTAssertNotNil(video.title);
XCTAssertTrue(video.viewCount > 0);
XCTAssertNotNil(video.expirationDate);
XCTAssertNotNil(video.thumbnailURLs.firstObject);
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:5 handler:nil];
}

- (void) testProtectedVEVOIsPlayable
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
Expand Down
2 changes: 1 addition & 1 deletion XCDYouTubeKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "XCDYouTubeKit"
s.version = "2.13.0"
s.version = "2.14.0"
s.summary = "YouTube video player for iOS and OS X."
s.homepage = "https://github.com/0xced/XCDYouTubeKit"
s.screenshot = "https://raw.github.com/0xced/XCDYouTubeKit/#{s.version}/Screenshots/XCDYouTubeVideoPlayerViewController.png"
Expand Down
8 changes: 4 additions & 4 deletions XCDYouTubeKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,10 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 47;
CURRENT_PROJECT_VERSION = 48;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 2.0.0;
DYLIB_CURRENT_VERSION = 2.13.0;
DYLIB_CURRENT_VERSION = 2.14.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -741,10 +741,10 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 47;
CURRENT_PROJECT_VERSION = 48;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 2.0.0;
DYLIB_CURRENT_VERSION = 2.13.0;
DYLIB_CURRENT_VERSION = 2.14.0;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down
5 changes: 5 additions & 0 deletions XCDYouTubeKit/XCDYouTubeError.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ typedef NS_ENUM(NSInteger, XCDYouTubeErrorCode) {
* Returned when a network error occurs. See `NSUnderlyingErrorKey` in the userInfo dictionary for more information.
*/
XCDYouTubeErrorNetwork = -1,
/**
* Returned when an empty response is returned. This may indicate that YouTube has blocked requests from your IP address because of overuse.
* This error does not contain any info in the `userInfo` property and is not appropriate to show to the user.
*/
XCDYouTubeErrorEmptyResponse = -3,

/**
* Previously returned when the given video identifier string is invalid.
Expand Down
6 changes: 4 additions & 2 deletions XCDYouTubeKit/XCDYouTubeVideo.m
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,14 @@ - (instancetype) initWithIdentifier:(NSString *)identifier info:(NSDictionary *)
{
stream = XCDDictionaryWithQueryString((NSString *)streamQuery);
}
NSDictionary *alternativeStreamInfo = XCDDictionaryWithQueryString(stream[@"cipher"]);
NSDictionary *alternativeStreamInfo = XCDDictionaryWithQueryString(stream[@"cipher"]).count == 0? XCDDictionaryWithQueryString(stream[@"signatureCipher"]) : XCDDictionaryWithQueryString(stream[@"cipher"]);
NSString *alternativeURLString = alternativeStreamInfo[@"url"];

NSString *scrambledSignature = stream[@"s"] == nil? alternativeStreamInfo[@"s"] : stream[@"s"];
NSString *spParam = stream[@"sp"] == nil ? alternativeStreamInfo[@"sp"] : stream[@"sp"];


if (scrambledSignature == nil)
XCDYouTubeLogInfo(@"No scrambled signature for stream: \n%@ This might result in a error.", stream);
if (scrambledSignature && !playerScript)
{
userInfo[XCDYouTubeNoStreamVideoUserInfoKey] = self;
Expand Down
11 changes: 9 additions & 2 deletions XCDYouTubeKit/XCDYouTubeVideoOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,16 @@ - (void) handleConnectionSuccessWithData:(NSData *)data response:(NSURLResponse
CFStringEncoding encoding = CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)response.textEncodingName ?: CFSTR(""));
// Use kCFStringEncodingMacRoman as fallback because it defines characters for every byte value and is ASCII compatible. See https://mikeash.com/pyblog/friday-qa-2010-02-19-character-encodings.html
NSString *responseString = CFBridgingRelease(CFStringCreateWithBytes(kCFAllocatorDefault, data.bytes, (CFIndex)data.length, encoding != kCFStringEncodingInvalidId ? encoding : kCFStringEncodingMacRoman, false)) ?: @"";
NSAssert(responseString.length > 0, @"Failed to decode response from %@ (response.textEncodingName = %@, data.length = %@)", response.URL, response.textEncodingName, @(data.length));

XCDYouTubeLogVerbose(@"Response: %@\n%@", response, responseString);
if (responseString.length == 0)
{
//Previously we would throw an assertion here, however, this has been changed to an error
//See more here https://github.com/0xced/XCDYouTubeKit/issues/479
self.lastError = [NSError errorWithDomain:XCDYouTubeVideoErrorDomain code:XCDYouTubeErrorEmptyResponse userInfo:nil];
XCDYouTubeLogError(@"Failed to decode response from %@ (response.textEncodingName = %@, data.length = %@)", response.URL, response.textEncodingName, @(data.length));
[self finishWithError];
return;
}

switch (requestType)
{
Expand Down

0 comments on commit 2ee18c1

Please sign in to comment.