Skip to content

Instantly share code, notes, and snippets.

@mplattner
Last active March 23, 2020 16:48
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 mplattner/1985100d6469048801761e4c3b87d12a to your computer and use it in GitHub Desktop.
Save mplattner/1985100d6469048801761e4c3b87d12a to your computer and use it in GitHub Desktop.
FM4 Davidecks Downloader
#!/usr/bin/python3
import requests
import wget
import datetime
from bs4 import BeautifulSoup
r = requests.get(url='https://fm4.orf.at/tags/davidecksplaylist/')
soup = BeautifulSoup(r.content, 'html.parser')
latestPlaylistUrl = soup.find('div', class_='listItem').find('a')['href']
if latestPlaylistUrl:
r = requests.get(url=latestPlaylistUrl)
soup = BeautifulSoup(r.content, 'html.parser')
playlistHtml = soup.find(id='ss-storyText')
playlistTitle = playlistHtml.find('h1').text
with open(datetime.datetime.today().strftime('%Y-%m-%d_%H-%M-%S') + ' - ' + playlistTitle + '.html', 'w') as f:
f.write(str(playlistHtml))
r = requests.get(url='https://audioapi.orf.at/fm4/api/json/current/broadcast/4DD')
responseData = r.json()
with open(datetime.datetime.today().strftime('%Y-%m-%d_%H-%M-%S') + '.json', 'wb') as f:
f.write(r.content)
startTitleMap = {}
for timelineEntry in responseData['items']:
if 'title' in timelineEntry and timelineEntry['type'] not in ['W', 'N']:
startTitleMap[timelineEntry['start']] = timelineEntry['title']
for stream in responseData['streams']:
print("Downloading '" + stream['loopStreamId'] + "': Please wait...")
if stream['start'] in startTitleMap:
print("Title: " + startTitleMap[stream['start']])
wget.download('https://loopstream01.apa.at/?channel=fm4&shoutcast=0&player=fm4_v1&referer=fm4.orf.at&id=' + stream['loopStreamId'], stream['loopStreamId'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment