Created
September 11, 2016 18:21
-
-
Save jchillerup/53dff508b5dbad0a24c41e5f20b8b396 to your computer and use it in GitHub Desktop.
Horribly hacked together script to download stuff from dr.dk/tv
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
import os, sys, re | |
import requests, json | |
slug = sys.argv[1].split('/')[-1] | |
metadata = requests.get("http://www.dr.dk/mu-online/api/1.3/page/tv/player/%s" % slug).json() | |
primary_asset_uri = metadata["ProgramCard"]["PrimaryAsset"]["Uri"] | |
primary_asset = requests.get(primary_asset_uri).json() | |
for link in primary_asset["Links"]: | |
if link["Target"] == "HDS": | |
stream_uri = link["Uri"] | |
break | |
playlist_uri = stream_uri.replace('/z/', '/i/').replace('manifest.f4m', 'master.m3u8') | |
playlist = requests.get(playlist_uri).text.splitlines() | |
while not playlist[0].startswith("#EXT-X-STREAM-INF"): | |
playlist.pop(0) | |
records = [] | |
for i in range(len(playlist) // 2): | |
header = playlist[i * 2] | |
url = playlist[i * 2 + 1] | |
bandwidth = int(re.search(r'BANDWIDTH=(\d+)', header[18:]).group(1)) | |
records.append((bandwidth, url)) | |
records.sort(reverse=True) | |
bandwidth, url = records[0] | |
cmdline = "ffmpeg -i '%s' -acodec copy -vcodec copy -absf aac_adtstoasc '%s.mp4' " % (url, slug) | |
print(cmdline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment