{"id":3031,"date":"2017-02-08T09:59:52","date_gmt":"2017-02-08T01:59:52","guid":{"rendered":"http:\/\/blog.hoyo.idv.tw\/?p=3031"},"modified":"2020-08-11T11:39:32","modified_gmt":"2020-08-11T03:39:32","slug":"hinet-hichannel-%e5%8f%96%e5%be%97-index-m3u8-%e6%92%ad%e6%94%be%e8%b7%af%e5%be%91","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=3031","title":{"rendered":"hinet hichannel \u53d6\u5f97 index.m3u8 \u64ad\u653e\u8def\u5f91"},"content":{"rendered":"<h2>2020\/8\/11 \u505c\u6b62\u7dad\u8b77<\/h2>\n<p>hichannel \u66f4\u6539\u4e86 token \uff0c\u73fe\u5728\u53ea\u9700\u8981\u4e00\u500b token \u548c\u4e00\u500b\u00a0expires \uff0c\u56e0\u70ba\u6c92\u6709\u5be6\u969b\u5229\u76ca Hoyo \u672c\u4eba\u4e5f\u6c92\u5728\u4f7f\u7528\u9019\u500b\u6536\u807d\u529f\u80fd\uff0c\u56e0\u6b64\u505c\u6b62\u7dad\u8b77<\/p>\n<p>--<\/p>\n<h2>\u5be6\u969b\u904b\u4f5c\u7d50\u679c<\/h2>\n<ul>\n<li><a href=\"https:\/\/hoyo.idv.tw\/?a=Tools\/HinetRadio\" target=\"_blank\" rel=\"noopener\">Hinet Radio M3U8<\/a><\/li>\n<\/ul>\n<p>--<\/p>\n<p>\u5148\u770b\u4e00\u4e0b\u53ef\u64ad\u653e\u7684\u5be6\u969b\u6848\u4f8b\u7db2\u5740<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/radio-hichannel.cdn.hinet.net\/live\/pool\/hich-ra000073\/ra-hls\/index.m3u8?token1=ICzRSfp8Qy6wVuIDVIlOLg&amp;token2=cSVWYP2kBp49hiIha41Y-A&amp;expire1=1462880161&amp;expire2=1462908961<\/pre>\n<p>\u89e3\u8b80<\/p>\n<ol>\n<li>ra-000073 \u662f\u983b\u9053\u7684\u4ee3\u865f\u540d\u7a31\uff0cra-000073 \u662f NEWS98 \uff0cKissRadio \u662f ra-000042<\/li>\n<li>index.m3u8 \u8868\u793a\u4f7f\u7528 HTTP HLS \u4e32\u6d41\u6280\u8853<\/li>\n<li>expire1 &amp; expire2 \u8868\u793a<strong>\u53ef\u4ee5\u57f7\u884c<\/strong>\u64ad\u653e\u7684\u6642\u9593\u5340\u9593\uff0c\u4f60\u62ff\u4e00\u500b\u65e9\u4e0a\u516b\u9ede\u5230\u4e0b\u5348\u56db\u9ede\u7684\u64ad\u653e\u7db2\u5740\u5728\u665a\u4e0a\u57f7\u884c\u662f\u4e0d\u80fd\u64ad\u653e\u7684<\/li>\n<li>token1 &amp; token2 \u548c expire \u662f\u76f8\u547c\u61c9\u7684\uff0c\u610f\u601d\u5c31\u662f\u5982\u679c expire \u7684\u6578\u503c\u70ba 1000 \u7b97\u51fa token \u662f ABC999 \uff0c\u90a3\u4e00\u6a23\u7684\u57f7\u884c\u74b0\u5883\u7b97\u51fa\u7684 token \u5c31\u6703\u76f8\u540c<\/li>\n<\/ol>\n<p>--<\/p>\n<p><strong>\u53c3\u8003\u8cc7\u6599<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/gist.github.com\/pa4373\/327076f5a5adfb9dbf29\" target=\"_blank\" rel=\"noopener noreferrer\">\u4e0d\u7528\u958bhichannel\u7db2\u9801\u4e5f\u80fd\u807d\u4e2d\u5ee3\u6d41\u884c\u7db2 \u00b7 GitHub<\/a><\/li>\n<\/ul>\n<pre class=\"nums:true lang:python decode:true\">#!\/usr\/bin\/env python\r\nimport time\r\nimport base64\r\nimport hashlib\r\nimport urllib\r\nimport urlparse\r\nimport urllib2\r\nimport subprocess\r\nfrom collections import OrderedDict\r\n\r\ndef gen_token(path, timestamp, ip_addr, token_ord):\r\n    const_str = 'radio@himediaservice#t'\r\n    cat_str = path + str(timestamp) + ip_addr + const_str + str(token_ord)\r\n    hashed = hashlib.md5(unicode(cat_str)).digest()\r\n    b64_md5hash = base64.b64encode(hashed)\r\n    return b64_md5hash.replace('+', '-').replace('\/', '_').replace('=', '')\r\n\r\ndef build_url():\r\n    base_url = 'http:\/\/radio-hichannel.cdn.hinet.net\/'\r\n    ip_addr = urllib2.urlopen('http:\/\/ipinfo.io\/ip').read().rstrip()\r\n    path = '\/live\/pool\/hich-ra000009\/ra-hls\/'\r\n    expire1 = int(time.time())\r\n    expire2 = expire1 + (60 * 60 * 8)\r\n    params = OrderedDict([\r\n        ('token1', gen_token(path, expire1, ip_addr, 1)),\r\n        ('token2', gen_token(path, expire2, ip_addr, 2)),\r\n        ('expire1', expire1),\r\n        ('expire2', expire2)\r\n    ])\r\n    params_str = urllib.urlencode(params)\r\n    return urlparse.urljoin(base_url, path + 'index.m3u8') + '?' + params_str\r\n\r\ndef check_url_alive(url):\r\n    try:\r\n        urllib2.urlopen(url)\r\n        return True\r\n    except urllib2.HTTPError:\r\n        return False\r\n\r\ndef ffplay(source):\r\n    _prefix_url = \"ffmpeg:\/\/{}\".format(source)\r\n    print \"HIT RETURN TO QUIT\\n\"\r\n    subprocess.call(['mplayer', '-msglevel', 'all=-1',\r\n                     '-cache', '1024', _prefix_url])\r\n\r\ndef main():\r\n    is_alive = None\r\n    while is_alive != True:\r\n        url = build_url()\r\n        is_alive = check_url_alive(url)\r\n\r\n    try:\r\n        ffplay(url)\r\n    except KeyboardInterrupt:\r\n        exit()\r\n\r\nif __name__ == '__main__':\r\n    main()<\/pre>\n<p>\u5beb PHP \u7684\u4eba\u8f49\u5230 python \u6703\u9047\u5230\u7684\u554f\u984c\u6709<\/p>\n<ol>\n<li>\u7d50\u675f\u4e0d\u7528\u52a0\u5206\u865f<\/li>\n<li>\\t \u548c\u7a7a\u767d\u662f\u5751\u7239\u7684\u4e0d\u4e00\u6a23<\/li>\n<li>\u7e2e\u884c\u4e0d\u662f\u723d\u7e2e\u5c31\u53ef\u4ee5\u7e2e<\/li>\n<li>\u76f8\u540c\u529f\u80fd\u7684 function \u9810\u8a2d\u7684\u8f38\u51fa\u548c PHP \u4e0d\u540c<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>\u597d\u597d\u7814\u7a76\u4e00\u4e0b\u7db2\u9801\u662f\u5982\u4f55\u904b\u4f5c\uff0c\u8ffd\u5230\u4e86 radio_proxy.swf \u9019\u500b\u6a94\u6848\uff0c\u7db2\u9801\u7684\u64ad\u653e\u6700\u5f8c\u5c31\u662f\u7531\u9019\u500b Flash \u6a94\u6848\u751f\u6210\u64ad\u653e\u8def\u5f91\uff0c\u9019\u6642\u53c8\u8981\u5c0b\u627e\u300c\u53cd\u7d44\u8b6f\u300d\u9ed1\u79d1\u6280<\/p>\n<p>\u53ef\u60dc\u7684\u662f\uff0c\u9583\u5ba2\u00a0Sothink SWF Decompile \u89e3\u4e0d\u958b\uff0c\u5927\u6982\u4e5f\u6709\u53cd\u5236\u9ed1\u79d1\u6280\u7684\u6280\u8853\u5427<\/p>\n<p>\u9084\u597d\u9019\u7a2e\u6771\u897f\u6709\u7dda\u4e0a\u7248\u53ef\u4ee5\u7528\uff01\uff1f...<\/p>\n<ul>\n<li><a href=\"http:\/\/www.showmycode.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Show My Code | Flash decompiler<\/a><\/li>\n<\/ul>\n<p>\u4e0d\u77e5\u9053\u7576\u6642\u54ea\u4f86\u7684\u8166\u6d1e\u60f3\u5230\u4e0a\u7db2\u627e online \u7248\uff0c\u4e0d\u904e\u7d50\u679c\u662f\u7f8e\u597d\u7684\uff0c\u81f3\u5c11\u662f\u89e3\u958b\u6709\u770b\u5230\u985e\u4f3c ActionScript \u7684\u8f38\u51fa\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u6709\u95dc\u7522\u751f token \u7684\u7247\u6bb5\u7a0b\u5f0f<\/p>\n<pre class=\"nums:true lang:as decode:true\">public function buildPlayUrl(clientIP:String, url:String):String{\r\n    if ((clientIP == null)){\r\n    } else {\r\n        (clientIP == null);\r\n    };\r\n    if ((clientIP == null)){\r\n        return (\"null ip or url\");\r\n    };\r\n    var pos:int = url.lastIndexOf(\"\/\");\r\n    if (pos &gt;= 0){\r\n    } else {\r\n        throw (new ArgumentError((\"error stream url format:\" + url)));\r\n    };\r\n    this.debug((\"build token =&gt; client ip:\" + clientIP));\r\n    var len:int = url.length;\r\n    var location:String = url.substr((pos + 1), len).toLowerCase();\r\n    var path:String = ((\"\/live\/pool\/hich-\" + location) + \"\/ra-hls\/\");\r\n    var now:Date = new Date();\r\n    now.time = (now.time + ((1000 * 60) * 5));\r\n    var expire1:String = this.toSecTimeStr(now.time);\r\n    now.time = (now.time + (((1000 * 60) * 60) * 8));\r\n    var expire2:String = this.toSecTimeStr(now.time);\r\n    var key1:String = (this.KEYS[0] + \"1\");\r\n    var key2:String = (this.KEYS[0] + \"2\");\r\n    var token1:String = this.buildToken(path, expire1.toString(), clientIP, key1);\r\n    var token2:String = this.buildToken(path, expire2.toString(), clientIP, key2);\r\n    var mp4Url:String = ((this.DOMAIN[0] + path) + \"index.m3u8\");\r\n    return (StringUtil.substitute(\"{0}?token1={1}&amp;token2={2}&amp;expire1={3}&amp;expire2={4}\", mp4Url, token1, token2, expire1.toString(), expire2.toString()));\r\n}\r\n\r\nprivate function toSecTimeStr(timeMillis:Number):String{\r\n    var secs:Number = int((timeMillis \/ 1000));\r\n    return (secs.toString());\r\n}\r\n\r\nprivate function buildToken(path:String, expire:String, ip:String, key:String):String{\r\n    var sec:String = (((path + expire) + ip) + key);\r\n    var bytes:ByteArray = new ByteArray();\r\n    bytes.writeUTFBytes(sec);\r\n    var md5:MD5 = new MD5();\r\n    var hash:ByteArray = md5.hash(bytes);\r\n    var token:String = Base64.encodeByteArray(hash);\r\n    var pat1:RegExp = \/\\+\/gi;\r\n    var pat2:RegExp = \/\\\/\/gi;\r\n    var pat3:RegExp = \/=\/gi;\r\n    token = token.replace(pat1, \"-\").replace(pat2, \"_\").replace(pat3, \"\");\r\n    return (token);\r\n}\r\n<\/pre>\n<p>\u57fa\u672c\u4e0a\u548c python \u67b6\u69cb\u662f\u4e00\u6a23\u7684\uff0c\u53ea\u662f\u53cd\u7d44\u8b6f\u6709\u5c11\u6771\u897f\uff0c\u6700\u95dc\u9375\u7684 KEYS \u6c92\u6709\u89e3\u958b\uff0c\u53ea\u597d\u56de\u982d\u7e7c\u7e8c\u7814\u7a76 python<\/p>\n<p>\u5f8c\u4f86\u8b49\u5be6 python \u6709\u95dc token \u7684\u6f14\u7b97\u6cd5\u662f\u6b63\u78ba\u7684<\/p>\n<p>--<\/p>\n<h2>Token \u6f14\u7b97\u6cd5<\/h2>\n<p>token1 \u5b57\u4e32\u7d44\u6210<\/p>\n<pre class=\"lang:default decode:true \">path + expire timestamp + IP + Key + 1<\/pre>\n<p>token2 \u5b57\u4e32\u7d44\u6210<\/p>\n<pre class=\"lang:default decode:true\">path + expire timestamp + IP + Key + 2<\/pre>\n<p>token1 \u7bc4\u4f8b\uff0ctoken2 \u53ea\u8981\u5c07\u6700\u5f8c\u7684 1 \u6539\u6210 2 \u5373\u53ef<\/p>\n<pre class=\"lang:default decode:true\">\/live\/pool\/hich-ra000073\/ra-hls\/146295177759.125.207.208radio@himediaservice#t1<\/pre>\n<p>\u7136\u5f8c\u62ff\u53bb md5() \u518d\u8dd1\u00a0base64_encode() \u5c31\u53ef\u4ee5\u5f97\u5230 Token \u4e86<\/p>\n<p>--<\/p>\n<p>index.m3u8 \u5167\u5bb9<\/p>\n<pre class=\"lang:default decode:true\">http:\/\/radio-hichannel.cdn.hinet.net\/live\/pool\/hich-ra000036\/ra-hls\/index.m3u8?token1=IKGH3KBN_Fy5_mAvsgaibQ&amp;token2=Af9RZuEDZ_yK9TIBmIuFTw&amp;expire1=1462943429&amp;expire2=1462972229\r\n\r\n#EXTM3U\r\n#EXT-X-VERSION:3\r\n#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=135680,CODECS=\"avc1.100.30,mp4a.40.2\",RESOLUTION=362x242\r\nhich-ra000036-video=0-audio=128000.m3u8?token1=IKGH3KBN_Fy5_mAvsgaibQ&amp;token2=Af9RZuEDZ_yK9TIBmIuFTw&amp;expire1=1462943429&amp;expire2=1462972229\r\n<\/pre>\n<p>--<\/p>\n<h2>PHP \u7a0b\u5f0f\u78bc<\/h2>\n<pre class=\"lang:php decode:true\">&lt;?php\r\nheader(\"Content-Type: text\/html; charset=utf-8\");\r\ndate_default_timezone_set(\"Asia\/Taipei\");\r\nset_time_limit(0);\r\nini_set('error_reporting',E_ALL &amp; ~E_NOTICE &amp; ~E_STRICT &amp; ~E_DEPRECATED);\r\n\r\nfunction gen_token( $path, $timestamp, $ip_addr, $token_ord ) {\r\n    $const_str = 'radio@himediaservice#t';\r\n    $cat_str = $path . $timestamp . $ip_addr . $const_str . $token_ord;\r\n    $hashed = md5($cat_str, true);\r\n    $b64_md5hash = base64_encode($hashed);\r\n    return str_replace( '=', '', str_replace( '\/', '_', str_replace( '+', '-', $b64_md5hash)));\r\n}\r\n\r\n$path = '\/live\/pool\/hich-ra000018\/ra-hls\/';\r\n$expire1 = time()+ (60 * 60 * 2);\r\n\/\/$expire1 = 1462951777;\r\n$expire2 = $expire1 + (60 * 60 * 12);\r\n\/\/$expire2 = 1462980577;\r\n$ip = $_SERVER['REMOTE_ADDR']; \/\/ \u57f7\u884c\u74b0\u5883\u5c0d\u5916\u7684 IP\r\n\r\n$token1 = gen_token($path, $expire1, $ip, 1);\r\n$token2 = gen_token($path, $expire2, $ip, 2);\r\n\r\n\/\/ $m3u8 \u5c31\u662f\u64ad\u653e\u8def\u5f91\r\n$m3u8 = 'http:\/\/radio-hichannel.cdn.hinet.net\/live\/pool\/hich-ra000018\/ra-hls\/index.m3u8?token1='. $token1 .'&amp;token2=' . $token2 . '&amp;expire1='. $expire1 .'&amp;expire2='. $expire2;\r\n\/\/echo $m3u8;\r\n\r\n$Filename = date('YmdHi00');\r\nexec('\/usr\/bin\/ffmpeg -i \"'. $m3u8 .'\" -t 01:00:00 \/tmp\/mp3\/'. $Filename .'.mp3 &amp;');<\/pre>\n<p>--<\/p>\n<h2>\u00a0\u66f4\u65b0<\/h2>\n<ul>\n<li>2019-02-20 \u7db2\u5740\u6539\u70ba https:\/\/ \u4ee5\u53ca\u53c8\u6539\u70ba index.m3u8 \u7684\u6a94\u540d<\/li>\n<li style=\"font-style: normal;\">2018-06-29 \u6700\u5f8c m3u8 \u7522\u51fa\u6642\uff0c index.m3u8 \u6a94\u6848\u540d\u7a31\u5fc5\u9808\u6539\u6210\u00a0ra-hls\/hich-ra000073-audio_track=128000.m3u8 \u9019\u7a2e\u683c\u5f0f\u7684\u6a94\u6848\u540d\u7a31<\/li>\n<\/ul>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"3031\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;10,489&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>2020\/8\/11 \u505c\u6b62\u7dad\u8b77 ...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"3031\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;10,489&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[260],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3031"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3031"}],"version-history":[{"count":17,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3031\/revisions"}],"predecessor-version":[{"id":7301,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3031\/revisions\/7301"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}