HCN, ISCS 함수 수정, 웹페이지 패치시 시간 간격 추가

This commit is contained in:
wonipapa 2017-09-06 14:36:32 +09:00
parent 89f9c4f839
commit 92eb54eafd
2 changed files with 66 additions and 54 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
@date_default_timezone_set('Asia/Seoul'); @date_default_timezone_set('Asia/Seoul');
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
@set_time_limit(0);
define("VERSION", "1.2.2"); define("VERSION", "1.2.2");
$debug = False; $debug = False;
@ -471,6 +472,7 @@ function GetEPGFromEPG($ChannelInfo) {
endforeach; endforeach;
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
endfor; endfor;
else: else:
@ -533,6 +535,7 @@ function GetEPGFromKT($ChannelInfo) {
$rating = str_replace("all", 0, str_replace("세 이상", "", trim($cells->item(2)->nodeValue))); $rating = str_replace("all", 0, str_replace("세 이상", "", trim($cells->item(2)->nodeValue)));
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
else : else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -594,6 +597,7 @@ function GetEPGFromLG($ChannelInfo) {
$rating = trim($spans->item(1)->nodeValue)=="All" ? 0 : trim($spans->item(1)->nodeValue); $rating = trim($spans->item(1)->nodeValue)=="All" ? 0 : trim($spans->item(1)->nodeValue);
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
else : else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -672,6 +676,7 @@ function GetEPGFromSK($ChannelInfo) {
'rating' => $rating 'rating' => $rating
); );
writeProgram($programdata); writeProgram($programdata);
usleep(1000);
endforeach; endforeach;
endif; endif;
} catch(Exception $e) { } catch(Exception $e) {
@ -739,6 +744,7 @@ function GetEPGFromSKB($ChannelInfo) {
if($cells->length > 3) $rating = str_replace('세', '', $cells->item(3)->nodeValue) ?: 0; if($cells->length > 3) $rating = str_replace('세', '', $cells->item(3)->nodeValue) ?: 0;
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
else : else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -820,6 +826,7 @@ function GetEPGFromSKY($ChannelInfo) {
'rating' => $rating 'rating' => $rating
); );
writeProgram($programdata); writeProgram($programdata);
usleep(1000);
endforeach; endforeach;
endif; endif;
} catch(Exception $e) { } catch(Exception $e) {
@ -889,6 +896,7 @@ function GetEPGFromNaver($ChannelInfo) {
$rating = $program['grade']; $rating = $program['grade'];
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
endfor; endfor;
endfor; endfor;
@ -910,11 +918,12 @@ function GetEPGFromIscs($ChannelInfo) {
$ServiceId = $ChannelInfo[3]; $ServiceId = $ChannelInfo[3];
$epginfo = array(); $epginfo = array();
foreach(range(1, $GLOBALS['period']) as $k) : foreach(range(1, $GLOBALS['period']) as $k) :
$url = "https://www.iscs.co.kr/service/sub/ajax_channel_view.asp"; $url = "http://m.iscs.co.kr/sub/02/data.asp";
$day = date("Y-m-d", strtotime("+".($k - 1)." days")); $day = date("Y-m-d", strtotime("+".($k - 1)." days"));
$params = array( $params = array(
's_idx' => $ServiceId, 'Exec_Mode' => 'view',
'C_date' => $day 'Source_Id' => $ServiceId,
'Ch_Day' => $day
); );
$params = http_build_query($params); $params = http_build_query($params);
$method = "POST"; $method = "POST";
@ -926,43 +935,33 @@ function GetEPGFromIscs($ChannelInfo) {
try { try {
$data = json_decode($response, TRUE); $data = json_decode($response, TRUE);
if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR); if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR);
if(count($data['html']) == 0) : if(count($data['total']) == 0) :
if($GLOBALS['debug']) : if($GLOBALS['debug']) :
printError($ChannelName.CHANNEL_ERROR); printError($ChannelName.CHANNEL_ERROR);
endif; endif;
else : else :
$response = $data['html']; $programs = $data['list'];
$pattern = '/<td class="name">(.*)<\/td>/'; foreach($programs as $program) :
$response = preg_replace_callback($pattern, function($matches) { return '<td class="name">'.htmlspecialchars($matches[1]).'</td>';}, $response);
$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 = "//div[@class='pp_tbl']/table/tbody/tr";
$rows = $xpath->query($query);
foreach($rows as $row) :
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
$rebroadcast = False; $rebroadcast = False;
$rating = 0; $rating = 0;
$cells = $row->getElementsByTagName('td'); $startTime = date("YmdHis", strtotime($day." ".$program['Time']));
$startTime = $cells->item(0)->nodeValue ?: "";
$startTime = date("YmdHis", strtotime($day." ".$startTime));
$programName = trim($cells->item(1)->nodeValue) ?: "";
$pattern = '/^(.*?)(?:\(([\d,]+)회\))?(?:\((재)\))?$/'; $pattern = '/^(.*?)(?:\(([\d,]+)회\))?(?:\((재)\))?$/';
preg_match($pattern, $programName, $matches); preg_match($pattern, trim($program['Pg_Name']), $matches);
if ($matches != NULL) : if ($matches != NULL) :
if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; if(isset($matches[1])) $programName = trim($matches[1]) ?: "";
if(isset($matches[2])) $episode = $matches[2] ?: ""; if(isset($matches[2])) $episode = $matches[2] ?: "";
if(isset($matches[3])) $rebroadcast = $matches[3] ? True : False; if(isset($matches[3])) $rebroadcast = $matches[3] ? True : False;
endif; endif;
$rating = $cells->item(2)->nodeValue=='전체관람' ? 0 : str_replace('세이상', '', $cells->item(2)->nodeValue); if($program['Rating'] == '모든연령'):
$rating = 0;
else:
$rating = str_replace("세이상","", $program['Rating']);
endif;
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
endif;
endif; endif;
} catch(Exception $e) { } catch(Exception $e) {
if($GLOBALS['debug']) printError($e->getMessage()); if($GLOBALS['debug']) printError($e->getMessage());
@ -982,38 +981,36 @@ function GetEPGFromHcn($ChannelInfo) {
$ServiceId = $ChannelInfo[3]; $ServiceId = $ChannelInfo[3];
$epginfo = array(); $epginfo = array();
foreach(range(1, $GLOBALS['period']) as $k) : foreach(range(1, $GLOBALS['period']) as $k) :
$url = "https://www.hcn.co.kr/ur/bs/ch/channelInfo.hcn"; $url = "http://m.hcn.co.kr/sch_ScheduleList.action";
$day = date("Y-m-d", strtotime("+".($k - 1)." days")); $day = date("Y-m-d", strtotime("+".($k - 1)." days"));
$params = array( $params = array(
'method' => 'ajax_00',
'pageType' => 'sheetList',
'ch_id' => $ServiceId, 'ch_id' => $ServiceId,
'onairdate' => $day 'onairdate' => $day,
'_' => _microtime()
); );
$params = http_build_query($params); $params = http_build_query($params);
$method = "POST"; $method = "GET";
try { try {
$response = getWeb($url, $params, $method); $response = getWeb($url, $params, $method);
if ($response === False && $GLOBALS['debug']) : if ($response === False && $GLOBALS['debug']) :
printError($ChannelName.HTTP_ERROR); printError($ChannelName.HTTP_ERROR);
else : else :
$response = mb_convert_encoding($response, "HTML-ENTITIES", "EUC-KR"); $response = mb_convert_encoding($response, "HTML-ENTITIES", "UTF-8");
$dom = new DomDocument; $dom = new DomDocument;
libxml_use_internal_errors(True); libxml_use_internal_errors(True);
if($dom->loadHTML($response)): if($dom->loadHTML($response)):
$xpath = new DomXPath($dom); $xpath = new DomXPath($dom);
$query = "//tr[@class='']"; $query = "//li";
$rows = $xpath->query($query); $rows = $xpath->query($query);
foreach($rows as $row) : foreach($rows as $row) :
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
$rebroadcast = False; $rebroadcast = False;
$rating = 0; $rating = 0;
$cells = $row->getElementsByTagName('td'); $startTime = trim($xpath->query("span[@class='progTime']", $row)->item(0)->nodeValue) ?: "";
$startTime = $cells->item(0)->nodeValue ?: "";
$startTime = date("YmdHis", strtotime($day." ".$startTime)); $startTime = date("YmdHis", strtotime($day." ".$startTime));
$programName = trim($cells->item(1)->nodeValue) ?: ""; $programName = trim($xpath->query("span[@class='progTitle']", $row)->item(0)->nodeValue) ?: "";
$category = trim($cells->item(2)->nodeValue) ?: ""; //$category = trim($cells->item(2)->nodeValue) ?: "";
$category = preg_replace('/\(.*\)/', '', $category); //$category = preg_replace('/\(.*\)/', '', $category);
$images = $row->getElementsByTagName('img'); $images = $row->getElementsByTagName('img');
foreach($images as $image): foreach($images as $image):
preg_match('/re\.png/', $image->getAttribute('src'), $rebroad); preg_match('/re\.png/', $image->getAttribute('src'), $rebroad);
@ -1023,6 +1020,7 @@ function GetEPGFromHcn($ChannelInfo) {
endforeach; endforeach;
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
else : else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -1107,6 +1105,7 @@ function GetEPGFromPooq($ChannelInfo) {
'rating' => $rating 'rating' => $rating
); );
writeProgram($programdata); writeProgram($programdata);
usleep(1000);
endif; endif;
endforeach; endforeach;
endif; endif;
@ -1177,6 +1176,7 @@ function GetEPGFromMbc($ChannelInfo) {
'rating' => $rating 'rating' => $rating
); );
writeProgram($programdata); writeProgram($programdata);
usleep(1000);
endif; endif;
endforeach; endforeach;
endif; endif;
@ -1249,6 +1249,7 @@ function GetEPGFromMil($ChannelInfo) {
'rating' => $rating 'rating' => $rating
); );
writeProgram($programdata); writeProgram($programdata);
usleep(1000);
endforeach; endforeach;
endif; endif;
} catch(Exception $e) { } catch(Exception $e) {
@ -1316,6 +1317,7 @@ function GetEPGFromIfm($ChannelInfo) {
'rating' => $rating 'rating' => $rating
); );
writeProgram($programdata); writeProgram($programdata);
usleep(1000);
endforeach; endforeach;
endif; endif;
} catch(Exception $e) { } catch(Exception $e) {
@ -1372,6 +1374,7 @@ function GetEPGFromKbs($ChannelInfo) {
$programName = str_replace(array("[","]", " Broadcast"), array("", "", ""), $programName); $programName = str_replace(array("[","]", " Broadcast"), array("", "", ""), $programName);
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating //ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
$epginfo[] = array($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; endforeach;
endif; endif;
} catch(Exception $e) { } catch(Exception $e) {
@ -1447,6 +1450,7 @@ function GetEPGFromArirang($ChannelInfo) {
'rating' => $rating 'rating' => $rating
); );
writeProgram($programdata); writeProgram($programdata);
usleep(1000);
endforeach; endforeach;
else : else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -1492,6 +1496,7 @@ function epgzip($epginfo) {
writeProgram($programdata); writeProgram($programdata);
endforeach; endforeach;
} }
function writeProgram($programdata) { function writeProgram($programdata) {
$fp = $GLOBALS['fp']; $fp = $GLOBALS['fp'];
$ChannelId = $programdata['channelId']; $ChannelId = $programdata['channelId'];
@ -1594,6 +1599,7 @@ function writeProgram($programdata) {
endif; endif;
fprintf($fp, " </programme>\n"); fprintf($fp, " </programme>\n");
} }
function getWeb($url, $params, $method) { function getWeb($url, $params, $method) {
$ch = curl_init(); $ch = curl_init();
if($method == "GET"): if($method == "GET"):
@ -1623,4 +1629,9 @@ function printError($string) {
header("Content-Type: text/plain; charset=utf-8"); header("Content-Type: text/plain; charset=utf-8");
print("Error : ".$string."\n"); print("Error : ".$string."\n");
} }
function _microtime() {
list($usec, $sec) = explode(" ", microtime());
return ($sec.(int)($usec*1000));
}
?> ?>

View File

@ -1514,6 +1514,7 @@ function epgzip($epginfo) {
writeProgram($programdata); writeProgram($programdata);
endforeach; endforeach;
} }
function writeProgram($programdata) { function writeProgram($programdata) {
$fp = $GLOBALS['fp']; $fp = $GLOBALS['fp'];
$ChannelId = $programdata['channelId']; $ChannelId = $programdata['channelId'];
@ -1616,6 +1617,7 @@ function writeProgram($programdata) {
endif; endif;
fprintf($fp, " </programme>\n"); fprintf($fp, " </programme>\n");
} }
function getWeb($url, $params, $method) { function getWeb($url, $params, $method) {
$ch = curl_init(); $ch = curl_init();
if($method == "GET"): if($method == "GET"):
@ -1644,8 +1646,7 @@ function printError($string) {
fwrite(STDERR, "Error : ".$string."\n"); fwrite(STDERR, "Error : ".$string."\n");
} }
function _microtime() function _microtime() {
{
list($usec, $sec) = explode(" ", microtime()); list($usec, $sec) = explode(" ", microtime());
return ($sec.(int)($usec*1000)); return ($sec.(int)($usec*1000));
} }