Skip to content

Instantly share code, notes, and snippets.

@pa4373
Last active October 19, 2019 15:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pa4373/327076f5a5adfb9dbf29 to your computer and use it in GitHub Desktop.
Save pa4373/327076f5a5adfb9dbf29 to your computer and use it in GitHub Desktop.
不用開hichannel網頁也能聽中廣流行網
#!/usr/bin/env python
import time
import base64
import hashlib
import urllib
import urlparse
import urllib2
import subprocess
from collections import OrderedDict
def gen_token(path, timestamp, ip_addr, token_ord):
const_str = 'radio@himediaservice#t'
cat_str = path + str(timestamp) + ip_addr + const_str + str(token_ord)
hashed = hashlib.md5(unicode(cat_str)).digest()
b64_md5hash = base64.b64encode(hashed)
return b64_md5hash.replace('+', '-').replace('/', '_').replace('=', '')
def build_url():
base_url = 'http://radio-hichannel.cdn.hinet.net/'
ip_addr = urllib2.urlopen('http://ipinfo.io/ip').read().rstrip()
path = '/live/pool/hich-ra000009/ra-hls/'
expire1 = int(time.time())
expire2 = expire1 + (60 * 60 * 8)
params = OrderedDict([
('token1', gen_token(path, expire1, ip_addr, 1)),
('token2', gen_token(path, expire2, ip_addr, 2)),
('expire1', expire1),
('expire2', expire2)
])
params_str = urllib.urlencode(params)
return urlparse.urljoin(base_url, path + 'index.m3u8') + '?' + params_str
def check_url_alive(url):
try:
urllib2.urlopen(url)
return True
except urllib2.HTTPError:
return False
def ffplay(source):
_prefix_url = "ffmpeg://{}".format(source)
print "HIT RETURN TO QUIT\n"
subprocess.call(['mplayer', '-msglevel', 'all=-1',
'-cache', '1024', _prefix_url])
def main():
is_alive = None
while is_alive != True:
url = build_url()
is_alive = check_url_alive(url)
try:
ffplay(url)
except KeyboardInterrupt:
exit()
if __name__ == '__main__':
main()
@yuyungyang
Copy link

嗨 請問 #12 const_str = 'radio@himediaservice#t'
是否已經失效了

@ksc91u
Copy link

ksc91u commented Mar 8, 2017

感謝大神
請問一下 ra000009 這個是怎麼來的呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment