Last active
December 31, 2017 13:12
-
-
Save oliver/57100b96b3527ac4c8db15a8d5619cf4 to your computer and use it in GitHub Desktop.
fetches video URLs from media.ccc.de
This file contains hidden or 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
#!/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"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: this command will give the same results:
curl https://media.ccc.de/c/34c3/podcast/mp4-master.xml | awk -F '"' '/url="/{print $2}'
(courtesy of https://events.ccc.de/congress/2017/wiki/index.php/Static:Streams).