Skip to content

Instantly share code, notes, and snippets.

@primaeval
Created March 14, 2016 11:24
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 primaeval/276a3965194a8ee167a6 to your computer and use it in GitHub Desktop.
Save primaeval/276a3965194a8ee167a6 to your computer and use it in GitHub Desktop.
find bbc live tv streams
import requests
import re
import random
'''
for channel in [
'bbc_one_hd',
'bbc_two_hd',
'bbc_four_hd',
'cbbc_hd',
'cbeebies_hd',
'bbc_news24',
'bbc_parliament',
'bbc_alba',
's4cpbs',
'bbc_one_london',
'bbc_one_scotland_hd',
'bbc_one_northern_ireland_hd',
'bbc_one_wales_hd',
'bbc_two_scotland',
'bbc_two_northern_ireland_digital',
'bbc_two_wales_digital',
'sport_stream_01',
'sport_stream_02',
'sport_stream_03',
'sport_stream_04',
'sport_stream_05',
'sport_stream_06',
'sport_stream_07',
'sport_stream_08',
'sport_stream_09',
'sport_stream_10',
'sport_stream_11',
'sport_stream_12',
'sport_stream_13',
'sport_stream_14',
'sport_stream_15',
'sport_stream_16',
'sport_stream_17',
'sport_stream_18',
'sport_stream_19',
'sport_stream_20',
'sport_stream_21',
'sport_stream_22',
'sport_stream_23',
'sport_stream_24',
]:
'''
for channel in ['bbc_one_hd','bbc_one_london','sport_stream_01']:
strm = '%s.strm' % channel
f = open(strm, 'w')
for protocol in ['hls']:
for device in ['pc','iptv-all', 'apple-ipad-hls']:
manifest_url = "http://open.live.bbc.co.uk/mediaselector/5/select/version/2.0/mediaset/%s/vpid/%s/transferformat/%s?cb=%d" % \
(device, channel, protocol, random.randrange(10000,99999))
#print manifest_url
r = requests.get(manifest_url)
html = r.text
#print html
match = re.compile(
'media.+?bitrate="(.+?)".+?encoding="(.+?)".+?connection.+?href="(.+?)".+?supplier="(.+?)".+?transferFormat="(.+?)"'
).findall(html)
playlist_urls = set()
for bitrate, encoding, url, supplier, transfer_format in match:
playlist_urls.add((supplier, url))
for (supplier, playlist_url) in playlist_urls:
r = requests.get(playlist_url)
html = r.text
match = re.compile('#EXT-X-STREAM-INF:PROGRAM-ID=(.+?),BANDWIDTH=(.+?),CODECS="(.*?)",RESOLUTION=(.+?)\s*(.+?.m3u8)').findall(html)
if match:
print playlist_url
for id, bandwidth, codecs, resolution, url in match:
f.write( "#EXTINF:0,%s %s %s %s %s %s\n%s\n" % (channel, protocol, device, supplier, bandwidth, resolution, url))
for cast in ['simulcast', 'webcast']:
### HDS #BUG high bitrate streams play at low bitrate
for device in ['pc', 'apple-ipad-hls']:
for provider in ['ak', 'llnw']:
url = 'http://a.files.bbci.co.uk/media/live/manifesto/audio_video/%s/hds/uk/%s/%s/%s.f4m' % (cast, device, provider, channel)
#print url
r = requests.get(url)
html = r.text
#print html
streams = re.compile('<media href="(.+?)" bitrate="(.+?)"/>').findall(html)
if streams:
print url
for stream in streams:
bitrate = stream[1]
bandwidth = int(int(bitrate) * 1000.0)
url = re.sub('.f4m$','.m3u8',stream[0])
f.write( "#EXTINF:0,%s %s hds %s %s %s\n%s\n" % (channel, cast, device, provider, bandwidth, url))
### HLS
for device in ['abr_hdtv', 'hdtv', 'tv', 'hls_tablet']:
for provider in ['ak', 'llnw']:
url = 'http://a.files.bbci.co.uk/media/live/manifesto/audio_video/%s/hls/uk/%s/%s/%s.m3u8' % (cast, device, provider, channel)
#print url
r = requests.get(url)
html = r.text
#print html
streams = re.compile('#EXT-X-STREAM-INF:PROGRAM-ID=(.+?),BANDWIDTH=(.+?),CODECS="(.*?)",RESOLUTION=(.+?)\s*(.+?.m3u8)').findall(html)
if streams:
print url
for stream in streams:
bandwidth = stream[1]
resolution = stream[3]
url = stream[4]
f.write( "#EXTINF:0,%s %s hls %s %s %s %s\n%s\n" % (channel, cast, device, provider, bandwidth, resolution, url))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment