|
|
本帖最后由 aming.ou 于 2023-12-22 18:52 编辑
自从电视家等直播软件被停服后,在山里大神的指导下,
学会了找直播软件,我用 DIYP影音Final版,
学会了制作频道接口,给DIYP提供直播源txt,
学会了获取xml格式的epg数据转存sqlite数据库,留作本地化 diyp epg源数据
学会了制作节目接口,给DIYP提供节目单epg,在epg加持下,实现了回放
成长历程,
1 电视直播APP还是DIYP影音最纯净 https://www.right.com.cn/forum/thread-8313390-1-1.html
2 自定义视频直播源,一键搭建PHP服务器=实现无限可能 https://www.right.com.cn/forum/thread-8313609-1-1.html
3 DIYP的EPG接口真的很耗服务器资源,求解 https://www.right.com.cn/forum/thread-8314154-1-1.html
以下是xml格式epg转存sqlite数据库 的php源码,欢迎技术讨论
食用方法,放到 2 php服务器的htdocs目录下, 访问 http://127.0.0.1/xml2db.php (每天访问一次就可以了)
核心代码:
- <?php
- // xml2db.php
- // 1 保存全量节目单, 0 仅保存list中频道相关的节目单
- $save_all = 1;
- $displayname = 'display-name';
- $n = 0;
- $start = microtime(true);
- class ChannelDB extends SQLite3
- {
- function __construct()
- {
- $isnew = 1;
- $f = 'channel_epg.db';
- if (file_exists($f))
- {
- $isnew = 0;
- }
- $this->open($f);
- if ($isnew > 0)
- {
- // 初始化数据库
- $this->exec("CREATE TABLE if not exists 'list' (item text, title text, epg text, url text,'isdel' integer,constraint name_pk primary key (item,title))");
- $this->exec("CREATE TABLE if not exists 'access_log' (ip_address text, access_time text,url text)");
- $this->exec("CREATE TABLE if not exists 'epg_channel' ( `name` text, `channel_id` text,constraint name_pk primary key (name))");
- $this->exec("CREATE TABLE if not exists 'epg_programme' ( `title` text, `sdate` text, `sstart` text, `sstop` text, `channel` text, `sdesc` text, 'inserttime' text,constraint name_pk primary key (channel,sdate,sstart))");
- $this->exec("CREATE TABLE if not exists 'tmp_epg_channel' ( `name` text, `channel_id` text)");
- $this->exec("CREATE TABLE if not exists 'tmp_epg_programme' ( `title` text, `sdate` text, `sstart` text, `sstop` text, `channel` text, `sdesc` text, 'inserttime' text)");
- // 初始化频道表样例数据
- $this->exec("INSERT INTO `list` (`item`,`title`,`epg`,`url`,`isdel`) VALUES ('广东频道','广州综合','','http://nas.jdshipin.com:8801/gztv.php?id=zhonghe','90');");
- $this->exec("INSERT INTO `list` (`item`,`title`,`epg`,`url`,`isdel`) VALUES ('广东频道','广州新闻','','http://nas.jdshipin.com:8801/gztv.php?id=xinwen#http://113.100.193.10:9901/tsfile/live/1000_1.m3u8','90');");
- $this->exec("INSERT INTO `list` (`item`,`title`,`epg`,`url`,`isdel`) VALUES ('央视频道','CCTV2','','http://dbiptv.sn.chinamobile.com/PLTV/88888893/224/3221226195/index.m3u8?0.smil','120');");
- }
- }
- }
- // 连接数据库
- $config = array();
- $channel = new ChannelDB();
- // 分析xml数据
- function getContent($url, $username, $password)
- {
- $process = curl_init($url);
- // curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
- curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
- $data = curl_exec($process);
- curl_close($process);
- return $data;
- }
- // 清空临时表
- $result = $channel->query("delete from tmp_epg_channel");
- $result = $channel->query("delete from tmp_epg_programme");
- // 节目总表地址
- $data = getContent("http://epg.51zmt.top:8000/e.xml");
- $xml = simplexml_load_string($data);
- // 开始事务处理
- $channel->exec("BEGIN TRANSACTION;");
- foreach ($xml->children() as $xmldata)
- {
- if ($xmldata->getName() == "channel")
- {
- $result = $channel->query("INSERT INTO tmp_epg_channel(name,channel_id) VALUES ('" . $xmldata->$displayname . "','" . $xmldata->attributes()->id . "')");
- if (!$result)
- {
- echo $n . ' - ' . $channel->lastErrorMsg() . '<br>';
- }
- }
- if ($xmldata->getName() == "programme")
- {
- $start_time = substr($xmldata->attributes()->start, 8, 2) . ":" . substr($xmldata->attributes()->start, 10, 2);
- $stop_time = substr($xmldata->attributes()->stop, 8, 2) . ":" . substr($xmldata->attributes()->stop, 10, 2);
- $jm_date = substr($xmldata->attributes()->stop, 0, 4) . "-" . substr($xmldata->attributes()->stop, 4, 2) . "-" . substr($xmldata->attributes()->stop, 6, 2);
- $n ++ ;
- $result = $channel->query("INSERT INTO tmp_epg_programme(channel,sdate,sstart,sstop,title,sdesc,inserttime) VALUES ('" . $xmldata->attributes()->channel . "','" . $jm_date . "','" . $start_time . "','" . $stop_time . "','" . $xmldata->title . "','','" . $time . "')");
- if (!$result)
- {
- echo $n . ' = ' . $channel->lastErrorMsg() . '<br>';
- }
- }
- }
- // 更新节目数据
- ……
- // 写入硬盘
- $channel->exec("COMMIT;");
- ?>
复制代码 完整代码:
(推荐完整版)12月22日更新,自建DIYP影音和TVBOX的接口PHP服务 https://www.right.com.cn/FORUM/thread-8315423-1-1.html
先浏览器打开 xml2db.php 进行数据库和epg数据初始化
再浏览器打开 channel.php 进行频道直播源维护
diyp影音epg接口填入 http://[php服务器地址]/epg.php 自动获取节目列表
不会搭建php服务器的,可以用这个接口【DIYP影音】 用这个 https://epg.erw.cc/api/diyp/
帖子来源 https://www.right.com.cn/FORUM/thread-8301810-1-1.html
发帖注意事项
请勿胡乱发帖:https://www.right.com.cn/forum/thread-8307840-1-1.html
账户手机验证:https://www.right.com.cn/forum/home.php?mod=spacecp&ac=plugin&id=jzsjiale_sms:home
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
评分
-
查看全部评分
|