找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 3489|回复: 38

[iptv信源 资源分享或寻求] 大同电视台PHP疑问~~~

[复制链接]
35 币恩山币 回复本帖可获得 1 币恩山币奖励! 每人限 1 次(中奖概率 50%)
发表于 2022-7-3 19:06 | 显示全部楼层 |阅读模式
本帖最后由 jiteloozz 于 2022-7-4 00:05 编辑

首先上代码:

  1. <?php
  2. header('Content-Type: text/json;charset=UTF-8');
  3. $id = isset($_GET['id'])?$_GET['id']:'ggpd';
  4. $mn= array(
  5.   'xwzh' => 16,//大同新闻综合
  6.   'ggpd' => 8,//大同公共
  7.   'mdsh' => 9,//大同煤都生活
  8.   'jtgb' => 14,//交通可视化广播
  9.   'xwzhgb' => 13,//新闻综合可视化广播
  10.   'jjwygb' => 15,//经济文艺可视化广播
  11. );
  12. switch(date('i')%3){
  13.    case 0:
  14.     $data=get_data('http://mapi.dtradio.com.cn/api/v1/program.php?channel_id='.$mn[$id]);
  15.     preg_match('/(.*?)playlist.m3u8?(.*?)"/',$data,$str);
  16.     $live=stripslashes(substr($str[1],strrpos($str[1],"http")));
  17.     $playurl = $live.'playlist.m3u8'.$str[2];
  18.    break;
  19.    case 1:
  20.     $data=get_data('http://mapi.dtradio.com.cn/api/v1/channel.php?category_id=0&channel_id='.$mn[$id]);
  21.     $playurl=json_decode($data)[0]->m3u8;
  22.    break;
  23.    default:
  24.     $data=get_data('http://mapi.dtradio.com.cn/api/v1/channel.php?category_id=1%2C3');
  25.     foreach(json_decode($data) as $sv){
  26.       if($sv->id==$mn[$id]){
  27.       $playurl= $sv->m3u8;
  28.       }
  29.     }
  30.    break;  
  31. }
  32. if(!$live){
  33. $live=strstr($playurl,'playlist.m3u8',true);
  34. }
  35. $refurl=preg_replace('/(.*?m3u8)/',"$live$1",get_data($playurl));
  36. $playurl=strstr($refurl,'http');
  37. //print_r(get_data($playurl));//获取不到TS数据
  38. header('Location:'.$playurl);
  39. function get_data($url){
  40. $header=array(
  41.              "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:50.0) Gecko/20100101 Firefox/50.0",
  42.              "Referer: https://www.dtradio.com.cn/local/folder25",
  43.              );   
  44. $ch = curl_init();
  45. curl_setopt($ch, CURLOPT_URL, $url);
  46. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  47. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  48. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  49. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  50. $data = curl_exec($ch);
  51. curl_close($ch);
  52. return $data;
  53. }
复制代码

向大神请教求解问题一:

pc端POT、手机端浏览器都能正常运行PHP并播放电视和广播;但是奇怪的是PC端黑鸟播放器、Blank播放器都只能播放广播,不能播放电视。。。Why?
向大神请教求解问题二:
尝试获取TS来解决问题一,但突然悲催的发现,尝试了多种方法,curl和file_get_contents()都获取不到ts数据,是不是代码还缺少特定请求?
print_r(get_data($playurl));     //问题:curl不到ts数据
貌似第一次遇上这种情况,特向大神请教求解,Thanks~~~


后记:问题二已解决
37句获取不到数据,是因为36句有个坑。
36句,37句,38句替换成

$playurl=trim(strstr($refurl,'http'));
$host='https://'.parse_url($playurl)[host];
print_r(preg_replace('/(..\/..\/)/',"$host/",get_data($playurl)));


问题二一解决,问题一就不是事了!!!
修正后代码,回复可见:
测试地址:http://mmitv.top/other/dttv.php?id=jtksh
  1. <?php
  2. header('Content-Type: text/json;charset=UTF-8');
  3. $id = isset($_GET['id'])?$_GET['id']:'jtksh';
  4. $mn= array(
  5.   'xwzh' => 16,   //大同新闻综合
  6.   'ggpd' => 8,    //大同公共
  7.   'mdsh' => 9,    //大同煤都生活
  8.   'jtksh' => 14,  //交通可视化广播
  9.   'xwksh' => 13,  //新闻综合可视化广播,大多数处于未播黑屏状态
  10.   'jjksh' => 15,  //经济文艺可视化广播,大多数处于未播黑屏状态
  11.   'jtgb'  => 12,  //大同交通广播
  12.   'xwgb'  => 10,  //大同新闻广播
  13.   'jjgb'  => 11,  //大同经济广播
  14. );
  15. switch(intval(date('s')/20)){
  16.    case 0://接口一
  17.     $data=get_data('http://mapi.dtradio.com.cn/api/v1/program.php?channel_id='.$mn[$id]);
  18.     preg_match('/(.*?)playlist.m3u8?(.*?)"/',$data,$str);
  19.     $live=stripslashes(substr($str[1],strrpos($str[1],"http")));
  20.     $playurl = $live.'playlist.m3u8'.$str[2];
  21.    break;
  22.    case 1://接口二,推荐
  23.     $data=get_data('http://mapi.dtradio.com.cn/api/v1/channel.php?category_id=0&channel_id='.$mn[$id]);
  24.     $playurl=json_decode($data)[0]->m3u8;
  25.    break;
  26.    default://接口三
  27.     $data=get_data('http://mapi.dtradio.com.cn/api/v1/channel.php?category_id=1%2C2%2C3');
  28.     foreach(json_decode($data) as $sv){
  29.       if($sv->id==$mn[$id]){
  30.       $playurl= $sv->m3u8;
  31.       }
  32.     }
  33.    break;  
  34. }
  35. if($mn[$id]>12&&$mn[$id]<16){
  36. header('Location:'.$playurl);
  37. exit;
  38. }else{
  39. //用截取方法会踩坑,会忽略字符串中的\n等字符;     //用preg_match('/\w*(.*?)$/')方式获取302地址不会踩坑。
  40. preg_match('/\w*(.*?)$/', get_data($playurl), $site);
  41. $playurl=preg_split('/playlist.m3u8/',$playurl)[0].$site[0];
  42. $host=parse_url($playurl)['host'];
  43. print_r(preg_replace('/(..\/..\/)/',"http://$host/",get_data($playurl)));
  44. exit;
  45. }
  46. function get_data($url){
  47. $header=array(
  48.              "User-Agent: Mozilla/5.0",
  49.              "Referer: https://www.dtradio.com.cn/local/folder25",            
  50.              );   
  51. $ch = curl_init();
  52. curl_setopt($ch, CURLOPT_URL, $url);
  53. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  54. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  55. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  56. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  57. $data = curl_exec($ch);
  58. curl_close($ch);
  59. return $data;
  60. }
复制代码


我的恩山、我的无线 The best wifi forum is right here.
发表于 2022-7-3 20:14 | 显示全部楼层

回帖奖励 +1 币恩山币

中奖概率 (50%)不错
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 20:21 | 显示全部楼层

回帖奖励 +1 币恩山币

先回复看看
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 20:29 | 显示全部楼层

回帖奖励 +1 币恩山币

黑鸟不能处理以../../打头这种ts.所以转换一下就可以了。

点评

感谢回复~~~  详情 回复 发表于 2022-7-3 20:54
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2022-7-3 20:30 | 显示全部楼层
问题二,已解决~~~
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2022-7-3 20:54 | 显示全部楼层
本帖最后由 jiteloozz 于 2022-7-3 20:55 编辑
opig 发表于 2022-7-3 20:29
黑鸟不能处理以../../打头这种ts.所以转换一下就可以了。

感谢回复~~~广播的ts也是../../打头的呢
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 20:58 | 显示全部楼层
本帖最后由 opig 于 2022-7-3 21:25 编辑

后面两个官站就黑屏。害得我查半天。../..不解析就是迅雷aplayer的问题吧,黑鸟和blank都是用它。
  1. <?php
  2. error_reporting(0);
  3. header('Content-Type: text/json;charset=UTF-8');
  4. $id = isset($_GET['id'])?$_GET['id']:1;
  5. $r = 'https://www.dtradio.com.cn/';
  6. $ids = array(
  7.     "1"  =>"16",  //大同新闻综合
  8.     "2"  =>"8",  //大同公共
  9.     "3"  =>"9",  //大同媒都生活
  10.     "4"  =>"14",  //大同交通广播
  11.     "5"  =>"13",  //大同新闻广播
  12.     "6"  =>"15",  //大同经济广播
  13. );
  14. if (empty($ids[$id])) { $id = 1;}

  15. $apiurl = "http://mapi.dtradio.com.cn/api/v1/channel.php?channel_id=$ids[$id]";
  16. $playurl = json_decode(file_get_contents($apiurl))[0]->channel_stream[0]->m3u8;
  17. preg_match('/\w*(.*?)$/', m3u8($playurl,$r), $m);
  18. $live = (preg_split("/playlist.m3u8/",$playurl))[0].$m[0];
  19. $site = parse_url($live)[host];
  20. echo str_replace("../../","http://$site/",m3u8($live,$r));

  21. function m3u8($url,$ref){
  22.     $ch = curl_init();
  23.     curl_setopt($ch, CURLOPT_URL, $url);
  24.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  25.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  26.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  27.     curl_setopt($ch, CURLOPT_REFERER, $ref);
  28.     $result = curl_exec($ch);
  29.     curl_close($ch);
  30.     return $result;
  31. }
  32. ?>
复制代码


点评

哈哈,居然发现我的PHP5.6服务器还不能解析19句; $live = (preg_split("/playlist.m3u8/",$playurl))[0].$m[0]; 要这样才行 $live = preg_split("/playlist.m3u8/",$playurl)[0].$m[0];  详情 回复 发表于 2022-7-3 22:46
大同台没有referer验证.  详情 回复 发表于 2022-7-3 21:27
嗯,18句用了preg_match('/\w*(.*?)$/',m3u8($playurl,$r), $m);就不会遇坑。 学习了~~~  详情 回复 发表于 2022-7-3 21:12
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 21:08 | 显示全部楼层

回帖奖励 +1 币恩山币


先回复看看
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2022-7-3 21:12 | 显示全部楼层
opig 发表于 2022-7-3 20:58
后面两个官站就黑屏。害得我查半天。../..不解析就是讯雷aplayer的问题吧。

嗯,18句用了preg_match('/\w*(.*?)$/',m3u8($playurl,$r), $m);就不会遇坑。

学习了~~~

点评

你回复我才发现,我打错别字$h了。不过反正不用refer也行。不影响使用。  详情 回复 发表于 2022-7-3 21:19
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 21:19 | 显示全部楼层
jiteloozz 发表于 2022-7-3 21:12
嗯,18句用了preg_match('/\w*(.*?)$/',m3u8($playurl,$r), $m);就不会遇坑。

学习了~~~

你回复我才发现,我打错别字$h了。不过反正不用refer也行。不影响使用。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 21:27 | 显示全部楼层
本帖最后由 guoma 于 2022-7-3 21:37 编辑
opig 发表于 2022-7-3 20:58
后面两个官站就黑屏。害得我查半天。../..不解析就是迅雷aplayer的问题吧,黑鸟和blank都是用它。

大同台没有referer验证.
  1. <?php
  2. $id = isset($_GET['id'])?$_GET['id']:'dtxwzh';
  3. $n = array(
  4.   'dtxwzh' => 16,//大同新闻综合
  5.   'dtgg' => 8,//大同公共
  6.   'dtmdsh' => 9,//大同煤都生活
  7.   'dtjtksh'  => 14,  //大同交通可视化广播
  8.   'dtjtgb'  => 12,  //大同交通广播
  9.   'dtxwgb'  => 10,  //大同新闻广播
  10.   'dtjjgb'  => 11,  //大同经济广播
  11. );
  12. $d = file_get_contents('http://mapi.dtradio.com.cn/api/v1/channel.php?channel_id='.$n[$id]);
  13. $playurl = json_decode($d)[0] -> m3u8;
  14. header('Location:'.$playurl);
  15. //echo $playurl;
  16. ?>
复制代码
新闻可视化广播/经济可视化广播貌视无效.


点评

老大,交通可视化广播ID变了,求新的ID。谢谢!!!  详情 回复 发表于 2023-2-4 21:34
求索纪录4K 239.253.2.153:8902  详情 回复 发表于 2022-7-9 02:12
很简洁的代码了。 用file_get_contents某些服务器解析没有用curl快。个人偏向于用curl。 这种直接输出,黑鸟播放器是播放不了的,有局限性性吧。所以做了ts输出。  详情 回复 发表于 2022-7-3 21:38
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 21:37 | 显示全部楼层
我是来混bi的, 看大佬表演
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 21:37 | 显示全部楼层

回帖奖励 +1 币恩山币

没混成功。////
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2022-7-3 21:38 | 显示全部楼层
guoma 发表于 2022-7-3 21:27
大同台没有referer验证.

很简洁的代码了。
用file_get_contents某些服务器解析没有用curl快。个人偏向于用curl。
这种直接输出,黑鸟播放器是播放不了的,有局限性性吧。所以做了ts输出。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2022-7-3 21:55 | 显示全部楼层
路过看看
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-23 15:11

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表