From 92eb54eafdaaf8f7cd2cc610260ca41d1037bb36 Mon Sep 17 00:00:00 2001 From: wonipapa Date: Wed, 6 Sep 2017 14:36:32 +0900 Subject: [PATCH] =?UTF-8?q?HCN,=20ISCS=20=ED=95=A8=EC=88=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=9B=B9=ED=8E=98=EC=9D=B4=EC=A7=80=20=ED=8C=A8?= =?UTF-8?q?=EC=B9=98=EC=8B=9C=20=EC=8B=9C=EA=B0=84=20=EA=B0=84=EA=B2=A9=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epg2xml-web.php | 115 ++++++++++++++++++++++++++---------------------- epg2xml.php | 5 ++- 2 files changed, 66 insertions(+), 54 deletions(-) diff --git a/epg2xml-web.php b/epg2xml-web.php index 585fa4f..037821a 100644 --- a/epg2xml-web.php +++ b/epg2xml-web.php @@ -1,6 +1,7 @@ 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>/'; - $response = preg_replace_callback($pattern, function($matches) { return ''.htmlspecialchars($matches[1]).'';}, $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, " \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)); +} ?> diff --git a/epg2xml.php b/epg2xml.php index af9eaba..51bf96c 100644 --- a/epg2xml.php +++ b/epg2xml.php @@ -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, " \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)); }