Skip to content

Instantly share code, notes, and snippets.

@jchillerup
Created September 11, 2016 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchillerup/53dff508b5dbad0a24c41e5f20b8b396 to your computer and use it in GitHub Desktop.
Save jchillerup/53dff508b5dbad0a24c41e5f20b8b396 to your computer and use it in GitHub Desktop.
Horribly hacked together script to download stuff from dr.dk/tv
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