Skip to content

Instantly share code, notes, and snippets.

@steventroughtonsmith
Last active December 3, 2015 22:51
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steventroughtonsmith/c24bb6b6a28c5b583008 to your computer and use it in GitHub Desktop.
Save steventroughtonsmith/c24bb6b6a28c5b583008 to your computer and use it in GitHub Desktop.
WWDC 15 Session Video Lister
//
// 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;
}
@eddyg
Copy link

eddyg commented Jun 10, 2015

Or, in python:

import json, requests

data = json.loads(requests.get('https://devimages.apple.com.edgekey.net/wwdc-services/ftzj8e4h/6rsxhod7fvdtnjnmgsun/videos.json').content)

for s in data['sessions']:
    if s['year'] == 2015:
        print s['id'], '-', s['title'], '\n', s['download_hd'], '\n'

@steventroughtonsmith
Copy link
Author

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")
    }
}

@steventroughtonsmith
Copy link
Author

…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("sessions.@unionOfObjects.download_hd"))

@pjcabrera
Copy link

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("sessions.@unionOfObjects.download_hd"))

@zydeco
Copy link

zydeco commented Jun 12, 2015

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