Last active
January 10, 2016 12:24
-
-
Save boxdot/6caef69f93a3c107ed7d to your computer and use it in GitHub Desktop.
Print the url for the recent Arte Tracks show.
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
#!/usr/bin/env python | |
"""Fetch the url of the recent arte tracks show.""" | |
import re | |
import sys | |
import urllib | |
import requests | |
# Visit main page of Arte Tacks | |
resp = requests.get('http://tracks.arte.tv/de/die-sendung') | |
resp.raise_for_status() | |
m = re.search('href="(/de/replay[^"]+?)"', resp.content) | |
if m is None: | |
raise RuntimeError("Cannot parse 'die-sendung' for video page url") | |
video_page_url = 'http://tracks.arte.tv{0}'.format(m.group(1)) | |
# Visit recent show page | |
resp = requests.get(video_page_url) | |
resp.raise_for_status() | |
m = re.search('json_url=([^&]+)&', resp.content) | |
if m is None: | |
raise RuntimeError( | |
"Cannot parse '{0}' for video json url".format(video_page_url)) | |
video_json_url = urllib.unquote(m.group(1)) | |
# Fetch video json | |
resp = requests.get(video_json_url) | |
resp.raise_for_status() | |
video = resp.json() | |
print video['videoJsonPlayer']['VSR']['HTTP_SQ_1']['url'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment