Update epg2xml-web.php
This commit is contained in:
parent
a0a4829c35
commit
683366474b
753
epg2xml-web.php
753
epg2xml-web.php
@ -3,7 +3,7 @@
|
||||
@date_default_timezone_set('Asia/Seoul');
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
@set_time_limit(0);
|
||||
define("VERSION", "1.2.5p3");
|
||||
define("VERSION", "1.2.6");
|
||||
$debug = False;
|
||||
$ua = "'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116'";
|
||||
$timeout = 5;
|
||||
@ -396,9 +396,7 @@ function getEPG() {
|
||||
$ChannelSource = $ChannelInfo[2];
|
||||
$ChannelServiceId = $ChannelInfo[3];
|
||||
if($GLOBALS['debug']) printLog($ChannelName.' 채널 EPG 데이터를 가져오고 있습니다');
|
||||
if($ChannelSource == 'EPG') :
|
||||
GetEPGFromEPG($ChannelInfo);
|
||||
elseif($ChannelSource == 'KT') :
|
||||
if($ChannelSource == 'KT') :
|
||||
GetEPGFromKT($ChannelInfo);
|
||||
elseif($ChannelSource == 'LG') :
|
||||
GetEPGFromLG($ChannelInfo);
|
||||
@ -408,121 +406,11 @@ function getEPG() {
|
||||
GetEPGFromSKB($ChannelInfo);
|
||||
elseif($ChannelSource == 'NAVER') :
|
||||
GetEPGFromNaver($ChannelInfo);
|
||||
elseif($ChannelSource == 'ISCS') :
|
||||
GetEPGFromIscs($ChannelInfo);
|
||||
elseif($ChannelSource == 'POOQ') :
|
||||
GetEPGFromPooq($ChannelInfo);
|
||||
elseif($ChannelSource == 'EVERYON') :
|
||||
GetEPGFromEveryon($ChannelInfo);
|
||||
elseif($ChannelSource == 'OKSUSU') :
|
||||
GetEPGFromOksusu($ChannelInfo);
|
||||
elseif($ChannelSource == 'MBC') :
|
||||
GetEPGFromMbc($ChannelInfo);
|
||||
elseif($ChannelSource == 'MIL'):
|
||||
GetEPGFromMil($ChannelInfo);
|
||||
elseif($ChannelSource == 'IFM'):
|
||||
GetEPGFromIfm($ChannelInfo);
|
||||
elseif($ChannelSource == 'KBS'):
|
||||
GetEPGFromKbs($ChannelInfo);
|
||||
elseif($ChannelSource == 'ARIRANG'):
|
||||
GetEPGFromArirang($ChannelInfo);
|
||||
endif;
|
||||
endforeach;
|
||||
fprintf($fp, "</tv>\n");
|
||||
}
|
||||
|
||||
// Get EPG data from epg.co.kr
|
||||
function GetEPGFromEPG($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$epginfo = array();
|
||||
foreach(range(1, $GLOBALS['period']) as $k) :
|
||||
$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,
|
||||
'select_group' => '100',
|
||||
'start_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 :
|
||||
$response = str_replace("charset=euc-kr", "charset=utf-8", $response);
|
||||
$response = mb_convert_encoding($response, "UTF-8", "EUC-KR");
|
||||
$pattern = '/<td height="25" valign=top >(.*)<\/td>/';
|
||||
$response = preg_replace_callback($pattern, function($matches) { return '<td class="title">'.htmlspecialchars($matches[1], ENT_NOQUOTES).'</td>';}, $response);
|
||||
$response = str_replace(array('</b>', '</a>', '<img', 'valign=top>','align=absmiddle>'), array('', '</a>', '<img', '>','>'), $response);
|
||||
$dom = new DomDocument;
|
||||
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";
|
||||
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;
|
||||
$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);
|
||||
usleep(1000);
|
||||
endforeach;
|
||||
endfor;
|
||||
else:
|
||||
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
|
||||
endif;
|
||||
endif;
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from KT
|
||||
function GetEPGFromKT($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
@ -747,8 +635,8 @@ function GetEPGFromSKB($ChannelInfo) {
|
||||
if ($response === False && $GLOBALS['debug']) :
|
||||
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 = 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 class="round_flag flag02">(.*?)<\/span>/', '', $response);
|
||||
$response = preg_replace('/<span class="round_flag flag03">(.*?)<\/span>/', '', $response);
|
||||
@ -758,6 +646,8 @@ function GetEPGFromSKB($ChannelInfo) {
|
||||
$response = preg_replace('/<span class="round_flag flag11">(.*?)<\/span>/', '', $response);
|
||||
$response = preg_replace('/<span class="round_flag flag12">(.*?)<\/span>/', '', $response);
|
||||
$response = preg_replace('/<strong class="hide">프로그램 안내<\/strong>/', '', $response);
|
||||
$response = preg_replace_callback('/<p class="cont">(.*)/', 'converthtmlspecialchars', $response);
|
||||
$response = preg_replace_callback('/<p class="tit">(.*)/', 'converthtmlspecialchars', $response);
|
||||
$dom = new DomDocument;
|
||||
libxml_use_internal_errors(True);
|
||||
if($dom->loadHTML('<?xml encoding="utf-8" ?>'.$response)):
|
||||
@ -873,632 +763,6 @@ function GetEPGFromNaver($ChannelInfo) {
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from Iscs
|
||||
function GetEPGFromIscs($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$epginfo = array();
|
||||
$epginfo2 = array();
|
||||
foreach(range(1, $GLOBALS['period']) as $k) :
|
||||
$istomorrow = False;
|
||||
$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($data['result'] == 0) :
|
||||
if($GLOBALS['debug']) :
|
||||
printError($ChannelName.CHANNEL_ERROR);
|
||||
endif;
|
||||
else :
|
||||
$response = $data['html'];
|
||||
$dom = new DomDocument;
|
||||
libxml_use_internal_errors(True);
|
||||
|
||||
if($dom->loadHTML('<?xml encoding="utf-8" ?>'.$response)):
|
||||
$xpath = new DomXPath($dom);
|
||||
$query = "//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[5])) $subprogramName = trim($matches[5]) ?: "";
|
||||
if(isset($matches[3])) $episode = $matches[3] ?: "";
|
||||
if(isset($matches[7])) $rebroadcast = $matches[7] ? 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);
|
||||
usleep(1000);
|
||||
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;
|
||||
$epginfo= array_map("unserialize", array_unique(array_map("serialize", $epginfo)));
|
||||
if($epginfo) 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'])." days"));
|
||||
$url = "https://wapie.pooq.co.kr/v1/epgs30/".$ServiceId."/";
|
||||
$params = array(
|
||||
'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));
|
||||
$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'];
|
||||
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
|
||||
$epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating);
|
||||
usleep(1000);
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
} catch(Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endif;
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
# Get EPG data from EVERYON
|
||||
function GetEPGFromEveryon($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$epginfo = array();
|
||||
foreach(range(1, $GLOBALS['period']) as $k) :
|
||||
$url = "http://www.everyon.tv/mobile/schedule_ch.ptv";
|
||||
$day = date("Ymd", strtotime("+".($k - 1)." days"));
|
||||
$params = array(
|
||||
'chid' => $ServiceId,
|
||||
'date' => $day
|
||||
);
|
||||
$params = http_build_query($params);
|
||||
$method = "GET";
|
||||
try {
|
||||
$response = getWeb($url, $params, $method);
|
||||
if ($response === False && $GLOBALS['debug']) :
|
||||
printError($ChannelName.HTTP_ERROR);
|
||||
else :
|
||||
$response = mb_convert_encoding($response, "HTML-ENTITIES", "UTF-8");
|
||||
$dom = new DomDocument;
|
||||
libxml_use_internal_errors(True);
|
||||
if($dom->loadHTML($response)):
|
||||
$xpath = new DomXPath($dom);
|
||||
$query = "//ul[@class='lt2']";
|
||||
$rows = $xpath->query($query);
|
||||
foreach($rows as $row) :
|
||||
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
|
||||
$rebroadcast = False;
|
||||
$rating = 0;
|
||||
$startTime = trim($xpath->query("li[@class='pr_time']", $row)->item(0)->nodeValue) ?: "";
|
||||
|
||||
$startTime = date("YmdHis", strtotime($day." ".$startTime));
|
||||
$programName = trim($xpath->query("li[@class='pr_name']", $row)->item(0)->nodeValue) ?: "";
|
||||
if(in_array($programName, array("편성표가 곧 등록될 예정입니다.", "편성 정보가 없습니다."))) continue;
|
||||
$grade = trim($xpath->query("li[contains(@class,'img')]", $row)->item(0)->getAttribute('class'));
|
||||
$rating = str_replace(array("img ","c", "all"), array("", "", "0"), $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);
|
||||
usleep(1000);
|
||||
endforeach;
|
||||
else :
|
||||
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
|
||||
endif;
|
||||
endif;
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from OKSUSU
|
||||
function GetEPGFromOksusu($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$today = date("Ymd");
|
||||
$lastday = date("Ymd", strtotime("+".($GLOBALS['period'] - 1)." days"));
|
||||
$url = "http://seg.oksusu.com:8080/seg/index.php'";
|
||||
$params = array(
|
||||
'svc_id' => $ServiceId,
|
||||
'start_time' => $today.'00',
|
||||
'end_time' => $lastday.'24',
|
||||
'tgroup' => 'oksusutest_02|null',
|
||||
'IF' => 'IF-NSMEPG-003',
|
||||
'response_format' => 'json',
|
||||
'm' => 'ch_epg',
|
||||
'ver' => '1.0'
|
||||
);
|
||||
$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($data['channel'] == NULL) :
|
||||
if($GLOBALS['debug']) :
|
||||
printError($ChannelName.CHANNEL_ERROR);
|
||||
endif;
|
||||
else :
|
||||
$programs = $data['channel']['programs'];
|
||||
foreach ($programs as $program) :
|
||||
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
|
||||
$rebroadcast = False;
|
||||
$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]) ?: "";
|
||||
if(isset($matches[2])) $episode = str_replace("회", "", $matches[2]) ?: "";
|
||||
if(isset($matches[5])) $rebroadcast = $matches[5] ? True : False;
|
||||
endif;
|
||||
$startTime = date("YmdHis",$program['startTime']/1000);
|
||||
$endTime = date("YmdHis",$program['endTime']/1000);
|
||||
$desc = $program['synopsis'] ?: "";
|
||||
$actors =trim(str_replace('...','',$program['actorName']), ', ') ?: "";
|
||||
$producers = trim(str_replace('...','',$program['directorName']), ', ') ?: "";
|
||||
if ($program['mainGenreName'] != NULL) :
|
||||
$category = $program['mainGenreName'];
|
||||
else:
|
||||
$category = "";
|
||||
endif;
|
||||
$rating = $program['ratingCd'] ?: 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);
|
||||
usleep(1000);
|
||||
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 Radio
|
||||
function GetEPGFromMbc($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$dayofweek = array('일', '월', '화', '수', '목', '금', '토');
|
||||
foreach(range(1, $GLOBALS['period']) as $k) :
|
||||
$url = "http://miniunit.imbc.com/Schedule";
|
||||
$day = date("Y-m-d", strtotime("+".($k - 1)." days"));
|
||||
$params = array(
|
||||
'rtype' => 'json'
|
||||
);
|
||||
$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(count($data['Programs']) == 0) :
|
||||
if($GLOBALS['debug']) :
|
||||
printError($ChannelName.CHANNEL_ERROR);
|
||||
endif;
|
||||
else :
|
||||
$programs = $data['Programs'];
|
||||
foreach($programs as $program) :
|
||||
if($program['Channel'] == "CHAM" && $program['LiveDays'] == $dayofweek[date("w", strtotime($day))]) :
|
||||
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
|
||||
$rebroadcast = False;
|
||||
$rating = 0;
|
||||
$pattern = '/^(.*?)(\(재\))?$/';
|
||||
preg_match($pattern, htmlspecialchars_decode($program['ProgramTitle']), $matches);
|
||||
if ($matches != NULL) :
|
||||
$programName = $matches[1];
|
||||
if(isset($matches[2])) $rebroadcast = $matches[2] ? True : False;
|
||||
endif;
|
||||
$startTime = $day." ".$program['StartTime'];
|
||||
$startTime = date("YmdHis", strtotime($startTime));
|
||||
$endTime = date("YmdHis", strtotime("+".$program['RunningTime']." minutes", strtotime($startTime)));
|
||||
$category = "음악";
|
||||
$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);
|
||||
usleep(1000);
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
} catch(Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endif;
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
|
||||
// Get EPG data from MIL Radio
|
||||
function GetEPGFromMil($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
foreach(range(1, $GLOBALS['period']) as $k) :
|
||||
$url = "http://radio.dema.mil.kr/web/fm/quick/ajaxTimetableList.do";
|
||||
$day = date("Y-m-d", strtotime("+".($k - 1)." days"));
|
||||
$params = array(
|
||||
'program_date' => date("Ymd", strtotime($day))
|
||||
);
|
||||
$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(count($data['resultList']) == 0) :
|
||||
if($GLOBALS['debug']) :
|
||||
printError($ChannelName.CHANNEL_ERROR);
|
||||
endif;
|
||||
else :
|
||||
$programs = $data['resultList'];
|
||||
foreach($programs as $program) :
|
||||
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
|
||||
$rebroadcast = False;
|
||||
$rating = 0;
|
||||
$pattern = '/^(.*?)(\(재\))?$/';
|
||||
preg_match($pattern, htmlspecialchars_decode($program['program_title']), $matches);
|
||||
if ($matches != NULL) :
|
||||
$programName = $matches[1];
|
||||
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));
|
||||
$actors = htmlspecialchars_decode($program['movie_actor']);
|
||||
$producers = htmlspecialchars_decode($program['movie_director']);
|
||||
$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);
|
||||
usleep(1000);
|
||||
endforeach;
|
||||
endif;
|
||||
} catch(Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endif;
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
|
||||
// Get EPG data from IFM Radio
|
||||
function GetEPGFromIfm($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$dayofweek = array('1', '2', '3', '4', '5', '6', '7');
|
||||
foreach(range(1, $GLOBALS['period']) as $k) :
|
||||
$url = "http://mapp.itvfm.co.kr/hyb/front/selectHybPgmList.do";
|
||||
$day = date("Y-m-d", strtotime("+".($k - 1)." days"));
|
||||
$params = array(
|
||||
'outDay' => $dayofweek[(date("w", strtotime($day)+1))%7],
|
||||
'viewDt' => $day
|
||||
);
|
||||
$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(count($data['hybMusicInfoList']) == 0) :
|
||||
if($GLOBALS['debug']) :
|
||||
printError($ChannelName.CHANNEL_ERROR);
|
||||
endif;
|
||||
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']) ?: "";
|
||||
$startTime = $day." ".$program['pgmStime'];
|
||||
$startTime = date("YmdHis", strtotime($startTime));
|
||||
$endTime = $day." ".$program['pgmEtime'];
|
||||
$endTime = date("YmdHis", strtotime($endTime));
|
||||
$actors = htmlspecialchars_decode($program['pgmDj']);
|
||||
$producers = htmlspecialchars_decode($program['pgmPd']);
|
||||
$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);
|
||||
usleep(1000);
|
||||
endforeach;
|
||||
endif;
|
||||
} catch(Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endif;
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
}
|
||||
|
||||
// Get EPG data from KBS Radio
|
||||
function GetEPGFromKbs($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$epginfo = array();
|
||||
foreach(range(1, $GLOBALS['period']) as $k) :
|
||||
$url = "http://world.kbs.co.kr/include/wink/_ajax_schedule.php";
|
||||
$day = date("Y-m-d", strtotime("+".($k - 1)." days"));
|
||||
$params = array(
|
||||
'channel'=>'wink_11'
|
||||
);
|
||||
$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(count($data['schedule']) == 0) :
|
||||
if($GLOBALS['debug']) :
|
||||
printError($ChannelName.CHANNEL_ERROR);
|
||||
endif;
|
||||
else :
|
||||
$dom = new DomDocument;
|
||||
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);
|
||||
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
|
||||
$epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating);
|
||||
usleep(1000);
|
||||
endforeach;
|
||||
endif;
|
||||
} catch(Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endif;
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from Arirang Radio
|
||||
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);
|
||||
$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);
|
||||
usleep(1000);
|
||||
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) {
|
||||
$epg1 = current($epginfo);
|
||||
@ -1652,7 +916,6 @@ function getWeb($url, $params, $method) {
|
||||
curl_setopt($ch, CURLOPT_HEADER, False);
|
||||
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);
|
||||
@ -1686,6 +949,10 @@ function startsWith($haystack, $needle) {
|
||||
return !strncmp($haystack, $needle, strlen($needle));
|
||||
}
|
||||
|
||||
function converthtmlspecialchars($match) {
|
||||
return '<p class="cont">'.htmlspecialchars($match[1]);
|
||||
}
|
||||
|
||||
//사용방법
|
||||
$usage = <<<USAGE
|
||||
usage: epg2xml.py [-h] [-i {ALL,KT,LG,SK}] [-v | -d | -o [xmltv.xml] | -s
|
||||
|
Loading…
x
Reference in New Issue
Block a user