云南省台代理源码
云南卫视,http://cn.sohu.blog/yntv.php?id=yunnanweishi云南都市,http://cn.sohu.blog/yntv.php?id=yunnandushi云南娱乐,http://cn.sohu.blog/yntv.php?id=yunnanyule康旅频道,http://cn.sohu.blog/yntv.php?id=yunnangonggong澜湄国际,http://cn.sohu.blog/yntv.php?id=yunnanguoji云南少儿,http://cn.sohu.blog/yntv.php?id=yunnanshaoer
<?php/*云南卫视,yntv.php?id=yunnanweishi云南都市,yntv.php?id=yunnandushi云南娱乐,yntv.php?id=yunnanyule康旅频道,yntv.php?id=yunnangonggong澜湄国际,yntv.php?id=yunnanguoji云南少儿,yntv.php?id=yunnanshaoer*/if(need_m3u8($id, $ts_url)) {$u = get_m3u8_url($id);$c = send_request($u, $ct, $u);$c = replace_ts_urls($u, $c);} else {$c = send_request($ts_url, $ct);}echo_content($ct, $c);functionneed_m3u8(&$id, &$ts_url){$q = $_SERVER['QUERY_STRING'];$r = stripos($q, 'id=') === 0;if($r)$id = $_GET['id'];else$ts_url = $q;return $r;}functionget_m3u8_url($id){$r = load_from_cache($id);if($r)return $r;$p = get_m3u8_url_from_web($id);$r = get_actual_m3u8_url($p);save_to_cache($id, $r);return $r;}functionget_m3u8_url_from_web($id) {$u = "https://yntv-api.yntv.cn/index/jmd/getRq?name=$id";$c = send_request($u);$j = json_decode($c);$r = "https://tvlive.yntv.cn{$j->url}?wsSecret={$j->string}&wsTime={$j->time}";return $r;}functionget_actual_m3u8_url($index_m3u8_url) {$c = send_request($index_m3u8_url, $ct, $r);if(stripos($c, '#EXT-X-STREAM-INF:') !== false) {$a = explode("\n", $c);foreach($a as $i) {$i = trim($i);if(strpos($i, '#') !== 0) {if(is_absolute_url($i))$r = $i;else$r = dirname($r)."/".$i;break;}}}return $r;}functionsave_to_cache($id, $url){$a[$id]['expire_time'] = time() + 60 * 60;$a[$id]['url'] = $url;array_to_file($a, 'yntv_cache.txt');}functionload_from_cache($id){file_to_array('yntv_cache.txt', $a);if(isset($a) && isset($a[$id]) && $a[$id]['expire_time'] > time())return $a[$id]['url'];elsereturn '';}functionfile_to_array($filename, &$array) {$array = [];if(file_exists($filename)) {$handle = fopen($filename, 'r');if(flock($handle, LOCK_SH)) { // 共享锁,允许其他进程读但禁止写$data = file_get_contents($filename);$array = unserialize($data);flock($handle, LOCK_UN);}fclose($handle);}return true;}functionarray_to_file($array, $filename) {$data = serialize($array);file_put_contents($filename, $data, LOCK_EX);return true;}functionsend_request($url, &$content_type = null, &$final_url = null){$ch = curl_init($url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);curl_setopt($ch, CURLOPT_REFERER, 'https://www.yntv.cn/');$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36';curl_setopt($ch, CURLOPT_USERAGENT, $ua);$res = curl_exec($ch);if(func_num_args() > 1)$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);if(func_num_args() > 2)$final_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);curl_close($ch);return $res;}functionreplace_ts_urls($m3u8_url, $m3u8_content){$dest_ts_path = dirname($m3u8_url)."/";$protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http';$self_part = "$protocol://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];return preg_replace_callback("/^((?!#).+)$/im",function ($matches) use ($self_part, $dest_ts_path) {if (!is_absolute_url($matches[1]))$ts = $dest_ts_path.$matches[1];else$ts = $matches[1];return "$self_part?$ts";},$m3u8_content);}functionis_absolute_url($url) {return stripos($url, 'http:') === 0 || stripos($url, 'https:') === 0;}functionecho_content($content_type, $content){header("Access-Control-Allow-Origin: *");header("Content-Type: $content_type");echo $content;}
夜雨聆风
