XCDYouTubeKit icon indicating copy to clipboard operation
XCDYouTubeKit copied to clipboard

Add the NSDictionary to the header of XCDYouTubeVideo

Open SoneeJohn opened this issue 8 years ago • 1 comments

I think exposing the NSDictionary object that the XCDYouTubeVideo class is initialized with would be really helpful. For instance, this would make it more flexible to use features that aren't implemented by the library as yet (https://github.com/0xced/XCDYouTubeKit/pull/281). Sometimes pull requests may not be merged with the library for whatever reason. By exposing this property it enables us to add these features on our own.

Currently, this is my method of getting the NSDictionary which isn't pretty for obvious reasons. 😉

self.operation = [[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"wJdeVtnUxuk" completionHandler:^(XCDYouTubeVideo * _Nullable video, NSError * _Nullable error) {
            
            NSURLSessionDataTask *task = [self.operation valueForKey:@"dataTask"];
            
            if (!task) {
                return;
            }
            
            [[[NSURLSession sharedSession]dataTaskWithURL:task.response.URL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                
                if (!data) {
                    return;
                }
                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)) ?: @"";

                NSDictionary *dic = DictionaryWithQueryString(responseString);
                
                
            }]resume];
            
        }];

SoneeJohn avatar Dec 29 '16 03:12 SoneeJohn

Update: Plus my method does not always work in getting back the original dictionary that the XCDYouTubeVideo was initialized with.

SoneeJohn avatar Dec 29 '16 23:12 SoneeJohn