커넥션 에러 관련 예외 처리 추가
This commit is contained in:
parent
2b6bf969af
commit
6ef42e0082
68
epg2xml.php
68
epg2xml.php
@ -3,7 +3,7 @@
|
|||||||
@date_default_timezone_set('Asia/Seoul');
|
@date_default_timezone_set('Asia/Seoul');
|
||||||
error_reporting(E_ALL ^ E_NOTICE);
|
error_reporting(E_ALL ^ E_NOTICE);
|
||||||
if (PHP_SAPI != "cli") header("Content-Type: application/xml; charset=utf-8");
|
if (PHP_SAPI != "cli") header("Content-Type: application/xml; charset=utf-8");
|
||||||
define("VERSION", "1.1.9");
|
define("VERSION", "1.2.0");
|
||||||
|
|
||||||
$debug = False;
|
$debug = False;
|
||||||
$ua = "User-Agent: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36', accept: '*/*'";
|
$ua = "User-Agent: 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36', accept: '*/*'";
|
||||||
@ -415,15 +415,15 @@ function GetEPGFromEPG($ChannelInfo) {
|
|||||||
'start_date' => $day
|
'start_date' => $day
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "POST";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 = str_replace("charset=euc-kr", "charset=utf-8", $response);
|
$response = str_replace("charset=euc-kr", "charset=utf-8", $response);
|
||||||
$dom = new DomDocument;
|
$dom = new DomDocument;
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(True);
|
||||||
$dom->loadHTML(mb_convert_encoding($response, "UTF-8", "EUC-KR"));
|
$dom->loadHTML(mb_convert_encoding($response, "UTF-8", "EUC-KR"));
|
||||||
$xpath = new DomXPath($dom);
|
$xpath = new DomXPath($dom);
|
||||||
for($i = 2; $i < 5; $i++) :
|
for($i = 2; $i < 5; $i++) :
|
||||||
@ -526,15 +526,15 @@ function GetEPGFromKT($ChannelInfo) {
|
|||||||
'tab_no' => '1'
|
'tab_no' => '1'
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "GET";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 = str_replace("charset=euc-kr", "charset=utf-8", $response);
|
$response = str_replace("charset=euc-kr", "charset=utf-8", $response);
|
||||||
$dom = new DomDocument;
|
$dom = new DomDocument;
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(True);
|
||||||
$dom->loadHTML(mb_convert_encoding($response, "UTF-8", "EUC-KR"));
|
$dom->loadHTML(mb_convert_encoding($response, "UTF-8", "EUC-KR"));
|
||||||
$xpath = new DomXPath($dom);
|
$xpath = new DomXPath($dom);
|
||||||
$query = "//table[@id='pop_day']/tbody/tr";
|
$query = "//table[@id='pop_day']/tbody/tr";
|
||||||
@ -601,15 +601,15 @@ function GetEPGFromLG($ChannelInfo) {
|
|||||||
'evntCmpYmd' => $day
|
'evntCmpYmd' => $day
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "POST";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'.$response;
|
$response = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'.$response;
|
||||||
$dom = new DomDocument;
|
$dom = new DomDocument;
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(True);
|
||||||
$response = mb_convert_encoding($response, "UTF-8", "EUC-KR");
|
$response = mb_convert_encoding($response, "UTF-8", "EUC-KR");
|
||||||
$response = str_replace(array('<재>', ' [..', ' (..'), array('<재>', '', ''), $response);
|
$response = str_replace(array('<재>', ' [..', ' (..'), array('<재>', '', ''), $response);
|
||||||
$dom->loadHTML($response);
|
$dom->loadHTML($response);
|
||||||
@ -682,9 +682,9 @@ function GetEPGFromSK($ChannelInfo) {
|
|||||||
'pcode' => '|^|start_time='.$today.'00|^|end_time='.$lastday.'24|^|svc_id='.$ServiceId
|
'pcode' => '|^|start_time='.$today.'00|^|end_time='.$lastday.'24|^|svc_id='.$ServiceId
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "POST";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 :
|
||||||
@ -761,9 +761,9 @@ function GetEPGFromSKY($ChannelInfo) {
|
|||||||
'indate_type' => 'now'
|
'indate_type' => 'now'
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "POST";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 :
|
||||||
@ -847,9 +847,9 @@ function GetEPGFromNaver($ChannelInfo) {
|
|||||||
'where' => 'nexearch'
|
'where' => 'nexearch'
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "GET";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 :
|
||||||
@ -940,9 +940,9 @@ function GetEPGFromMbc($ChannelInfo) {
|
|||||||
'rtype' => 'json'
|
'rtype' => 'json'
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "GET";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 :
|
||||||
@ -1014,9 +1014,9 @@ function GetEPGFromMil($ChannelInfo) {
|
|||||||
'program_date' => date("Ymd", strtotime($day))
|
'program_date' => date("Ymd", strtotime($day))
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "GET";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 :
|
||||||
@ -1089,9 +1089,9 @@ function GetEPGFromIfm($ChannelInfo) {
|
|||||||
'viewDt' => $day
|
'viewDt' => $day
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "GET";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 :
|
||||||
@ -1158,9 +1158,9 @@ function GetEPGFromKbs($ChannelInfo) {
|
|||||||
'channel'=>'wink_11'
|
'channel'=>'wink_11'
|
||||||
);
|
);
|
||||||
$params = http_build_query($params);
|
$params = http_build_query($params);
|
||||||
$url = $url."?".$params;
|
$method = "GET";
|
||||||
try {
|
try {
|
||||||
$response = getWeb($url);
|
$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 :
|
||||||
@ -1173,7 +1173,7 @@ function GetEPGFromKbs($ChannelInfo) {
|
|||||||
endif;
|
endif;
|
||||||
else :
|
else :
|
||||||
$dom = new DomDocument;
|
$dom = new DomDocument;
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(True);
|
||||||
$dom->loadHTML($data['schedule']);
|
$dom->loadHTML($data['schedule']);
|
||||||
$xpath = new DomXPath($dom);
|
$xpath = new DomXPath($dom);
|
||||||
$query = "//li";
|
$query = "//li";
|
||||||
@ -1314,16 +1314,26 @@ function writeProgram($programdata) {
|
|||||||
endif;
|
endif;
|
||||||
fprintf($fp, " </programme>\n");
|
fprintf($fp, " </programme>\n");
|
||||||
}
|
}
|
||||||
function getWeb($url) {
|
function getWeb($url, $params, $method) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
if($method == "GET"):
|
||||||
|
$url = $url."?".$params;
|
||||||
|
elseif($method == "POST"):
|
||||||
|
curl_setopt ($ch, CURLOPT_POST, True);
|
||||||
|
curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
|
||||||
|
endif;
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER,True);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['ua']);
|
curl_setopt($ch, CURLOPT_HEADER, False);
|
||||||
|
curl_setopt($ch, CURLOPT_FAILONERROR,True);
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['ua']);
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
|
if(curl_error($ch) && $GLOBALS['debug']) printError($url." ".curl_error($ch));
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
function printLog($string) {
|
function printLog($string) {
|
||||||
fwrite(STDERR, $string."\n");
|
fwrite(STDERR, $string."\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user