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
@date_default_timezone_set('Asia/Seoul');
error_reporting(E_ALL ^ E_NOTICE);
@set_time_limit(0);
define("VERSION", "1.2.2");
$debug = False;
@ -471,6 +472,7 @@ function GetEPGFromEPG($ChannelInfo) {
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:
@ -533,6 +535,7 @@ function GetEPGFromKT($ChannelInfo) {
$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);
usleep(1000);
endforeach;
else :
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);
//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);
@ -672,6 +676,7 @@ function GetEPGFromSK($ChannelInfo) {
'rating' => $rating
);
writeProgram($programdata);
usleep(1000);
endforeach;
endif;
} catch(Exception $e) {
@ -739,6 +744,7 @@ function GetEPGFromSKB($ChannelInfo) {
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);
usleep(1000);
endforeach;
else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -819,7 +825,8 @@ function GetEPGFromSKY($ChannelInfo) {
'rebroadcast' => $rebroadcast,
'rating' => $rating
);
writeProgram($programdata);
writeProgram($programdata);
usleep(1000);
endforeach;
endif;
} catch(Exception $e) {
@ -889,6 +896,7 @@ function GetEPGFromNaver($ChannelInfo) {
$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);
usleep(1000);
endforeach;
endfor;
endfor;
@ -910,11 +918,12 @@ function GetEPGFromIscs($ChannelInfo) {
$ServiceId = $ChannelInfo[3];
$epginfo = array();
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"));
$params = array(
's_idx' => $ServiceId,
'C_date' => $day
'Exec_Mode' => 'view',
'Source_Id' => $ServiceId,
'Ch_Day' => $day
);
$params = http_build_query($params);
$method = "POST";
@ -926,43 +935,33 @@ function GetEPGFromIscs($ChannelInfo) {
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(count($data['total']) == 0) :
if($GLOBALS['debug']) :
printError($ChannelName.CHANNEL_ERROR);
endif;
else :
$response = $data['html'];
$pattern = '/<td class="name">(.*)<\/td>/';
$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 = "";
$rebroadcast = False;
$programs = $data['list'];
foreach($programs as $program) :
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
$rebroadcast = False;
$rating = 0;
$startTime = date("YmdHis", strtotime($day." ".$program['Time']));
$pattern = '/^(.*?)(?:\(([\d,]+)회\))?(?:\((재)\))?$/';
preg_match($pattern, trim($program['Pg_Name']), $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;
if($program['Rating'] == '모든연령'):
$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;
else:
$rating = str_replace("세이상","", $program['Rating']);
endif;
//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());
@ -982,38 +981,36 @@ function GetEPGFromHcn($ChannelInfo) {
$ServiceId = $ChannelInfo[3];
$epginfo = array();
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"));
$params = array(
'method' => 'ajax_00',
'pageType' => 'sheetList',
'ch_id' => $ServiceId,
'onairdate' => $day
'onairdate' => $day,
'_' => _microtime()
);
$params = http_build_query($params);
$method = "POST";
$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", "EUC-KR");
$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 = "//tr[@class='']";
$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('td');
$startTime = $cells->item(0)->nodeValue ?: "";
$startTime = trim($xpath->query("span[@class='progTime']", $row)->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);
$programName = trim($xpath->query("span[@class='progTitle']", $row)->item(0)->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);
@ -1023,6 +1020,7 @@ function GetEPGFromHcn($ChannelInfo) {
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;
else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -1107,6 +1105,7 @@ function GetEPGFromPooq($ChannelInfo) {
'rating' => $rating
);
writeProgram($programdata);
usleep(1000);
endif;
endforeach;
endif;
@ -1177,6 +1176,7 @@ function GetEPGFromMbc($ChannelInfo) {
'rating' => $rating
);
writeProgram($programdata);
usleep(1000);
endif;
endforeach;
endif;
@ -1248,7 +1248,8 @@ function GetEPGFromMil($ChannelInfo) {
'rebroadcast' => $rebroadcast,
'rating' => $rating
);
writeProgram($programdata);
writeProgram($programdata);
usleep(1000);
endforeach;
endif;
} catch(Exception $e) {
@ -1315,7 +1316,8 @@ function GetEPGFromIfm($ChannelInfo) {
'rebroadcast' => $rebroadcast,
'rating' => $rating
);
writeProgram($programdata);
writeProgram($programdata);
usleep(1000);
endforeach;
endif;
} catch(Exception $e) {
@ -1371,7 +1373,8 @@ function GetEPGFromKbs($ChannelInfo) {
$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);
$epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating);
usleep(1000);
endforeach;
endif;
} catch(Exception $e) {
@ -1446,7 +1449,8 @@ function GetEPGFromArirang($ChannelInfo) {
'rebroadcast' => $rebroadcast,
'rating' => $rating
);
writeProgram($programdata);
writeProgram($programdata);
usleep(1000);
endforeach;
else :
if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR);
@ -1492,6 +1496,7 @@ function epgzip($epginfo) {
writeProgram($programdata);
endforeach;
}
function writeProgram($programdata) {
$fp = $GLOBALS['fp'];
$ChannelId = $programdata['channelId'];
@ -1594,6 +1599,7 @@ function writeProgram($programdata) {
endif;
fprintf($fp, " </programme>\n");
}
function getWeb($url, $params, $method) {
$ch = curl_init();
if($method == "GET"):
@ -1623,4 +1629,9 @@ function printError($string) {
header("Content-Type: text/plain; charset=utf-8");
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);
endforeach;
}
function writeProgram($programdata) {
$fp = $GLOBALS['fp'];
$ChannelId = $programdata['channelId'];
@ -1616,6 +1617,7 @@ function writeProgram($programdata) {
endif;
fprintf($fp, " </programme>\n");
}
function getWeb($url, $params, $method) {
$ch = curl_init();
if($method == "GET"):
@ -1644,8 +1646,7 @@ function printError($string) {
fwrite(STDERR, "Error : ".$string."\n");
}
function _microtime()
{
function _microtime() {
list($usec, $sec) = explode(" ", microtime());
return ($sec.(int)($usec*1000));
}