Skip to content

Commit

Permalink
Set session user-agent to desktop client (fixes 0xced#510)
Browse files Browse the repository at this point in the history
YouTube appears to randomly redirect client to mobile site. This should fix the issue for now
  • Loading branch information
SoneeJohn authored and dpwilhelmsen committed Jun 19, 2021
1 parent 12f6a1c commit 81dbc03
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions XCDYouTubeKit/XCDYouTubeVideoOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ - (instancetype) initWithVideoIdentifier:(NSString *)videoIdentifier languageIde
_videoIdentifier = videoIdentifier ?: @"";
_languageIdentifier = languageIdentifier ?: @"en";

_session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
_cookies = [cookies copy];
_customPatterns = [customPatterns copy];

for (NSHTTPCookie *cookie in _cookies) {
[_session.configuration.HTTPCookieStorage setCookie:cookie];
[configuration.HTTPCookieStorage setCookie:cookie];
}

NSString *cookieValue = [NSString stringWithFormat:@"f1=50000000&f6=8&hl=%@", _languageIdentifier];
Expand All @@ -107,7 +107,9 @@ - (instancetype) initWithVideoIdentifier:(NSString *)videoIdentifier languageIde
NSHTTPCookieSecure:@"TRUE"
}];

[_session.configuration.HTTPCookieStorage setCookie:additionalCookie];
[configuration.HTTPCookieStorage setCookie:additionalCookie];
configuration.HTTPAdditionalHeaders = @{@"User-Agent": @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15"};
_session = [NSURLSession sessionWithConfiguration:configuration];
_operationStartSemaphore = dispatch_semaphore_create(0);

return self;
Expand Down

0 comments on commit 81dbc03

Please sign in to comment.