#!/usr/bin/env python # # Downloads URLs for all talks of a conference from media.ccc.de. # Prefers HD videos with many languages. # Prints a list of URLs, for use eg. with wget -i . # import requests baseUrl = "https://api.media.ccc.de/public" conferenceAcronym = "34c3" def getJson(url): r = requests.get(url) return r.json() confUrl = baseUrl + "/conferences/" + conferenceAcronym def calcSortKey(rec): """ Returns a sort key for a recording. The returned key is a list of integers, each of which represents an aspect of the recording. Items at start of the list represent the more important aspects. For each aspect, lower numbers mean that the recording will be preferred over recordings with a higher number. """ key = [] INF = 2**62 # we want video, not audio: mimeTypePrefs = ["video/mp4", "video/webm"] try: key.append(mimeTypePrefs.index(rec["mime_type"])) except: key.append(INF) # we don't want slides-only videos: if rec["folder"].find("slides-") >= 0: key.append(1) else: key.append(0) # prefer videos with many languages (by counting number of hyphens in strings like "deu-eng-fra"): key.append(INF - rec["language"].count("-")) # prefer high-quality video key.append(not(rec["high_quality"])) # prefer highest-resolution video key.append(INF - (rec["width"]*rec["height"])) return key for event in getJson(confUrl)["events"]: #print "event: %s (%s)" % (event["title"], event["url"]) recs = getJson(event["url"])["recordings"] recs.sort(key=calcSortKey) print recs[0]["recording_url"]