Skip to content

Commit

Permalink
Add logs to query operation and other related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SoneeJohn committed Feb 19, 2020
1 parent b473f4f commit 8bccc9d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
11 changes: 11 additions & 0 deletions XCDYouTubeKit/XCDURLGetOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "XCDURLGetOperation.h"
#import "XCDYouTubeLogger+Private.h"

@interface XCDURLGetOperation() <NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
@property (atomic, assign) BOOL isExecuting;
Expand Down Expand Up @@ -64,6 +65,8 @@ - (void) start
if (self.isCancelled)
return;

XCDYouTubeLogInfo(@"Starting URL GET operation: %@", self);

self.isExecuting = YES;

[self startRequest];
Expand All @@ -74,6 +77,8 @@ - (void) cancel
if (self.isCancelled || self.isFinished)
return;

XCDYouTubeLogInfo(@"Canceling URL GET operation: %@", self);

[super cancel];

[self.dataTask cancel];
Expand All @@ -88,6 +93,7 @@ - (void) cancel
- (void)finishWithError:(NSError *)error
{
self.error = error;
XCDYouTubeLogError(@"URL GET operation finished with error: %@\nDomain: %@\nCode: %@\nUser Info: %@", self.error.localizedDescription, self.error.domain, @(self.error.code), self.error.userInfo);
[self finish];
}

Expand All @@ -96,6 +102,7 @@ - (void)finish
self.isExecuting = NO;
self.isFinished = YES;
[self.session invalidateAndCancel];
XCDYouTubeLogInfo(@"URL GET operation finished");
}

#pragma mark -
Expand All @@ -109,6 +116,9 @@ - (void)startRequest

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.url];
[request addValue:[NSString stringWithFormat:@"bytes=%@-%@", @(rangeStart), @(rangeEnd)] forHTTPHeaderField:@"Range"];

XCDYouTubeLogDebug(@"Starting URL GET operation with URL: %@", self.url);
XCDYouTubeLogInfo(@"URL GET request: %@", request.description);

self.dataTask = [self.session dataTaskWithRequest:request];

Expand Down Expand Up @@ -152,6 +162,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)dataTask didCompleteWithError:(NSError *)error
{
self.response = dataTask.response;
XCDYouTubeLogVerbose(@"%@ Response: %@", self, self.response);
if (self.isCancelled)
return;

Expand Down
16 changes: 16 additions & 0 deletions XCDYouTubeKit/XCDURLHeadOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "XCDURLHeadOperation.h"
#import "XCDYouTubeLogger+Private.h"

@interface XCDURLHeadOperation ()
@property (atomic, assign) BOOL isExecuting;
Expand Down Expand Up @@ -65,6 +66,8 @@ - (void) start
if (self.isCancelled)
return;

XCDYouTubeLogInfo(@"Starting URL HEAD operation: %@", self);

self.isExecuting = YES;

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.url];
Expand All @@ -79,6 +82,17 @@ - (void) start
self.response = response;
self.error = error;

XCDYouTubeLogVerbose(@"%@ Response: %@", self, self.response);

if (self.error)
{
XCDYouTubeLogError(@"URL HEAD operation finished with error: %@\nDomain: %@\nCode: %@\nUser Info: %@", self.error.localizedDescription, self.error.domain, @(self.error.code), self.error.userInfo);
}
else
{
XCDYouTubeLogInfo(@"URL HEAD operation finished with success");
}

self.isExecuting = NO;
self.isFinished = YES;

Expand All @@ -94,6 +108,8 @@ - (void) cancel

[super cancel];

XCDYouTubeLogInfo(@"Canceling URL HEAD operation: %@", self);

[self.dataTask cancel];

dispatch_semaphore_wait(self.operationStartSemaphore, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(200 * NSEC_PER_MSEC)));
Expand Down
12 changes: 10 additions & 2 deletions XCDYouTubeKit/XCDYouTubeVideoQueryOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "XCDURLHeadOperation.h"
#import "XCDYouTubeError.h"
#import "XCDURLGetOperation.h"
#import "XCDYouTubeLogger+Private.h"

@interface XCDYouTubeVideoQueryOperation ()

Expand Down Expand Up @@ -74,6 +75,8 @@ - (void) start
if (self.isCancelled)
return;

XCDYouTubeLogInfo(@"Starting query operation: %@", self);

self.isExecuting = YES;
[self startQuery];
}
Expand All @@ -82,7 +85,9 @@ - (void) cancel
{
if (self.isCancelled || self.isFinished)
return;


XCDYouTubeLogInfo(@"Canceling query operation: %@", self);

[super cancel];

[self.queryQueue cancelAllOperations];
Expand All @@ -96,6 +101,8 @@ - (void) cancel

- (void) startQuery
{
XCDYouTubeLogDebug(@"Starting query request for video: %@", self.video);

NSMutableArray <XCDURLHeadOperation *>*HEADOperations = [NSMutableArray new];
BOOL isHTTPLiveStream = self.video.streamURLs[XCDYouTubeVideoQualityHTTPLiveStreaming] != nil;

Expand Down Expand Up @@ -189,14 +196,15 @@ - (void) finishWithStreamURLs:(NSDictionary *)streamURLs streamErrors:(NSDiction
[self finishWithError:error];
return;
}

XCDYouTubeLogInfo(@"Query operation finished with success: %@", streamURLs);
self.streamURLs = [streamURLs copy];
[self finish];
}

- (void) finishWithError:(NSError *)error
{
self.error = error;
XCDYouTubeLogError(@"Query operation finished with error: %@\nDomain: %@\nCode: %@\nUser Info: %@", self.error.localizedDescription, self.error.domain, @(self.error.code), self.error.userInfo);
[self finish];
}

Expand Down

0 comments on commit 8bccc9d

Please sign in to comment.