From 9c57912dd01e66f376c7dde9542a345ef214dae0 Mon Sep 17 00:00:00 2001 From: wonipapa Date: Fri, 19 May 2017 10:27:29 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95,=20file?= =?UTF-8?q?=5Fget=5Fcontents=20=ED=95=A8=EC=88=98=20curl=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epg2xml.php | 108 +++++++++++++++------------------------------------- 1 file changed, 31 insertions(+), 77 deletions(-) diff --git a/epg2xml.php b/epg2xml.php index 8bdfb99..a145719 100644 --- a/epg2xml.php +++ b/epg2xml.php @@ -2,7 +2,9 @@ array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); - $epginfo = array(); foreach(range(1, $GLOBALS['period']) as $k) : $url = "http://www.epg.co.kr/epg-cgi/extern/cnm_guide_type_v070530.cgi"; $day = date("Ymd", strtotime("+".($k - 1)." days")); @@ -416,7 +415,7 @@ function GetEPGFromEPG($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -514,13 +513,6 @@ function GetEPGFromKT($ChannelInfo) { $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; $epginfo = array(); - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); - $epginfo = array(); foreach(range(1, $GLOBALS['period']) as $k) : $url = "http://tv.olleh.com/renewal_sub/liveTv/pop_schedule_week.asp"; $day = date("Ymd", strtotime("+".($k - 1)." days")); @@ -534,7 +526,7 @@ function GetEPGFromKT($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -599,13 +591,6 @@ function GetEPGFromLG($ChannelInfo) { $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; $epginfo = array(); - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); - $epginfo = array(); foreach(range(1, $GLOBALS['period']) as $k) : $url = "http://www.uplus.co.kr/css/chgi/chgi/RetrieveTvSchedule.hpi"; $day = date("Ymd", strtotime("+".($k - 1)." days")); @@ -616,7 +601,7 @@ function GetEPGFromLG($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -689,12 +674,6 @@ function GetEPGFromSK($ChannelInfo) { $ServiceId = $ChannelInfo[3]; $today = date("Ymd"); $lastday = date("Ymd", strtotime("+".($GLOBALS['period'] - 1)." days")); - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); $url = "http://m.btvplus.co.kr/Common/Inc/IFGetData.asp"; $params = array( 'variable' => 'IF_LIVECHART_DETAIL', @@ -703,7 +682,7 @@ function GetEPGFromSK($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -770,12 +749,6 @@ function GetEPGFromSKY($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; - $options = array( - 'http' => array( - 'method' => 'POST', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); foreach(range(1, $GLOBALS['period']) as $k) : $url = "http://www.skylife.co.kr/channel/epg/channelScheduleListJson.do"; $day = date("Y-m-d", strtotime("+".($k - 1)." days")); @@ -788,7 +761,7 @@ function GetEPGFromSKY($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -850,12 +823,6 @@ function GetEPGFromNaver($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); $epginfo = array(); $totaldate = array(); foreach(range(1, $GLOBALS['period']) as $k) : @@ -880,7 +847,7 @@ function GetEPGFromNaver($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -963,12 +930,6 @@ function GetEPGFromMbc($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); $dayofweek = array('일', '월', '화', '수', '목', '금', '토'); foreach(range(1, $GLOBALS['period']) as $k) : $url = "http://miniunit.imbc.com/Schedule"; @@ -979,7 +940,7 @@ function GetEPGFromMbc($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -1044,12 +1005,6 @@ function GetEPGFromMil($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); 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")); @@ -1059,7 +1014,7 @@ function GetEPGFromMil($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -1123,12 +1078,6 @@ function GetEPGFromIfm($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); $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"; @@ -1140,7 +1089,7 @@ function GetEPGFromIfm($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -1199,12 +1148,6 @@ function GetEPGFromKbs($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; $ServiceId = $ChannelInfo[3]; - $options = array( - 'http' => array( - 'method' => 'GET', - 'header'=> $GLOBALS['ua'] - )); - $context = stream_context_create($options); $epginfo = array(); foreach(range(1, $GLOBALS['period']) as $k) : $url = "http://world.kbs.co.kr/include/wink/_ajax_schedule.php"; @@ -1215,7 +1158,7 @@ function GetEPGFromKbs($ChannelInfo) { $params = http_build_query($params); $url = $url."?".$params; try { - $response = @file_get_contents($url, False, $context); + $response = getWeb($url); if ($response === False && $GLOBALS['debug']) : printError($ChannelName.HTTP_ERROR); else : @@ -1369,10 +1312,21 @@ function writeProgram($programdata) { endif; fprintf($fp, " \n"); } -function printLog($args) { - fwrite(STDERR, $args."\n"); +function getWeb($url) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['ua']); + $response = curl_exec($ch); + curl_close($ch); + return $response; } -function printError($args) { - fwrite(STDERR, "Error : ".$args."\n"); +function printLog($string) { + fwrite(STDERR, $string."\n"); +} +function printError($string) { + fwrite(STDERR, "Error : ".$string."\n"); } ?> +