From ff8610569a631c3b8a32622df7d04c18ffe23784 Mon Sep 17 00:00:00 2001 From: flysaki15 Date: Tue, 15 Aug 2023 20:43:18 +0900 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E9=80=A0v0.01=EF=BC=9A=E6=94=BE?= =?UTF-8?q?=E9=80=81=E4=B8=AD=E7=95=AA=E7=B5=84=E3=81=AE=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E5=8F=96=E5=BE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/api/epginfo.php | 61 +++++++++++++++++------------- htdocs/api/epginfo_tvmaid_maya.php | 35 +++++++++++++++++ 2 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 htdocs/api/epginfo_tvmaid_maya.php diff --git a/htdocs/api/epginfo.php b/htdocs/api/epginfo.php index 149019a..11587d5 100644 --- a/htdocs/api/epginfo.php +++ b/htdocs/api/epginfo.php @@ -7,6 +7,7 @@ require_once ('classloader.php'); require_once ('require.php'); require_once ('module.php'); + require_once ('epginfo_tvmaid_maya.php'); // BonDriverとチャンネルを取得 list($BonDriver_dll, $BonDriver_dll_T, $BonDriver_dll_S, // BonDriver @@ -52,33 +53,45 @@ function getEpgInfo($ch, $chnum, $sid, $onid, $tsid){ // ----------------------------------- - if (!empty($EDCB_http_url)){ + // チャンネル名 + $channel_name = $ch[$chnum]; - // 番組表 API - @$epg = simplexml_load_file($EDCB_http_url.'api/EnumEventInfo?onair=&onid='.$onid.'&sid='.$sid.'&tsid='.$tsid); + // 番組情報の取得 + $pgFound = (function() use($channel_name) { + $epg = MayaEpg::getEpgData(); + $pgFoundArr = array_filter($epg, function ($pg) use ($channel_name) { + return $pg['name'] === $channel_name; + }); - // チャンネル名 - if (isset($epg->items->eventinfo[0]->service_name)){ - $channel = mb_convert_kana(strval($epg->items->eventinfo[0]->service_name), 'asv'); - } else { - $channel = 'チャンネル名を取得できませんでした'; + if(!count($pgFoundArr)){ + return null; } + return current($pgFoundArr); + })(); + + + if ($pgFound){ +//print_r($pgFound); + $epg = null; + // チャンネル名 + $channel = $channel_name; + $program_name = $pgFound['title'] ?: ''; + + + // 開始/終了時間の解析 + $starttimestamp = MayaEpg::getTimeFromMayaTime($pgFound['start']); //タイムスタンプに変換 + $duration = $pgFound['duration']; + $endtimestamp = MayaEpg::getTimeFromMayaTime($pgFound['end']); // 秒数を足す + // 表示用 + $starttime = date("H:i", $starttimestamp); + $endtime = date("H:i", $endtimestamp); + // 現在の番組 - if (isset($epg->items->eventinfo[0]->startTime)){ - $starttime = $epg->items->eventinfo[0]->startDate.' '.$epg->items->eventinfo[0]->startTime; - } else { - $starttime = date('Y/m/d').'00:00:00'; - } - if (isset($epg->items->eventinfo[0]->duration)){ - $duration = $epg->items->eventinfo[0]->duration; - } else { - $duration = '0000'; - } - if (isset($epg->items->eventinfo[0]->event_name)){ + if ($program_name){ //文字列に変換してさらに半角に変換して改行をbrにする - $program_name = str_replace("\n", "
\n", mb_convert_kana(strval($epg->items->eventinfo[0]->event_name), 'asv')); - } else { + $program_name = str_replace("\n", "
\n", mb_convert_kana(strval($program_name), 'asv')); + } else { // TODO: 放送休止対応、次の番組対応 (23/08/15) if (isset($epg->items->eventinfo[0]->service_name)){ $program_name = '放送休止'; } else { @@ -128,12 +141,6 @@ function getEpgInfo($ch, $chnum, $sid, $onid, $tsid){ } } - // 開始/終了時間の解析 - $starttimestamp = strtotime($starttime); //タイムスタンプに変換 - $endtimestamp = $starttimestamp + $duration; // 秒数を足す - $starttime = date("H:i", $starttimestamp); - $endtime = date("H:i", $endtimestamp); - // 次の番組の開始/終了時間の解析 $next_starttimestamp = strtotime($next_starttime); //タイムスタンプに変換 $next_endtimestamp = $next_starttimestamp + $next_duration; // 秒数を足す diff --git a/htdocs/api/epginfo_tvmaid_maya.php b/htdocs/api/epginfo_tvmaid_maya.php new file mode 100644 index 0000000..385f364 --- /dev/null +++ b/htdocs/api/epginfo_tvmaid_maya.php @@ -0,0 +1,35 @@ +prepare("select service.fsid, name, title, desc, start, end, duration from service + left join ( + select id, fsid, title, desc, start, end, duration from event + where start < ? and end > ?) + as _event on service.fsid = _event.fsid + where driver = (select driver from tuner where name = 'siano') order by service.id" + ); + $stmt->execute([$sqlTimeStampStr, $sqlTimeStampStr]); + return $stmt->fetchAll(PDO::FETCH_ASSOC); + } + + static function fetchEpgData(){ + self::$data = self::getEpgDataFromMayaDb(); + } + + public static function getEpgData(){ + if(!self::$data){ + self::fetchEpgData(); + } + + return self::$data; + } + + public static function getTimeFromMayaTime($mayaTime){ + return intval($mayaTime) / 10000000 - 62135629200; + } +}