Last active
December 3, 2015 22:51
-
-
Save steventroughtonsmith/c24bb6b6a28c5b583008 to your computer and use it in GitHub Desktop.
WWDC 15 Session Video Lister
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// wwcd15sessionlister | |
// | |
// Created by Steven Troughton-Smith on 10/06/2015. | |
// | |
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://devimages.apple.com.edgekey.net/wwdc-services/ftzj8e4h/6rsxhod7fvdtnjnmgsun/videos.json"]]; | |
NSData * d = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil]; | |
NSDictionary *wwdc = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:d options:0 error:nil]; | |
NSArray *sessions = [wwdc valueForKeyPath:@"sessions"]; | |
sessions = [sessions sortedArrayWithOptions:0 usingComparator:^NSComparisonResult(NSDictionary *session1, NSDictionary *session2) { | |
if ([session1[@"id"] intValue] > [session2[@"id"] intValue]) | |
{ | |
return NSOrderedDescending; | |
} | |
return NSOrderedAscending; | |
}]; | |
for (NSDictionary *session in sessions) | |
{ | |
if ([[session[@"year"] stringValue] isEqualToString:@"2015"]) | |
{ | |
NSString *filename = [session[@"download_hd"] lastPathComponent]; | |
printf("%s - %s\n%s\n\n", [[session[@"id"] stringValue] UTF8String], [session[@"title"] UTF8String], [session[@"download_hd"] UTF8String] ); | |
} | |
} | |
} | |
return 0; | |
} |
Or some sloppy Swift 2.0:
import Foundation
let req = NSURLRequest(URL: NSURL(string:"https://devimages.apple.com.edgekey.net/wwdc-services/ftzj8e4h/6rsxhod7fvdtnjnmgsun/videos.json")!)
let data = try NSURLConnection.sendSynchronousRequest(req, returningResponse: nil)
let wwdc = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments)
var sessions = wwdc.valueForKeyPath("sessions") as! NSArray
for session in sessions.sortedArrayUsingDescriptors([NSSortDescriptor(key: "id", ascending: true)])
{
if session["year"] as! Int == 2015
{
let id = session["id"] as! Int
let title = session["title"] as! String
let download = session["download_hd"] as! String
print("\(id) - \(title)\n\(download)\n")
}
}
…and a gross mini version
import Foundation
let data = NSData(contentsOfURL: NSURL(string:"https://devimages.apple.com.edgekey.net/wwdc-services/ftzj8e4h/6rsxhod7fvdtnjnmgsun/videos.json")!)!
let wwdc = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments)
print(wwdc.valueForKeyPath("[email protected]_hd"))
Gross mini version in Swift 1.2
import Foundation
let data = NSData(contentsOfURL: NSURL(string:"https://devimages.apple.com.edgekey.net/wwdc-services/ftzj8e4h/6rsxhod7fvdtnjnmgsun/videos.json")!)!
let wwdc: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments, error: nil)
print(wwdc!.valueForKeyPath("[email protected]_hd"))
I made a pyramidal swift version, but github didn't seem to like the abundance of emojis 😦
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or, in python: