Skip to content

Instantly share code, notes, and snippets.

@mayli
Last active December 24, 2015 22:16
Show Gist options
  • Save mayli/9c934c2e7172339708cb to your computer and use it in GitHub Desktop.
Save mayli/9c934c2e7172339708cb to your computer and use it in GitHub Desktop.
Generate rtmp.strm file for tv.byr.cn
#!/usr/bin/env python
import urllib
import re
import os
import shutil
URL = "http://tv.byr.cn/mobile/"
TV_STR = '"col-md-12"'
RE_TV = re.compile('<a>(.+)<\/a>')
RE_CHANNEL = re.compile('"http:\/\/tv6.byr.cn\/hls\/([a-z0-9]+).m3u8.*?">(.*?)<\/a>')
RTMP_TMPL = 'rtmp://localhost:1935/livetv/{channel}.flv'
FN_TMPL = '{name}.strm'
def fetch_html(url=URL):
return urllib.urlopen(url).read()
def split_tv(html):
return html.split(TV_STR)[1:]
def dump_all():
for tv_html in split_tv(fetch_html(URL)):
tv = RE_TV.findall(tv_html)[0]
print tv
if not os.path.isdir(tv):
os.mkdir(tv)
for channel, name in RE_CHANNEL.findall(tv_html):
print channel, name
filename = FN_TMPL.format(name=name)
filename = os.path.join(tv, filename)
if not os.path.isfile(name):
open(filename, "w").write(RTMP_TMPL.format(channel=channel))
if __name__ == '__main__':
dump_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment