Skip to content

Instantly share code, notes, and snippets.

@honzajavorek
Last active December 28, 2015 18:19
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 honzajavorek/7541798 to your computer and use it in GitHub Desktop.
Save honzajavorek/7541798 to your computer and use it in GitHub Desktop.
This script exports all radio streams from play.cz to a nice m3u playlist format.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from urlparse import urlparse, parse_qs
import requests
import lxml.html
def playcz():
data_url = (
'http://api.play.cz/jsonp/getStream/{}/wma,mp3,aac/'
'160/?r=listen.play.cz&callback=x'
)
resp = requests.get('http://www.play.cz/radio/')
soup = lxml.html.fromstring(resp.content)
radio_links = soup.cssselect('li a[href^="http://www.play.cz/radio/"]')
print '#EXTM3U\n'
for radio_link in radio_links:
resp = requests.get(radio_link.get('href'))
soup = lxml.html.fromstring(resp.content)
listen_links = soup.cssselect('a[href^="http://listen.play.cz/"]')
listen_link = listen_links[0].get('href')
shortcut = parse_qs(urlparse(listen_link).query)['shortcut'][0]
resp = requests.get(data_url.format(shortcut))
data = json.loads(resp.content[2:-2]) # stripping the callback
title = data['data']['radio']['title']
stream_url = data['data']['stream']['pubpoint']
print u'#EXTINF:-1,{}\n'.format(title).encode('utf-8')
print '{}\n'.format(stream_url)
if __name__ == '__main__':
playcz()
requests
cssselect
lxml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment