找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 6811|回复: 18

php源码:抓取tianmaotv数据生成xmltv格式的epg

[复制链接]
发表于 2020-4-26 16:13 | 显示全部楼层 |阅读模式
51zmt上的epg没有提供大部分省市地方台的epg,于是想抓取epg网站比如tianmaotv.cn上的节目表,生成xmltv格式,给perfect player、GoIPTV等使用。
php文件生成并储存在梅林系统的路由器上,用crontab设置每天凌晨自动抓取生成当天节目的xml文件:
# crontab -e 编辑
输入

30 0 * * * /.../php-cgi xxx.php
保存

# crontab -l 可以查看到建好的计划任务。


以下是源码,大家可以根据自己的需求添加修改频道名称,或者参考编写适合其他epg网站的代码。
默认存在php默认根路径的hn_tmtv.xml,大家可以自行修改。


<?php
$cid=array(
array('1182','湖南都市'),
array('1181','湖南经视'),
array('1434','湖南公共'),
array('1432','湖南娱乐'),
array('1433','湖南电视剧'),
array('1571','湖南电影'),
array('2307','湖南国际'),
array('1674','湖南教育'),
    );
function compress_html($string) {
$string = str_replace("\r", '', $string);
$string = str_replace("\n", '', $string);
$string = str_replace("\t", '', $string);
$string = str_replace(" ", '', $string);
$string = str_replace("&nbsp;&nbsp",'',$string);
return $string;
}
$dt=date('Y',time()+8*3600);
$w=date("w",time()+8*3600);
if ($w<'1') {$w=7;}
$w="_w".$w."/";
$url0="https://www.tianmaotv.cn/jmb";
$xmlhd="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE tv SYSTEM \"http://api.torrent-tv.ru/xmltv.dtd\">\n<tv generator-info-name=\"tianmaotv\" generator-info-url=\"www.tianmaotv.cn\">\n";
$myfile = fopen("hn_tmtv.xml", "w") or die("Unable to open file!");
fwrite($myfile, $xmlhd);
$nid=sizeof($cid);
for ($id = 1; $id <= $nid; $id++) {
$url=$url0."/".$cid[$id-1][0].$w;
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,60);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$re = curl_exec($ch);
curl_close($ch);
$re=compress_html($re);
$t0=array();
$t1=array();
$nm=array();
preg_match('|div_programList">(.*?)</div></dl>|',$re,$u);
preg_match_all('|<time>([\s\S]+?)</time>|i',$u[1], $t0);
preg_match_all('|</time>([\s\S]+?);|i',$u[1], $nm);
$t0=$t0[1];
$nm=$nm[1];
$num=sizeof($t0);
for ($i = 0; $i < $num; $i++) {
    $tmp=str_replace(":","",$t0[$i]);
    $t0[$i]=$dt.str_replace("-","",$tmp).'00 +0800';}
for ($i = 1; $i < $num; $i++) {$t1[]=$t0[$i];}
$t1[]=$dt.'235959 +0800';
$idc=$id+10000;
$chn="<channel id=\"".$idc."\"><display-name lang=\"zh\">".$cid[$id-1][1]."</display-name></channel>\n";
for ($i = 0; $i < $num; $i++) {
$chn=$chn."<programme start=\"".$t0[$i]."\" stop=\"".$t1[$i]."\" channel=\"".$idc."\">\n<title lang=\"zh\">".$nm[$i]."</title>\n<desc lang=\"zh\"> </desc>\n</programme>\n";}
fwrite($myfile, $chn);
}
fwrite($myfile, "</tv>\n");
fclose($myfile);
?>

想抓取明后天节目表的可以自行添加类似代码。


评分

参与人数 1恩山币 +1 收起 理由
山凝黛迪 + 1 感谢你的分享,无论怎样,你都是最无私的人!来,说说,你E盘上还有啥一起给我吧!

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
发表于 2020-4-26 19:26 | 显示全部楼层
感谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-4-26 19:33 | 显示全部楼层
还是不太明白
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-4-26 19:42 | 显示全部楼层
深度好文!学习了!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-4-26 19:43 | 显示全部楼层
虽然不会,还是支持技术分享贴
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-4-26 22:03 | 显示全部楼层
谢谢分享,小白不太懂
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-7-22 17:18 | 显示全部楼层
兄弟,请问如何修改成今明后天呢?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-11 16:52 | 显示全部楼层
需要tianmaotv.cn的节目数据可以找我,我可以提供站长工具,包含所有频道数据。

点评

我想要频道数据,可以吗  详情 回复 发表于 2021-4-21 15:05
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-11 17:27 | 显示全部楼层
好难啊,看不太明白
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-13 12:24 | 显示全部楼层
楼主,请教如何生成DIYP可用的EPG?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-16 16:54 | 显示全部楼层
求楼主写tvsou的,两天记录,然后压缩文件的
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-18 18:36 | 显示全部楼层
ubuntu下怎么用
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-21 19:44 | 显示全部楼层
我服务器地址给你远程,能否帮我写个爬虫脚本,想爬电视猫的。51zmt没有我本地频道  95346618  QQ
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-22 08:39 | 显示全部楼层

楼主,请教如何生成DIYP可用的EPG?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2020-8-29 22:13 | 显示全部楼层
大佬你好 天猫tv直接访问/jmd,会显示403没权限所以请问有tvsou的php文件吗
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-24 16:43

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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

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