From c6796297cc2379c5278e7e5f4b43ae509f133767 Mon Sep 17 00:00:00 2001 From: wonipapa Date: Fri, 1 Sep 2017 16:58:55 +0900 Subject: [PATCH] Update 1.2.2 --- epg2xml-web.php | 874 +++++++++++++++++++++++++++++------------------- epg2xml.json | 8 +- epg2xml.php | 7 +- epg2xml.py | 1 - 4 files changed, 546 insertions(+), 344 deletions(-) diff --git a/epg2xml-web.php b/epg2xml-web.php index 7e4e514..5715447 100644 --- a/epg2xml-web.php +++ b/epg2xml-web.php @@ -1,10 +1,11 @@ 2 ? 2 : $period; - else : + else : printError("default_fetch_limit는 1, 2, 3, 4, 5, 6, 7만 가능합니다."); exit; endif; @@ -280,18 +281,18 @@ endif; function getEPG() { $fp = $GLOBALS['fp']; $MyISP = $GLOBALS['MyISP']; + $MyChannels = $GLOBALS['MyChannels']; $Channelfile = __DIR__."/Channel.json"; $IconUrl = ""; $ChannelInfos = array(); - try { $f = @file_get_contents($Channelfile); if($f === False) : - printError("Channel.".JSON_FILE_ERROR); + printError("Channel.json.".JSON_FILE_ERROR); exit; else : try { - $Channeldatas = json_decode($f, TRUE); + $Channeldatajson = json_decode($f, TRUE); if(json_last_error() != JSON_ERROR_NONE) throw new Exception("Channel.".JSON_SYNTAX_ERROR); } catch(Exception $e) { @@ -304,13 +305,19 @@ function getEPG() { printError($e->getMessage()); exit; } +//My Channel 정의 + $MyChannelInfo = array(); + if($MyChannels) : + $MyChannelInfo = array_map('trim',explode(',', $MyChannels)); + endif; + header("Content-Type: application/xml; charset=utf-8"); fprintf($fp, "\n"); fprintf($fp, "\n\n"); fprintf($fp, "\n", VERSION); - - foreach ($Channeldatas as $Channeldata) : #Get Channel & Print Channel info - if($Channeldata['Enabled'] == 1) : + + foreach ($Channeldatajson as $Channeldata) : //Get Channel & Print Channel info + if($Channeldata['Enabled'] == 1 || in_array($Channeldata['Id'], $MyChannelInfo)) : $ChannelId = $Channeldata['Id']; $ChannelName = htmlspecialchars($Channeldata['Name'], ENT_XML1); $ChannelSource = $Channeldata['Source']; @@ -365,10 +372,12 @@ function getEPG() { GetEPGFromSKY($ChannelInfo); elseif($ChannelSource == 'NAVER') : GetEPGFromNaver($ChannelInfo); - elseif($ChannelSource == 'TBROAD') : - GetEPGFromTbroad($ChannelInfo); elseif($ChannelSource == 'ISCS') : GetEPGFromIscs($ChannelInfo); + elseif($ChannelSource == 'HCN') : + GetEPGFromHcn($ChannelInfo); + elseif($ChannelSource == 'POOQ') : + GetEPGFromPooq($ChannelInfo); elseif($ChannelSource == 'MBC') : GetEPGFromMbc($ChannelInfo); elseif($ChannelSource == 'MIL'): @@ -377,6 +386,8 @@ function getEPG() { GetEPGFromIfm($ChannelInfo); elseif($ChannelSource == 'KBS'): GetEPGFromKbs($ChannelInfo); + elseif($ChannelSource == 'ARIRANG'): + GetEPGFromArirang($ChannelInfo); endif; endforeach; fprintf($fp, "\n"); @@ -389,11 +400,11 @@ function GetEPGFromEPG($ChannelInfo) { $ServiceId = $ChannelInfo[3]; $epginfo = array(); foreach(range(1, $GLOBALS['period']) as $k) : - $url = "http://www.epg.co.kr/epg-cgi/extern/cnm_guide_type_v070530.cgi"; + $url = "http://211.43.210.10:88/epg-cgi/extern/cnm_guide_type_v070530.php"; $day = date("Ymd", strtotime("+".($k - 1)." days")); $params = array( 'beforegroup' => '100', - 'checkchannel' => $ServiceId, + 'checkchannel[]' => $ServiceId, 'select_group' => '100', 'start_date' => $day ); @@ -405,91 +416,72 @@ function GetEPGFromEPG($ChannelInfo) { printError($ChannelName.HTTP_ERROR); else : $response = str_replace("charset=euc-kr", "charset=utf-8", $response); + $response = mb_convert_encoding($response, "UTF-8", "EUC-KR"); + $pattern = '/(.*)<\/td>/'; + $response = preg_replace_callback($pattern, function($matches) { return ''.htmlspecialchars($matches[1], ENT_NOQUOTES).'';}, $response); + $response = str_replace(array('</b>', '</a>', '<img', 'valign=top>','align=absmiddle>'), array('', '', '','>'), $response); $dom = new DomDocument; - libxml_use_internal_errors(true); - $dom->loadHTML(mb_convert_encoding($response, "UTF-8", "EUC-KR")); - $xpath = new DomXPath($dom); - for($i = 2; $i < 5; $i++) : - $thisday = $day; - $query = "//table[contains(@style,'margin-bottom:30')][".$i."]//td[contains(@colspan,'2')]/following::td[1]/table[1]//td[2]"; - $programs = $xpath->query($query); - foreach($programs as $program) : - $hour = $xpath->query("parent::*/parent::*/parent::*/parent::*/td[1]", $program)->item(0); - $hour = str_replace("시", "", trim($hour->nodeValue)); - $minute = $xpath->query("preceding-sibling::td[1]", $program)->item(0); - $hour = $hour.":".str_replace(array("[", "]"), array("",""), trim($minute->nodeValue)); - switch ($i) : - case 2 : - $hour = $hour." AM"; - break; - case 3 : - $hour = $hour." PM"; - break; - case 4 : - if($hour > 5 && $hour < 12) : - $hour = $hour." PM"; - elseif($hour <5 || $hour == 12) : + libxml_use_internal_errors(True); + if($dom->loadHTML($response)): + $xpath = new DomXPath($dom); + for($i = 2; $i < 5; $i++) : + $thisday = $day; + $query = "//table[contains(@style,'margin-bottom:30')][".$i."]//td[contains(@colspan,'2')]/following::td[1]/table[1]//td[2]"; + $programs = $xpath->query($query); + foreach($programs as $program) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + $hour = $xpath->query("parent::*/parent::*/parent::*/parent::*/td[1]", $program)->item(0); + $hour = str_replace("시", "", trim($hour->nodeValue)); + $minute = $xpath->query("preceding-sibling::td[1]", $program)->item(0); + $minute = str_replace(array("[", "]"), array("",""), trim($minute->nodeValue)); + $minute = substr($minute, -2); + $hour = $hour.":".$minute; + switch ($i) : + case 2 : $hour = $hour." AM"; - $thisday = date("Ymd", strtotime($day." +1 days")); - endif; - break; - endswitch; - $startTime = date("YmdHis", strtotime($thisday." ".$hour)); - $programName = ""; - $subprogramName = ""; - $rating = 0; - $episode = ""; - $rebroadcast = False; - preg_match('/?(.*)?(.*?)\s*(<(.*)>)?\s*(\(재\))?\s*(\(([\d,]+)회\))?()?\s*<\/td>/', trim($dom->saveHTML($program)), $matches); - if ($matches != NULL) : - if(isset($matches[2])) $programName = trim($matches[2]) ?: ""; - if(isset($matches[4])) $subprogramName = trim($matches[4]) ?: ""; - if(isset($matches[5])) $rebroadcast = $matches[5] ? True : False; - if(isset($matches[7])) $episode = $matches[7] ?: ""; - if(isset($matches[8])) : - $image = $matches[8] ? $matches[8] : ""; - preg_match('/.*schedule_([\d,]+)?.*/', $image, $grade); - if($grade != NULL) $rating = $grade[1]; + break; + case 3 : + $hour = $hour." PM"; + break; + case 4 : + if($hour > 5 && $hour < 12) : + $hour = $hour." PM"; + elseif($hour <5 || $hour == 12) : + $hour = $hour." AM"; + $thisday = date("Ymd", strtotime($day." +1 days")); + endif; + break; + endswitch; + $startTime = date("YmdHis", strtotime($thisday." ".$hour)); + $pattern = '/^(.*?)\s*(?:<(.*)>)?\s*(?:\((재)\))?\s*(?:\(([\d,]+)회\)?)?$/'; + $programName = trim($program->nodeValue); + preg_match($pattern, $programName, $matches); + if ($matches != NULL) : + if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; + if(isset($matches[2])) $subprogramName = trim($matches[2]) ?: ""; + if(isset($matches[3])) $rebroadcast = $matches[3] ? True : False; + if(isset($matches[4])) $episode = $matches[4] ?: ""; endif; - endif; - //programName, startTime, rating, subprogramName, rebroadcast, episode - $epginfo[] = array($programName, $startTime, $rating, $subprogramName, $rebroadcast, $episode ); - endforeach; - endfor; + $images = $program->getElementsByTagName('img'); + foreach($images as $image): + preg_match('/.*schedule_([\d,]+)?.*/', $image->getAttribute('src'), $grade); + if($grade != NULL) $rating = $grade[1]; + endforeach; + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); + endforeach; + endfor; + else: + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; endif; } catch (Exception $e) { if($GLOBALS['debug']) printError($e->getMessage()); } endforeach; - $zipped = array_slice(array_map(NULL, $epginfo, array_slice($epginfo,1)),0,-1); - foreach($zipped as $epg) : - $programName = $epg[0][0] ?: ""; - $subprogramName = $epg[0][3] ?: ""; - $startTime = $epg[0][1] ?: ""; - $endTime = $epg[1][1] ?: ""; - $desc = ""; - $actors = ""; - $producers = ""; - $category = ""; - $rebroadcast = $epg[0][4]; - $episode = $epg[0][5] ?: ""; - $rating = $epg[0][2] ?: 0; - $programdata = array( - 'channelId'=> $ChannelId, - 'startTime' => $startTime, - 'endTime' => $endTime, - 'programName' => $programName, - 'subprogramName'=> $subprogramName, - 'desc' => $desc, - 'actors' => $actors, - 'producers' => $producers, - 'category' => $category, - 'episode' => $episode, - 'rebroadcast' => $rebroadcast, - 'rating' => $rating - ); - writeProgram($programdata); - endforeach; + epgzip($epginfo); } // Get EPG data from KT @@ -516,58 +508,41 @@ function GetEPGFromKT($ChannelInfo) { printError($ChannelName.HTTP_ERROR); else : $response = str_replace("charset=euc-kr", "charset=utf-8", $response); + $response = mb_convert_encoding($response, "UTF-8", "EUC-KR"); $dom = new DomDocument; - libxml_use_internal_errors(true); - $dom->loadHTML(mb_convert_encoding($response, "UTF-8", "EUC-KR")); - $xpath = new DomXPath($dom); - $query = "//table[@id='pop_day']/tbody/tr"; - $rows = $xpath->query($query); - foreach($rows as $row) : - $cells = $row->getElementsByTagName('td'); - #programName, startTime, rating, category - $startTime = date("YmdHis", strtotime($day." ".trim($cells->item(0)->nodeValue))); - $rating = str_replace("all", 0, str_replace("세 이상", "", trim($cells->item(2)->nodeValue))); - $epginfo[]= array(trim($cells->item(1)->nodeValue), $startTime, $rating, trim($cells->item(4)->nodeValue)); - endforeach; + libxml_use_internal_errors(True); + if($dom->loadHTML($response)): + $xpath = new DomXPath($dom); + $query = "//table[@id='pop_day']/tbody/tr"; + $rows = $xpath->query($query); + foreach($rows as $row) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + $cells = $row->getElementsByTagName('td'); + //programName, startTime, rating, category + $startTime = date("YmdHis", strtotime($day." ".trim($cells->item(0)->nodeValue))); + $pattern = '/^(.*?)( <(.*)>)?$/'; + $programName = trim($cells->item(1)->nodeValue); + preg_match($pattern, $programName, $matches); + if ($matches != NULL) : + if(isset($matches[1])) $programName = $matches[1] ?: ""; + if(isset($matches[3])) $subprogramName = $matches[3] ?: ""; + endif; + $category = trim($cells->item(4)->nodeValue); + $rating = str_replace("all", 0, str_replace("세 이상", "", trim($cells->item(2)->nodeValue))); + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); + endforeach; + else : + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; endif; } catch (Exception $e) { if($GLOBALS['debug']) printError($e->getMessage()); } endforeach; - $zipped = array_slice(array_map(NULL, $epginfo, array_slice($epginfo,1)),0,-1); - foreach($zipped as $epg) : - $programName = ""; - $subprogramName = ""; - preg_match('/^(.*?)( <(.*)>)?$/', $epg[0][0], $matches); - if ($matches != NULL) : - if(isset($matches[1])) $programName = $matches[1] ?: ""; - if(isset($matches[3])) $subprogramName = $matches[3] ?: ""; - endif; - $startTime = $epg[0][1] ?: ""; - $endTime = $epg[1][1] ?: ""; - $desc = ""; - $actors = ""; - $producers = ""; - $category = $epg[0][3] ?: ""; - $rebroadcast = False; - $episode = ""; - $rating = $epg[0][2] ?: 0; - $programdata = array( - 'channelId'=> $ChannelId, - 'startTime' => $startTime, - 'endTime' => $endTime, - 'programName' => $programName, - 'subprogramName'=> $subprogramName, - 'desc' => $desc, - 'actors' => $actors, - 'producers' => $producers, - 'category' => $category, - 'episode' => $episode, - 'rebroadcast' => $rebroadcast, - 'rating' => $rating - ); - writeProgram($programdata); - endforeach; + epgzip($epginfo); } // Get EPG data from LG @@ -591,65 +566,44 @@ function GetEPGFromLG($ChannelInfo) { printError($ChannelName.HTTP_ERROR); else : $response = ''.$response; - $dom = new DomDocument; - libxml_use_internal_errors(true); $response = mb_convert_encoding($response, "UTF-8", "EUC-KR"); $response = str_replace(array('<재>', ' [..', ' (..'), array('<재>', '', ''), $response); - $dom->loadHTML($response); - $xpath = new DomXPath($dom); - $query = "//div[@class='tblType list']/table/tbody/tr"; - $rows = $xpath->query($query); - foreach($rows as $row) : - $cells = $row->getElementsByTagName('td'); - $programName = trim($cells->item(1)->childNodes->item(0)->nodeValue); - $startTime = date("YmdHis", strtotime($day." ".trim($cells->item(0)->nodeValue))); - $spans = $cells->item(1)->getElementsByTagName('span'); - $rating = trim($spans->item(1)->nodeValue)=="All" ? 0 : trim($spans->item(1)->nodeValue); - //programName, startTime, rating, category - $epginfo[]= array($programName, $startTime, $rating, trim($cells->item(2)->nodeValue)); - endforeach; + $dom = new DomDocument; + libxml_use_internal_errors(True); + if($dom->loadHTML($response)): + $xpath = new DomXPath($dom); + $query = "//div[@class='tblType list']/table/tbody/tr"; + $rows = $xpath->query($query); + foreach($rows as $row) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + $cells = $row->getElementsByTagName('td'); + $startTime = date("YmdHis", strtotime($day." ".trim($cells->item(0)->nodeValue))); + $programName = trim($cells->item(1)->childNodes->item(0)->nodeValue); + $pattern = '/(<재>)?\s?(?:\[.*?\])?(.*?)(?:\[(.*)\])?\s?(?:\(([\d,]+)회\))?$/'; + preg_match($pattern, $programName, $matches); + if ($matches != NULL) : + if(isset($matches[2])) $programName = trim($matches[2]) ?: ""; + if(isset($matches[3])) $subprogramName = trim($matches[3]) ?: ""; + if(isset($matches[4])) $episode = trim($matches[4]) ?: ""; + if(isset($matches[1])) $rebroadcast = trim($matches[1]) ? True: False; + endif; + $category = trim($cells->item(2)->nodeValue); + $spans = $cells->item(1)->getElementsByTagName('span'); + $rating = trim($spans->item(1)->nodeValue)=="All" ? 0 : trim($spans->item(1)->nodeValue); + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); + endforeach; + else : + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; endif; } catch (Exception $e) { if($GLOBALS['debug']) printError($e->getMessage()); } endforeach; - $zipped = array_slice(array_map(NULL, $epginfo, array_slice($epginfo,1)),0,-1); - foreach($zipped as $epg) : - preg_match('/(<재>?)?(.*?)(\[(.*)\])?\s?(\(([\d,]+)회\))?$/', $epg[0][0], $matches); - $programName = ""; - $subprogramName = ""; - $episode = ""; - $rebroadcast = False; - if ($matches != NULL) : - if(isset($matches[2])) $programName = trim($matches[2]) ?: ""; - if(isset($matches[4])) $subprogramName = trim($matches[4]) ?: ""; - if(isset($matches[6])) $episode = trim($matches[6]) ?: ""; - if(isset($matches[1])) $rebroadcast = trim($matches[1]) ? True: False; - endif; - $startTime = $epg[0][1] ?: ""; - $endTime = $epg[1][1] ?: ""; - $desc = ""; - $actors = ""; - $producers = ""; - $category = $epg[0][3] ?: ""; - - $rating = $epg[0][2] ?: 0; - $programdata = array( - 'channelId'=> $ChannelId, - 'startTime' => $startTime, - 'endTime' => $endTime, - 'programName' => $programName, - 'subprogramName'=> $subprogramName, - 'desc' => $desc, - 'actors' => $actors, - 'producers' => $producers, - 'category' => $category, - 'episode' => $episode, - 'rebroadcast' => $rebroadcast, - 'rating' => $rating - ); - writeProgram($programdata); - endforeach; + epgzip($epginfo); } // Get EPG data from SK @@ -681,11 +635,11 @@ function GetEPGFromSK($ChannelInfo) { else : $programs = $data['channel']['programs']; foreach ($programs as $program) : - $programName = ""; - $subprogramName = ""; - $episode = ""; + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; $rebroadcast = False; - preg_match('/^(.*?)(?:\s*[\(<]([\d,회]+)[\)>])?(?:\s*<([^<]*?)>)?(\((재)\))?$/', str_replace('...', '>', $program['programName']), $matches); + $rating = 0; + $pattern = '/^(.*?)(?:\s*[\(<]([\d,회]+)[\)>])?(?:\s*<([^<]*?)>)?(\((재)\))?$/'; + preg_match($pattern, str_replace('...', '>', $program['programName']), $matches); if ($matches != NULL) : if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; if(isset($matches[3])) $subprogramName = trim($matches[3]) ?: ""; @@ -736,12 +690,11 @@ function GetEPGFromSKB($ChannelInfo) { $ServiceId = $ChannelInfo[3]; $epginfo = array(); foreach(range(1, $GLOBALS['period']) as $k) : - $url = "http://www.skbroadband.com/content/realtime/Channel_List.do"; + $url = "http://m.skbroadband.com/content/realtime/Channel_List.do"; $day = date("Ymd", strtotime("+".($k - 1)." days")); $params = array( 'key_depth2' => $ServiceId, - 'key_depth3' => $day, - 'tab_gubun' => 'lst' + 'key_depth3' => $day ); $params = http_build_query($params); $method = "POST"; @@ -751,64 +704,51 @@ function GetEPGFromSKB($ChannelInfo) { printError($ChannelName.HTTP_ERROR); else : $response = str_replace('charset="euc-kr"', 'charset="utf-8"', $response); + $response = mb_convert_encoding($response, "UTF-8", "EUC-KR"); + $response = preg_replace('//is', '', $response); + $response = preg_replace('/<\/span>/is', '', $response); + $pattern = '/(.*)<\/span>/'; + $response = preg_replace_callback($pattern, function($matches) { return ''.htmlspecialchars($matches[1], ENT_NOQUOTES).'';}, $response); $dom = new DomDocument; libxml_use_internal_errors(True); - $response = mb_convert_encoding($response, "UTF-8", "EUC-KR"); - $dom->loadHTML($response); - $xpath = new DomXPath($dom); - $query = "//tr[@class='".$day."']"; - $rows = $xpath->query($query); - foreach($rows as $row) : - $cells = $row->getElementsByTagName('td'); - $pattern = '/^(.*?)(\(([\d,]+)회\))?(<(.*)>)?(\((재)\))?$/'; - preg_match($pattern, trim($cells->item(0)->nodeValue), $matches); - if ($matches != NULL) : - if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; - if(isset($matches[5])) $subprogramName = trim($matches[5]) ?: ""; - if(isset($matches[3])) $episode = $matches[3] ?: ""; - if(isset($matches[7])) $rebroadcast = $matches[7] ? True : False; - endif; - preg_match('/.*\s*([\d,]+)\s*.*/', $cells->item(1)->nodeValue, $rating); - $startTime = $row->getElementsByTagName('th')->item(0)->nodeValue; - $startTime = date("YmdHis", strtotime($day." ".$startTime)); - $rating = $rating[1]; - //programName, startTime, rating, subprogramName, rebroadcast, episode - $epginfo[]= array($programName, $startTime, $rating, $subprogramName, $rebroadcast, $episode); - endforeach; + if($dom->loadHTML($response)): + $xpath = new DomXPath($dom); + $query = "//span[@class='caption' or @class='explan' or @class='fullHD' or @class='UHD' or @class='nowon']"; + $spans = $xpath->query($query); + foreach($spans as $span) : + $span->parentNode->removeChild( $span); + endforeach; + $query = "//div[@id='dawn']/ul/li"; + $rows = $xpath->query($query); + foreach($rows as $row) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + $cells = $row->getElementsByTagName('span'); + $startTime = $cells->item(0)->nodeValue ?: ""; + $startTime = date("YmdHis", strtotime($day." ".$startTime)); + $programName = trim($cells->item(2)->nodeValue) ?: ""; + $pattern = '/^(.*?)(\(([\d,]+)회\))?(<(.*)>)?(\((재)\))?$/'; + preg_match($pattern, $programName, $matches); + if ($matches != NULL) : + if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; + if(isset($matches[5])) $subprogramName = trim($matches[5]) ?: ""; + if(isset($matches[3])) $episode = $matches[3] ?: ""; + if(isset($matches[7])) $rebroadcast = $matches[7] ? True : False; + endif; + if($cells->length > 3) $rating = str_replace('세', '', $cells->item(3)->nodeValue) ?: 0; + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); + endforeach; + else : + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; endif; } catch (Exception $e) { if($GLOBALS['debug']) printError($e->getMessage()); } endforeach; - $zipped = array_slice(array_map(NULL, $epginfo, array_slice($epginfo,1)),0,-1); - foreach($zipped as $epg) : - $programName = trim($epg[0][0]) ?: ""; - $subprogramName = trim($epg[0][3]) ?: ""; - $episode = $epg[0][5] ?: ""; - $rebroadcast = $epg[0][4] ? True: False; - $startTime = $epg[0][1] ?: ""; - $endTime = $epg[1][1] ?: ""; - $desc = ""; - $actors = ""; - $producers = ""; - $category = ""; - $rating = $epg[0][2] ?: 0; - $programdata = array( - 'channelId'=> $ChannelId, - 'startTime' => $startTime, - 'endTime' => $endTime, - 'programName' => $programName, - 'subprogramName'=> $subprogramName, - 'desc' => $desc, - 'actors' => $actors, - 'producers' => $producers, - 'category' => $category, - 'episode' => $episode, - 'rebroadcast' => $rebroadcast, - 'rating' => $rating - ); - writeProgram($programdata); - endforeach; + epgzip($epginfo); } // Get EPG data from SKY @@ -842,6 +782,9 @@ function GetEPGFromSKY($ChannelInfo) { else : $programs = $data['scheduleListIn']; foreach($programs as $program) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; $programName = htmlspecialchars_decode($program['program_name']) ?: ""; $subprogramName = str_replace(array('lt;', 'gt;', 'amp;'), array('<', '>', '&'),$program['program_subname']) ?: ""; $startTime = $program['starttime']; @@ -851,8 +794,12 @@ function GetEPGFromSKY($ChannelInfo) { $description = str_replace(array('lt;', 'gt;', 'amp;'), array('<', '>', '&'),$program['description']) ?: ""; $summary = str_replace(array('lt;', 'gt;', 'amp;'), array('<', '>', '&'),$program['summary']) ?: ""; $desc = $description ?: ""; - if($summary) : - $desc = $desc."\n".$summary; + if($desc) : + if($summary): + $desc = $desc."\n".$summary; + endif; + else : + $desc = $summary; endif; $category = $program['program_category1']; $episode = $program['episode_id'] ?: ""; @@ -932,41 +879,19 @@ function GetEPGFromNaver($ChannelInfo) { for($i = 0; $i < count($data['displayDates']); $i++) : for($j = 0; $j < 24; $j++) : foreach($data['schedules'][$j][$i] as $program) : - //programName, startTime, episode, rebroadcast, rating + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; $startTime = date("YmdHis", strtotime($data['displayDates'][$i]['date']." ".$program['startTime'])); - $epginfo[] = array($program['title'], $startTime, str_replace("회","", $program['episode']), $program['isRerun'], $program['grade']); + $programName = htmlspecialchars_decode(trim($program['title']), ENT_XML1); + $episode = str_replace("회","", $program['episode']); + $rebroadcast = $program['isRerun'] ? True : False; + $rating = $program['grade']; + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); endforeach; endfor; endfor; - $zipped = array_slice(array_map(NULL, $epginfo, array_slice($epginfo,1)),0,-1); - foreach($zipped as $epg) : - $programName = htmlspecialchars_decode($epg[0][0], ENT_XML1) ?: ""; - $subprogramName = ""; - $startTime = $epg[0][1] ?: ""; - $endTime = $epg[1][1] ?: ""; - $desc = ""; - $actors = ""; - $producers = ""; - $category = ""; - $rebroadcast = $epg[0][3] ? True: False; - $episode = $epg[0][2] ?: ""; - $rating = $epg[0][4] ?: 0; - $programdata = array( - 'channelId'=> $ChannelId, - 'startTime' => $startTime, - 'endTime' => $endTime, - 'programName' => $programName, - 'subprogramName'=> $subprogramName, - 'desc' => $desc, - 'actors' => $actors, - 'producers' => $producers, - 'category' => $category, - 'episode' => $episode, - 'rebroadcast' => $rebroadcast, - 'rating' => $rating - ); - writeProgram($programdata); - endforeach; endif; } catch(Exception $e) { if($GLOBALS['debug']) printError($e->getMessage()); @@ -975,21 +900,223 @@ function GetEPGFromNaver($ChannelInfo) { } catch (Exception $e) { if($GLOBALS['debug']) printError($e->getMessage()); } -} - -// Get EPG data from Tbroad -function GetEPGFromTbroad($ChannelInfo) { - $url='https://www.tbroad.com/chplan/selectRealTimeListForNormal.tb'; + epgzip($epginfo); } // Get EPG data from Iscs function GetEPGFromIscs($ChannelInfo) { - $url='http://service.iscs.co.kr/sub/channel_view.asp'; + $ChannelId = $ChannelInfo[0]; + $ChannelName = $ChannelInfo[1]; + $ServiceId = $ChannelInfo[3]; + $epginfo = array(); + foreach(range(1, $GLOBALS['period']) as $k) : + $url = "https://www.iscs.co.kr/service/sub/ajax_channel_view.asp"; + $day = date("Y-m-d", strtotime("+".($k - 1)." days")); + $params = array( + 's_idx' => $ServiceId, + 'C_date' => $day + ); + $params = http_build_query($params); + $method = "POST"; + try { + $response = getWeb($url, $params, $method); + if ($response === False && $GLOBALS['debug']) : + printError($ChannelName.HTTP_ERROR); + else : + try { + $data = json_decode($response, TRUE); + if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR); + if(count($data['html']) == 0) : + if($GLOBALS['debug']) : + printError($ChannelName.CHANNEL_ERROR); + endif; + else : + $response = $data['html']; + $response = mb_convert_encoding($response, "HTML-ENTITIES", "UTF-8"); + $pattern = '/(.*)<\/td>/'; + $response = preg_replace_callback($pattern, function($matches) { return ''.htmlspecialchars($matches[1]).'';}, $response); + $dom = new DomDocument; + libxml_use_internal_errors(True); + if($dom->loadHTML($response)): + $xpath = new DomXPath($dom); + $query = "//div[@class='pp_tbl']/table/tbody/tr"; + $rows = $xpath->query($query); + foreach($rows as $row) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + $cells = $row->getElementsByTagName('td'); + $startTime = $cells->item(0)->nodeValue ?: ""; + $startTime = date("YmdHis", strtotime($day." ".$startTime)); + $programName = trim($cells->item(1)->nodeValue) ?: ""; + $pattern = '/^(.*?)(?:\(([\d,]+)회\))?(?:\((재)\))?$/'; + preg_match($pattern, $programName, $matches); + if ($matches != NULL) : + if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; + if(isset($matches[2])) $episode = $matches[2] ?: ""; + if(isset($matches[3])) $rebroadcast = $matches[3] ? True : False; + endif; + $rating = $cells->item(2)->nodeValue=='전체관람' ? 0 : str_replace('세이상', '', $cells->item(2)->nodeValue); + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); + endforeach; + else : + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; + endif; + } catch(Exception $e) { + if($GLOBALS['debug']) printError($e->getMessage()); + } + endif; + } catch (Exception $e) { + if($GLOBALS['debug']) printError($e->getMessage()); + } + endforeach; + epgzip($epginfo); +} + +// Get EPG data from Hcn +function GetEPGFromHcn($ChannelInfo) { + $ChannelId = $ChannelInfo[0]; + $ChannelName = $ChannelInfo[1]; + $ServiceId = $ChannelInfo[3]; + $epginfo = array(); + foreach(range(1, $GLOBALS['period']) as $k) : + $url = "https://www.hcn.co.kr/ur/bs/ch/channelInfo.hcn"; + $day = date("Y-m-d", strtotime("+".($k - 1)." days")); + $params = array( + 'method' => 'ajax_00', + 'pageType' => 'sheetList', + 'ch_id' => $ServiceId, + 'onairdate' => $day + ); + $params = http_build_query($params); + $method = "POST"; + try { + $response = getWeb($url, $params, $method); + if ($response === False && $GLOBALS['debug']) : + printError($ChannelName.HTTP_ERROR); + else : + $response = mb_convert_encoding($response, "HTML-ENTITIES", "EUC-KR"); + $dom = new DomDocument; + libxml_use_internal_errors(True); + if($dom->loadHTML($response)): + $xpath = new DomXPath($dom); + $query = "//tr[@class='']"; + $rows = $xpath->query($query); + foreach($rows as $row) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + $cells = $row->getElementsByTagName('td'); + $startTime = $cells->item(0)->nodeValue ?: ""; + $startTime = date("YmdHis", strtotime($day." ".$startTime)); + $programName = trim($cells->item(1)->nodeValue) ?: ""; + $category = trim($cells->item(2)->nodeValue) ?: ""; + $category = preg_replace('/\(.*\)/', '', $category); + $images = $row->getElementsByTagName('img'); + foreach($images as $image): + preg_match('/re\.png/', $image->getAttribute('src'), $rebroad); + if($rebroad != NULL) $rebroadcast = True; + preg_match('/.*plus([\d,]+)\.png/', $image->getAttribute('src'), $grade); + if($grade != NULL) $rating = $grade[1]; + endforeach; + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); + endforeach; + else : + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; + endif; + } catch (Exception $e) { + if($GLOBALS['debug']) printError($e->getMessage()); + } + endforeach; + epgzip($epginfo); +} + +// Get EPG data from POOQ +function GetEPGFromPooq($ChannelInfo) { + $ChannelId = $ChannelInfo[0]; + $ChannelName = $ChannelInfo[1]; + $ServiceId = $ChannelInfo[3]; + $today = date("Ymd"); + $lastday = date("Ymd", strtotime("+".($GLOBALS['period'] - 1)." days")); + $url = "https://wapie.pooq.co.kr/v1/epgs30/".$ServiceId."/"; $params = array( - 'chan_idx'=>'242', - 'source_id'=>'203', - 'Chan_Date'=>'2017-04-18' + 'deviceTypeId'=> 'pc', + 'marketTypeId'=> 'generic', + 'apiAccessCredential'=> 'EEBE901F80B3A4C4E5322D58110BE95C', + 'offset'=> '0', + 'limit'=> '1000', + 'startTime'=> date("Y/m/d", strtotime($today)).' 00:00', + 'endTime'=> date("Y/m/d", strtotime($lastday)).' 00:00' ); + foreach(range(1, $GLOBALS['period']) as $k) : + $day = date("Y-m-d", strtotime("+".($k - 1)." days")); + $date_list[] = $day; + endforeach; + $params = http_build_query($params); + $method = "GET"; + try { + $response = getWeb($url, $params, $method); + if ($response === False && $GLOBALS['debug']) : + printError($ChannelName.HTTP_ERROR); + else : + try { + $data = json_decode($response, TRUE); + if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR); + if($data['result']['count'] == 0) : + if($GLOBALS['debug']) : + printError($ChannelName.CHANNEL_ERROR); + endif; + else : + $programs = $data['result']['list']; + foreach ($programs as $program) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + if(in_array($program['startDate'] , $date_list)) : + $startTime = $program['startDate']." ".$program['startTime']; + $startTime = date("YmdHis", strtotime($startTime)); + $endTime = $program['startDate']." ".$program['endTime']; + $endTime = date("YmdHis", strtotime($endTime)); + $pattern = '/^(.*?)(?:([\d,]+)회)?(?:\((재)\))?$/'; + $programName = str_replace("\r\n", "", $program['programTitle']); + preg_match($pattern, $programName, $matches); + if($matches !== NULL) : + if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; + if(isset($matches[2])) $episode = trim($matches[2]) ?: ""; + if(isset($matches[3])) $rebroadcast = $matches[3] ? True : False; + endif; + if($program['programStaring']) $actors = trim($program['programStaring'], ','); + if($program['programSummary']) $desc = trim($program['programSummary']); + $rating = $program['age']; + $programdata = array( + 'channelId'=> $ChannelId, + 'startTime' => $startTime, + 'endTime' => $endTime, + 'programName' => $programName, + 'subprogramName'=> $subprogramName, + 'desc' => $desc, + 'actors' => $actors, + 'producers' => $producers, + 'category' => $category, + 'episode' => $episode, + 'rebroadcast' => $rebroadcast, + 'rating' => $rating + ); + writeProgram($programdata); + endif; + endforeach; + endif; + } catch(Exception $e) { + if($GLOBALS['debug']) printError($e->getMessage()); + } + endif; + } catch (Exception $e) { + if($GLOBALS['debug']) printError($e->getMessage()); + } } // Get EPG data from MBC @@ -1022,23 +1149,19 @@ function GetEPGFromMbc($ChannelInfo) { $programs = $data['Programs']; foreach($programs as $program) : if($program['Channel'] == "CHAM" && $program['LiveDays'] == $dayofweek[date("w", strtotime($day))]) : - $programName = ""; + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; $rebroadcast = False; - preg_match('/^(.*?)(\(재\))?$/', htmlspecialchars_decode($program['ProgramTitle']), $matches); + $rating = 0; + $pattern = '/^(.*?)(\(재\))?$/'; + preg_match($pattern, htmlspecialchars_decode($program['ProgramTitle']), $matches); if ($matches != NULL) : $programName = $matches[1]; - $rebroadcast = $matches[2] ? True : False; + if(isset($matches[2])) $rebroadcast = $matches[2] ? True : False; endif; - $subprogramName = ""; $startTime = $day." ".$program['StartTime']; $startTime = date("YmdHis", strtotime($startTime)); $endTime = date("YmdHis", strtotime("+".$program['RunningTime']." minutes", strtotime($startTime))); - $desc = ""; - $actors = ""; - $producers = ""; $category = "음악"; - $episode = ""; - $rating = 0; $programdata = array( 'channelId'=> $ChannelId, 'startTime' => $startTime, @@ -1095,24 +1218,22 @@ function GetEPGFromMil($ChannelInfo) { else : $programs = $data['resultList']; foreach($programs as $program) : - $programName = ""; + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; $rebroadcast = False; - preg_match('/^(.*?)(\(재\))?$/', htmlspecialchars_decode($program['program_title']), $matches); + $rating = 0; + $pattern = '/^(.*?)(\(재\))?$/'; + preg_match($pattern, htmlspecialchars_decode($program['program_title']), $matches); if ($matches != NULL) : $programName = $matches[1]; - $rebroadcast = $matches[2] ? True : False; + if(isset($matches[2])) $rebroadcast = $matches[2] ? True : False; endif; $subprogramName = htmlspecialchars_decode($program['program_subtitle']); $startTime = $day." ".$program['program_time']; $startTime = date("YmdHis", strtotime($startTime)); $endTime = $day." ".$program['program_end_time']; $endTime = date("YmdHis", strtotime($endTime)); - $desc = ""; $actors = htmlspecialchars_decode($program['movie_actor']); $producers = htmlspecialchars_decode($program['movie_director']); - $category = ""; - $episode = ""; - $rating = 0; $programdata = array( 'channelId'=> $ChannelId, 'startTime' => $startTime, @@ -1170,19 +1291,16 @@ function GetEPGFromIfm($ChannelInfo) { else : $programs = $data['hybMusicInfoList']; foreach($programs as $program) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; $programName = htmlspecialchars_decode($program['pgmTitle']) ?: ""; - $subprogramName = ""; $startTime = $day." ".$program['pgmStime']; $startTime = date("YmdHis", strtotime($startTime)); $endTime = $day." ".$program['pgmEtime']; $endTime = date("YmdHis", strtotime($endTime)); - $desc = ""; $actors = htmlspecialchars_decode($program['pgmDj']); $producers = htmlspecialchars_decode($program['pgmPd']); - $category = ""; - $episode = ""; - $rebroadcast = False; - $rating = 0; $programdata = array( 'channelId'=> $ChannelId, 'startTime' => $startTime, @@ -1238,18 +1356,22 @@ function GetEPGFromKbs($ChannelInfo) { endif; else : $dom = new DomDocument; - libxml_use_internal_errors(true); + libxml_use_internal_errors(True); $dom->loadHTML($data['schedule']); $xpath = new DomXPath($dom); $query = "//li"; $rows = $xpath->query($query); foreach($rows as $row) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; $cells = $row->getElementsByTagName('span'); + $startTime = $day." ".trim($cells->item(0)->childNodes->item(0)->nodeValue); + $startTime = date("YmdHis", strtotime($startTime)); $programName = trim($cells->item(2)->childNodes->item(0)->nodeValue); $programName = str_replace(array("[","]", " Broadcast"), array("", "", ""), $programName); - $startTime = $day." ".trim($cells->item(0)->childNodes->item(0)->nodeValue); - //programName, startTime, rating, category - $epginfo[]= array($programName, $startTime); + //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating + $epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); endforeach; endif; } catch(Exception $e) { @@ -1260,21 +1382,99 @@ function GetEPGFromKbs($ChannelInfo) { if($GLOBALS['debug']) printError($e->getMessage()); } endforeach; + epgzip($epginfo); +} + +function GetEPGFromArirang($ChannelInfo) { + $ChannelId = $ChannelInfo[0]; + $ChannelName = $ChannelInfo[1]; + $ServiceId = $ChannelInfo[3]; + $epginfo = array(); + foreach(range(1, $GLOBALS['period']) as $k) : + $url = "http://www.arirang.com/Radio/Radio_Index.asp"; + $day = date("Y-m-d", strtotime("+".($k - 1)." days")); + $params = array(); + $params = http_build_query($params); + $method = "GET"; + try { + $response = getWeb($url, $params, $method); + if ($response === False && $GLOBALS['debug']) : + printError($ChannelName.HTTP_ERROR); + else : + $dom = new DomDocument; + libxml_use_internal_errors(True); + //echo $response; + + $response = mb_convert_encoding($response, "HTML-ENTITIES", "EUC-KR"); + if($dom->loadHTML($response)): + $xpath = new DomXPath($dom); + $dayofweek = date("w", strtotime($day)); + if($dayofweek == 0): + $query = "//table[@id='aIRSW_sun']/tr"; + elseif($dayofweek == 6): + $query = "//table[@id='aIRSW_sat']/tr"; + else : + $query = "//table[@id='aIRSW_week']/tr"; + endif; + $rows = $xpath->query($query); + foreach($rows as $row) : + $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; + $rebroadcast = False; + $rating = 0; + $time = $row->getElementsByTagName('th'); + $times = explode('~', trim($time->item(0)->nodeValue)); + $startTime = date("YmdHis", strtotime($day." ".$times[0])); + $endTime = date("YmdHis", strtotime($day." ".$times[1])); + $program = $row->getElementsByTagName('td'); + $pattern = '/^(.*?)(?:\((Re)\))?$/'; + preg_match($pattern, trim($program->item(0)->nodeValue), $matches); + if ($matches != NULL) : + $programName = $matches[1]; + if(isset($matches[2])) $rebroadcast = $matches[2] ? True : False; + endif; + $programdata = array( + 'channelId'=> $ChannelId, + 'startTime' => $startTime, + 'endTime' => $endTime, + 'programName' => $programName, + 'subprogramName'=> $subprogramName, + 'desc' => $desc, + 'actors' => $actors, + 'producers' => $producers, + 'category' => $category, + 'episode' => $episode, + 'rebroadcast' => $rebroadcast, + 'rating' => $rating + ); + writeProgram($programdata); + endforeach; + else : + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; + endif; + } catch (Exception $e) { + if($GLOBALS['debug']) printError($e->getMessage()); + } + endforeach; +} + +# Zip epginfo +function epgzip($epginfo) { + #ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating $zipped = array_slice(array_map(NULL, $epginfo, array_slice($epginfo,1)),0,-1); foreach($zipped as $epg) : - $programName = $epg[0][0] ?: ""; - $subprogramName = ""; + $ChannelId = $epg[0][0] ?: ""; $startTime = $epg[0][1] ?: ""; - $startTime = date("YmdHis", strtotime($startTime)); $endTime = $epg[1][1] ?: ""; - $endTime = date("YmdHis", strtotime($endTime)); - $desc = ""; - $actors = ""; - $producers = ""; - $category = ""; - $rebroadcast = False; - $episode = ""; - $rating = 0; + $programName = $epg[0][2] ?: ""; + $subprogramName = $epg[0][3] ?: ""; + $desc = $epg[0][4] ?: ""; + $actors = $epg[0][5] ?: ""; + $producers = $epg[0][6] ?: ""; + $category = $epg[0][7] ?: ""; + $episode = $epg[0][8] ?: ""; + $rebroadcast = $rebroadcast = $epg[0][9] ? True: False; + $rating = $epg[0][10] ?: 0; $programdata = array( 'channelId'=> $ChannelId, 'startTime' => $startTime, @@ -1292,7 +1492,6 @@ function GetEPGFromKbs($ChannelInfo) { writeProgram($programdata); endforeach; } - function writeProgram($programdata) { $fp = $GLOBALS['fp']; $ChannelId = $programdata['channelId']; @@ -1307,7 +1506,8 @@ function writeProgram($programdata) { endif; if($programName == NULL): $programName = $subprogramName; - endif; $actors = htmlspecialchars($programdata['actors'], ENT_XML1); + endif; + $actors = htmlspecialchars($programdata['actors'], ENT_XML1); $producers = htmlspecialchars($programdata['producers'], ENT_XML1); $category = htmlspecialchars($programdata['category'], ENT_XML1); $episode = $programdata['episode']; @@ -1320,17 +1520,19 @@ function writeProgram($programdata) { $rating = sprintf("%s세 이상 관람가", $programdata['rating']); endif; if($GLOBALS['addverbose'] == 'y') : - $desc = htmlspecialchars($programdata['programName'], ENT_XML1); + $desc = trim(htmlspecialchars($programdata['programName'], ENT_XML1)); if($subprogramName) $desc = $desc."\n부제 : ".$subprogramName; + if($rebroadcast == True && $GLOBALS['addrebroadcast'] == 'y') $desc = $desc."\n방송 : 재방송"; if($episode) $desc = $desc."\n회차 : ".$episode."회"; if($category) $desc = $desc."\n장르 : ".$category; - if($actors) $desc = $desc."\n출연 : ".$actors; - if($producers) $desc = $desc."\n제작 : ".$producers; + if($actors) $desc = $desc."\n출연 : ".trim($actors); + if($producers) $desc = $desc."\n제작 : ".trim($producers); $desc = $desc."\n등급 : ".$rating; else: $desc = ""; endif; if($programdata['desc']) $desc = $desc."\n".htmlspecialchars($programdata['desc'], ENT_XML1); + $desc = preg_replace('/ +/', ' ', $desc); $contentTypeDict = array( '교양' => 'Arts / Culture (without music)', '만화' => 'Cartoons / Puppets', @@ -1395,20 +1597,22 @@ function getWeb($url, $params, $method) { curl_setopt ($ch, CURLOPT_POSTFIELDS, $params); endif; curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,True); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, True); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $GLOBALS['timeout']); curl_setopt($ch, CURLOPT_HEADER, False); - curl_setopt($ch, CURLOPT_FAILONERROR,True); + curl_setopt($ch, CURLOPT_FAILONERROR, True); curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['ua']); $response = curl_exec($ch); if(curl_error($ch) && $GLOBALS['debug']) printError($url." ".curl_error($ch)); curl_close($ch); return $response; } + function printLog($string) { header("Content-Type: text/plain; charset=utf-8"); print($string."\n"); } + function printError($string) { header("Content-Type: text/plain; charset=utf-8"); print("Error : ".$string."\n"); diff --git a/epg2xml.json b/epg2xml.json index 6792673..750a546 100644 --- a/epg2xml.json +++ b/epg2xml.json @@ -3,9 +3,9 @@ "###_COMMENT_###" : "epg 정보를 가져오는 설정 파일", "###_COMMENT_###" : "사용하는 ISP 선택 (ALL, KT, LG, SK)", "MyISP": "ALL", - "###_COMMENT_###" : "### # My Channel Enabled:1 로 하고자 하는 채널 ID ###", + "###_COMMENT_###" : "### # My Channel EPG 정보 가져오는 2017-09-01채널 ID ###", "###_COMMENT_###" : "1, 2, 3, 4", - "MyChannels" : "60, 110, 111, 122, 164", + "MyChannels" : "60, 110, 111, 122, 164", "###_COMMENT_###" : "output 셋팅은 (d, o, s) 셋중에 하나로 선택한다", "###_COMMENT_###" : " d - EPG 정보 화면 출력", "###_COMMENT_###" : " o - EPG 정보 파일로 저정", @@ -15,12 +15,12 @@ "default_icon_url": "", "###_COMMENT_###" : "### 제목에 재방송 정보 출력 ###", "default_rebroadcast": "y", - "###_COMMENT_###" : "#### 제목에 회차정보 출력 ###", + "###_COMMENT_###" : "#### 제목에 회차정보 출력 ###", "default_episode" : "y", "###_COMMENT_###" : "### EPG 정보 추가 출력 ###", "default_verbose" : "y", "###_COMMENT_###" : "### epg 데이터 가져오는 기간으로 1에서 2까지 설정가능 ###", - "default_fetch_limit" : "2", + "default_fetch_limit" : "7", "###_COMMENT_###" : "### epg 저장시 기본 저장 이름 (ex: /home/tvheadend/xmltv.xml) ###", "default_xml_file" : "xmltv.xml", "###_COMMENT_###" : "### # External XMLTV 사용시 기본 소켓 이름 (ex: /home/tvheadend/xmltv.sock) ###", diff --git a/epg2xml.php b/epg2xml.php index bde7925..7a4a689 100644 --- a/epg2xml.php +++ b/epg2xml.php @@ -1,8 +1,7 @@ #!/usr/bin/env php 2 ? 2 : $period; else : printError("default_fetch_limit는 1, 2, 3, 4, 5, 6, 7만 가능합니다."); @@ -379,7 +377,6 @@ function getEPG() { $ChannelSource = $ChannelInfo[2]; $ChannelServiceId = $ChannelInfo[3]; if($GLOBALS['debug']) printLog($ChannelName.' 채널 EPG 데이터를 가져오고 있습니다'); - if($ChannelSource == 'EPG') : GetEPGFromEPG($ChannelInfo); elseif($ChannelSource == 'KT') : @@ -1479,6 +1476,7 @@ function GetEPGFromArirang($ChannelInfo) { } endforeach; } + # Zip epginfo function epgzip($epginfo) { #ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating @@ -1632,6 +1630,7 @@ function getWeb($url, $params, $method) { function printLog($string) { fwrite(STDERR, $string."\n"); } + function printError($string) { fwrite(STDERR, "Error : ".$string."\n"); } diff --git a/epg2xml.py b/epg2xml.py index e099875..b1a005b 100644 --- a/epg2xml.py +++ b/epg2xml.py @@ -1091,7 +1091,6 @@ if default_fetch_limit : sys.exit() else : period = int(default_fetch_limit) - #if period > 2 : period = 2 else : printError("epg2xml.json 파일의 default_fetch_limit항목이 없습니다."); sys.exit()