diff --git a/epg2xml-web.php b/epg2xml-web.php deleted file mode 100644 index 2db6852..0000000 --- a/epg2xml-web.php +++ /dev/null @@ -1,997 +0,0 @@ -getMessage()); - exit; - } - endif; -} -catch(Exception $e) { - printError($e->getMessage()); - exit; -} - -if(php_sapi_name() != "cli"): - if(isset($_GET['h']) || isset($_GET['help']))://도움말 출력 - header("Content-Type: text/plain; charset=utf-8"); - print($help); - exit; - elseif(isset($_GET['v'])|| isset($_GET['version']))://버전 정보 출력 - header("Content-Type: text/plain; charset=utf-8"); - printf("epg2xml.php version : %s\n", VERSION); - exit; - endif; -else : - if((isset($args['h']) && $args['h'] === False) || (isset($args['help']) && $args['help'] === False))://도움말 출력 - printf($help); - exit; - elseif((isset($args['v']) && $args['v'] === False) || (isset($args['version']) && $args['version'] === False))://버전 정보 출력 - printf("epg2xml.php version : %s\n", VERSION); - exit; - endif; -endif; -if($output == "display") : - $fp = fopen('php://output', 'w+'); - if ($fp === False) : - printError(DISPLAY_ERROR); - exit; - else : - try { - getEpg(); - fclose($fp); - } catch(Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endif; -elseif($output == "file") : - if($default_xml_file) : - $fp = fopen($default_xml_file, 'w+'); - if ($fp === False) : - printError(FIEL_ERROR); - exit; - else : - try { - getEpg(); - fclose($fp); - } catch(Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endif; - else : - printError("epg2xml.json 파일의 default_xml_file항목이 없습니다."); - exit; - endif; -elseif($output == "socket") : - if($default_xml_socket && php_sapi_name() == "cli") : - $default_xml_socket = "unix://".$default_xml_socket; - $fp = @fsockopen($default_xml_socket, -1, $errno, $errstr, 30); - if ($fp === False) : - printError(SOCKET_ERROR); - exit; - else : - try { - getEpg(); - fclose($fp); - } catch(Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endif; - else : - printError("epg2xml.json 파일의 default_xml_socket항목이 없습니다."); - exit; - endif; -endif; - -function getEPG() { - $fp = $GLOBALS['fp']; - $MyISP = $GLOBALS['MyISP']; - $MyChannels = $GLOBALS['MyChannels']; - $Channelfile = __DIR__."/Channel.json"; - $IconUrl = ""; - $ChannelInfos = array(); - try { - $f = @file_get_contents($Channelfile); - if($f === False) : - printError("Channel.json.".JSON_FILE_ERROR); - exit; - else : - try { - $Channeldatajson = json_decode($f, TRUE); - if(json_last_error() != JSON_ERROR_NONE) throw new Exception("Channel.".JSON_SYNTAX_ERROR); - } - catch(Exception $e) { - printError($e->getMessage()); - exit; - } - endif; - } - catch(Exception $e) { - printError($e->getMessage()); - exit; - } -//My Channel 정의 - $MyChannelInfo = array(); - if($MyChannels) : - $MyChannelInfo = array_map('trim',explode(',', $MyChannels)); - endif; - if(php_sapi_name() != "cli" && $GLOBALS['default_output'] == "d") header("Content-Type: application/xml; charset=utf-8"); - fprintf($fp, "\n"); - fprintf($fp, "\n\n"); - fprintf($fp, "\n", VERSION); - - foreach ($Channeldatajson as $Channeldata) : //Get Channel & Print Channel info - if(in_array($Channeldata['Id'], $MyChannelInfo)) : - $ChannelId = $Channeldata['Id']; - $ChannelName = htmlspecialchars($Channeldata['Name'], ENT_XML1); - $ChannelSource = $Channeldata['Source']; - $ChannelServiceId = $Channeldata['ServiceId']; - $ChannelIconUrl = htmlspecialchars($Channeldata['Icon_url'], ENT_XML1); - if($MyISP != "ALL" && $Channeldata[$MyISP.'Ch'] != Null): - $ChannelInfos[] = array($ChannelId, $ChannelName, $ChannelSource, $ChannelServiceId); - $Channelnumber = $Channeldata[$MyISP.'Ch']; - $ChannelISPName = htmlspecialchars($Channeldata[$MyISP." Name"], ENT_XML1); - fprintf($fp, " \n", $ChannelId); - fprintf($fp, " %s\n", $ChannelName); - fprintf($fp, " %s\n", $ChannelISPName); - fprintf($fp, " %s\n", $Channelnumber); - fprintf($fp, " %s\n", $Channelnumber." ".$ChannelISPName); - if($IconUrl) : - fprintf($fp, " \n", $IconUrl, $ChannelId); - else : - fprintf($fp, " \n", $ChannelIconUrl); - endif; - fprintf($fp, " \n"); - elseif($MyISP == "ALL"): - $ChannelInfos[] = array($ChannelId, $ChannelName, $ChannelSource, $ChannelServiceId); - fprintf($fp, " \n", $ChannelId); - fprintf($fp, " %s\n", $ChannelName); - if($IconUrl) : - fprintf($fp, " \n", $IconUrl, $ChannelId); - else : - fprintf($fp, " \n", $ChannelIconUrl); - endif; - fprintf($fp, " \n"); - endif; - endif; - endforeach; - // Print Program Information - foreach ($ChannelInfos as $ChannelInfo) : - $ChannelId = $ChannelInfo[0]; - $ChannelName = $ChannelInfo[1]; - $ChannelSource = $ChannelInfo[2]; - $ChannelServiceId = $ChannelInfo[3]; - if($GLOBALS['debug']) printLog($ChannelName.' 채널 EPG 데이터를 가져오고 있습니다'); - if($ChannelSource == 'KT') : - GetEPGFromKT($ChannelInfo); - elseif($ChannelSource == 'LG') : - GetEPGFromLG($ChannelInfo); - elseif($ChannelSource == 'SK') : - GetEPGFromSK($ChannelInfo); - elseif($ChannelSource == 'SKB') : - GetEPGFromSKB($ChannelInfo); - elseif($ChannelSource == 'NAVER') : - GetEPGFromNaver($ChannelInfo); - endif; - endforeach; - fprintf($fp, "\n"); -} - -// Get EPG data from KT -function GetEPGFromKT($ChannelInfo) { - $ChannelId = $ChannelInfo[0]; - $ChannelName = $ChannelInfo[1]; - $ServiceId = $ChannelInfo[3]; - $epginfo = array(); - foreach(range(1, $GLOBALS['period']) as $k) : - $url = "http://tv.kt.com/tv/channel/pSchedule.asp"; - $day = date("Ymd", strtotime("+".($k - 1)." days")); - $params = array( - 'ch_type' => '1', - 'view_type' => '1', - 'service_ch_no' => $ServiceId, - 'seldate' => $day - ); - $params = http_build_query($params); - $method = "POST"; - 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"); - $dom = new DomDocument; - libxml_use_internal_errors(True); - if($dom->loadHTML(''.$response)): - $xpath = new DomXPath($dom); - $query = "//tbody/tr"; - $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'); - $programs = array_map(null, iterator_to_array($xpath->query('p', $cells->item(1))), iterator_to_array($xpath->query('p', $cells->item(2))), iterator_to_array($xpath->query('p', $cells->item(3)))); - foreach($programs as $program): - $hour = trim($cells->item(0)->nodeValue); - $minute = trim($program[0]->nodeValue); - $startTime = date("YmdHis", strtotime($day.$hour.$minute."00")); - $programName = trim($program[1]->nodeValue); - $images = $program[1]->getElementsByTagName('img')->item(0); - preg_match('/([\d,]+)/', $images->getAttribute('alt'), $grade); - if($grade != NULL): - $rating = $grade[1]; - else: - $rating = 0; - endif; - $programName = str_replace("방송중 ", "", $programName); - $category = trim($program[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; - endforeach; - else : - if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); - endif; - endif; - } catch (Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endforeach; - if($epginfo) epgzip($epginfo); -} - -// Get EPG data from LG -function GetEPGFromLG($ChannelInfo) { - $ChannelId = $ChannelInfo[0]; - $ChannelName = $ChannelInfo[1]; - $ServiceId = $ChannelInfo[3]; - $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")); - $params = array( - 'chnlCd' => $ServiceId, - 'evntCmpYmd' => $day - ); - $params = http_build_query($params); - $method = "POST"; - try { - $response = getWeb($url, $params, $method); - if ($response === False && $GLOBALS['debug']) : - printError($ChannelName.HTTP_ERROR); - else : - $response = mb_convert_encoding($response, "UTF-8", "EUC-KR"); - $response = str_replace(array('<재>', ' [..', ' (..'), array('<재>', '', ''), $response); - $dom = new DomDocument; - libxml_use_internal_errors(True); - if($dom->loadHTML(''.$response)): - $xpath = new DomXPath($dom); - $query = "//div[@class='tblType list']/table/tbody/tr"; - $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 = date("YmdHis", strtotime($day." ".trim($cells->item(0)->nodeValue))); - $programName = trim($cells->item(1)->childNodes->item(0)->nodeValue); - $pattern = '/(<재>)?\s?(?:\[.*?\])?(.*?)(?:\[(.*)\])?\s?(?:\(([\d,]+)회\))?$/'; - preg_match($pattern, $programName, $matches); - if ($matches != NULL) : - if(isset($matches[2])) $programName = trim($matches[2]) ?: ""; - if(isset($matches[3])) $subprogramName = trim($matches[3]) ?: ""; - if(isset($matches[4])) $episode = trim($matches[4]) ?: ""; - if(isset($matches[1])) $rebroadcast = trim($matches[1]) ? True: False; - endif; - $category = trim($cells->item(2)->nodeValue); - $spans = $cells->item(1)->getElementsByTagName('span'); - $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); - endif; - endif; - } catch (Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endforeach; - if($epginfo) epgzip($epginfo); -} - -// Get EPG data from SK -function GetEPGFromSK($ChannelInfo) { - $ChannelId = $ChannelInfo[0]; - $ChannelName = $ChannelInfo[1]; - $ServiceId = $ChannelInfo[3]; - $today = date("Ymd"); - $lastday = date("Ymd", strtotime("+".($GLOBALS['period'] - 1)." days")); - $url = "http://m.btvplus.co.kr/common/inc/IFGetData.do"; - $params = array( - 'variable' => 'IF_LIVECHART_DETAIL', - 'pcode' => '|^|start_time='.$today.'00|^|end_time='.$lastday.'24|^|svc_id='.$ServiceId - ); - $params = http_build_query($params); - $method = "POST"; - try { - $response = getWeb($url, $params, $method); - if ($response === False && $GLOBALS['debug']) : - printError($ChannelName.HTTP_ERROR); - else : - try { - $data = json_decode($response, TRUE); - if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR); - if($data['channel'] == NULL) : - if($GLOBALS['debug']) : - printError($ChannelName.CHANNEL_ERROR); - endif; - else : - $programs = $data['channel']['programs']; - foreach ($programs as $program) : - $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; - $rebroadcast = False; - $rating = 0; - $pattern = '/^(.*?)(?:\s*[\(<]([\d,회]+)[\)>])?(?:\s*<([^<]*?)>)?(\((재)\))?$/'; - preg_match($pattern, str_replace('...', '>', $program['programName']), $matches); - if ($matches != NULL) : - if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; - if(isset($matches[3])) $subprogramName = trim($matches[3]) ?: ""; - if(isset($matches[2])) $episode = str_replace("회", "", $matches[2]) ?: ""; - if(isset($matches[5])) $rebroadcast = $matches[5] ? True : False; - endif; - $startTime = date("YmdHis",$program['startTime']/1000); - $endTime = date("YmdHis",$program['endTime']/1000); - $desc = $program['synopsis'] ?: ""; - $actors =trim(str_replace('...','',$program['actorName']), ', ') ?: ""; - $producers = trim(str_replace('...','',$program['directorName']), ', ') ?: ""; - if ($program['mainGenreName'] != NULL) : - $category = $program['mainGenreName']; - else: - $category = ""; - endif; - $rating = $program['ratingCd'] ?: 0; - $programdata = array( - 'channelId'=> $ChannelId, - 'startTime' => $startTime, - 'endTime' => $endTime, - 'programName' => $programName, - 'subprogramName'=> $subprogramName, - 'desc' => $desc, - 'actors' => $actors, - 'producers' => $producers, - 'category' => $category, - 'episode' => $episode, - 'rebroadcast' => $rebroadcast, - 'rating' => $rating - ); - writeProgram($programdata); - usleep(1000); - endforeach; - endif; - } catch(Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endif; - } catch (Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } -} - -// Get EPG data from SKB -function GetEPGFromSKB($ChannelInfo) { - $ChannelId = $ChannelInfo[0]; - $ChannelName = $ChannelInfo[1]; - $ServiceId = $ChannelInfo[3]; - $epginfo = array(); - foreach(range(1, $GLOBALS['period']) as $k) : - $url = "http://m.skbroadband.com/content/realtime/Channel_List.do"; - $day = date("Ymd", strtotime("+".($k - 1)." days")); - $params = array( - 'key_depth2' => $ServiceId, - 'key_depth3' => $day - ); - $params = http_build_query($params); - $method = "POST"; - try { - $response = getWeb($url, $params, $method); - if ($response === False && $GLOBALS['debug']) : - printError($ChannelName.HTTP_ERROR); - else : - $response = str_replace('charset="EUC-KR"', 'charset="UTF-8"', $response); - $response = mb_convert_encoding($response, "UTF-8", "EUC-KR"); - $response = preg_replace('//is', '', $response); - $response = preg_replace('/(.*?)<\/span>/', '', $response); - $response = preg_replace('/(.*?)<\/span>/', '', $response); - $response = preg_replace('/(.*?)<\/span>/', '', $response); - $response = preg_replace('/(.*?)<\/span>/', '', $response); - $response = preg_replace('/(.*?)<\/span>/', '', $response); - $response = preg_replace('/(.*?)<\/span>/', '', $response); - $response = preg_replace('/(.*?)<\/span>/', '', $response); - $response = preg_replace('/프로그램 안내<\/strong>/', '', $response); - $response = preg_replace_callback('/

(.*)/', 'converthtmlspecialchars', $response); - $response = preg_replace_callback('/

(.*)/', 'converthtmlspecialchars', $response); - $dom = new DomDocument; - libxml_use_internal_errors(True); - if($dom->loadHTML(''.$response)): - $xpath = new DomXPath($dom); - $query = "//span[@class='caption' or @class='explan' or @class='fullHD' or @class='UHD' or @class='nowon']"; - $spans = $xpath->query($query); - foreach($spans as $span) : - $span->parentNode->removeChild( $span); - endforeach; - $query = "//div[@id='uiScheduleTabContent']/div/ol/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('p'); - $startTime = $cells->item(0)->nodeValue ?: ""; - $startTime = date("YmdHis", strtotime($day." ".$startTime)); - $programName = trim($cells->item(1)->childNodes->item(0)->nodeValue) ?: ""; - $pattern = '/^(.*?)(\(([\d,]+)회\))?(<(.*)>)?(\((재)\))?$/'; - preg_match($pattern, $programName, $matches); - if ($matches != NULL) : - if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; - if(isset($matches[5])) $subprogramName = trim($matches[5]) ?: ""; - if(isset($matches[3])) $episode = $matches[3] ?: ""; - if(isset($matches[7])) $rebroadcast = $matches[7] ? True : False; - endif; - if(trim($cells->item(1)->childNodes->item(1)->nodeValue)) $rating = str_replace('세 이상', '', trim($cells->item(1)->childNodes->item(1)->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); - endif; - endif; - } catch (Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endforeach; - if($epginfo) epgzip($epginfo); -} - -// Get EPG data from Naver -function GetEPGFromNaver($ChannelInfo) { - $ChannelId = $ChannelInfo[0]; - $ChannelName = $ChannelInfo[1]; - $ServiceId = $ChannelInfo[3]; - $epginfo = array(); - $totaldate = array(); - $url = "https://search.naver.com/p/csearch/content/batchrender_ssl.nhn"; - foreach(range(1, $GLOBALS['period']) as $k) : - $day = date("Ymd", strtotime("+".($k - 1)." days")); - $totaldate[] = $day; - endforeach; - $params = array( - '_callback' => 'epg', - 'fileKey' => 'single_schedule_channel_day', - 'pkid' => '66', - 'u1' => 'single_schedule_channel_day', - 'u2' => join(",", $totaldate), - 'u3' => $day, - 'u4' => $GLOBALS['period'], - 'u5' => $ServiceId, - 'u6' => 1, - 'u7' => $ChannelName."편성표", - 'u8' => $ChannelName."편성표", - 'where' => 'nexearch' - ); - $params = http_build_query($params); - $method = "GET"; - try { - $response = getWeb($url, $params, $method); - if ($response === False && $GLOBALS['debug']) : - printError($ChannelName.HTTP_ERROR); - else : - try { - $response = str_replace('epg( ', '', $response ); - $response = substr($response, 0, strlen($response)-2); - $response = preg_replace("/\/\*.*?\*\//","",$response); - $data = json_decode($response, TRUE); - if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR); - if($data['displayDates'][0]['count'] == 0) : - if($GLOBALS['debug']) : - printError($ChannelName.CHANNEL_ERROR); - endif; - else : - for($i = 0; $i < count($data['displayDates']); $i++) : - for($j = 0; $j < 24; $j++) : - foreach($data['schedules'][$j][$i] as $program) : - $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; - $rebroadcast = False; - $rating = 0; - $startTime = date("YmdHis", strtotime($data['displayDates'][$i]['date']." ".$program['startTime'])); - $programName = htmlspecialchars_decode(trim($program['title']), ENT_XML1); - $episode = str_replace("회","", $program['episode']); - $rebroadcast = $program['isRerun'] ? True : False; - $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; - endif; - } catch(Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - endif; - } catch (Exception $e) { - if($GLOBALS['debug']) printError($e->getMessage()); - } - if($epginfo) epgzip($epginfo); -} - -# Zip epginfo -function epgzip($epginfo) { - $epg1 = current($epginfo); - array_shift($epginfo); - foreach($epginfo as $epg2): - $ChannelId = $epg1[0] ?: ""; - $startTime = $epg1[1] ?: ""; - $endTime = $epg2[1] ?: ""; - $programName = $epg1[2] ?: ""; - $subprogramName = $epg1[3] ?: ""; - $desc = $epg1[4] ?: ""; - $actors = $epg1[5] ?: ""; - $producers = $epg1[6] ?: ""; - $category = $epg1[7] ?: ""; - $episode = $epg1[8] ?: ""; - $rebroadcast = $rebroadcast = $epg1[9] ? True: False; - $rating = $epg1[10] ?: 0; - $programdata = array( - 'channelId'=> $ChannelId, - 'startTime' => $startTime, - 'endTime' => $endTime, - 'programName' => $programName, - 'subprogramName'=> $subprogramName, - 'desc' => $desc, - 'actors' => $actors, - 'producers' => $producers, - 'category' => $category, - 'episode' => $episode, - 'rebroadcast' => $rebroadcast, - 'rating' => $rating - ); - writeProgram($programdata); - $epg1 = $epg2; - endforeach; -} - -function writeProgram($programdata) { - $fp = $GLOBALS['fp']; - $ChannelId = $programdata['channelId']; - $startTime = $programdata['startTime']; - $endTime = $programdata['endTime']; - $programName = trim(htmlspecialchars($programdata['programName'], ENT_XML1)); - $subprogramName = trim(htmlspecialchars($programdata['subprogramName'], ENT_XML1)); - preg_match('/(.*) \(?(\d+부)\)?/', $programName, $matches); - if ($matches != NULL) : - if(isset($matches[1])) $programName = trim($matches[1]) ?: ""; - if(isset($matches[2])) $subprogramName = trim($matches[2]." ".$subprogramName) ?: ""; - endif;// - if($programName == NULL): - $programName = $subprogramName; - endif; - $actors = htmlspecialchars($programdata['actors'], ENT_XML1); - $producers = htmlspecialchars($programdata['producers'], ENT_XML1); - $category = htmlspecialchars($programdata['category'], ENT_XML1); - $episode = $programdata['episode']; - if($episode) : - $episode_ns = (int)$episode - 1; - $episode_ns = '0' . '.' . $episode_ns . '.' . '0' . '/' . '0'; - $episode_on = $episode; - endif; - $rebroadcast = $programdata['rebroadcast']; - if($episode && $GLOBALS['addepisode'] == 'y') $programName = $programName." (".$episode."회)"; - if($rebroadcast == True && $GLOBALS['addrebroadcast'] == 'y') $programName = $programName." (재)"; - if($programdata['rating'] == 0) : - $rating = "전체 관람가"; - else : - $rating = sprintf("%s세 이상 관람가", $programdata['rating']); - endif; - if($GLOBALS['addverbose'] == 'y') : - $desc = $programName; - if($subprogramName) $desc = $desc."\n부제 : ".$subprogramName; - if($rebroadcast == True && $GLOBALS['addrebroadcast'] == 'y') $desc = $desc."\n방송 : 재방송"; - if($episode) $desc = $desc."\n회차 : ".$episode."회"; - if($category) $desc = $desc."\n장르 : ".$category; - if($actors) $desc = $desc."\n출연 : ".trim($actors); - if($producers) $desc = $desc."\n제작 : ".trim($producers); - $desc = $desc."\n등급 : ".$rating; - else: - $desc = ""; - endif; - if($programdata['desc']) $desc = $desc."\n".htmlspecialchars($programdata['desc'], ENT_XML1); - $desc = preg_replace('/ +/', ' ', $desc); - $contentTypeDict = array( - '교양' => 'Arts / Culture (without music)', - '만화' => 'Cartoons / Puppets', - '교육' => 'Education / Science / Factual topics', - '취미' => 'Leisure hobbies', - '드라마' => 'Movie / Drama', - '영화' => 'Movie / Drama', - '음악' => 'Music / Ballet / Dance', - '뉴스' => 'News / Current affairs', - '다큐' => 'Documentary', - '라이프' => 'Documentary', - '시사/다큐' => 'Documentary', - '연예' => 'Show / Game show', - '스포츠' => 'Sports', - '홈쇼핑' => 'Advertisement / Shopping' - ); - $contentType = ""; - foreach($contentTypeDict as $key => $value) : - if(!(strpos($category, $key) === False)) : - $contentType = $value; - endif; - endforeach; - fprintf($fp, " \n", $startTime, $endTime, $ChannelId); - fprintf($fp, " %s\n", $programName); - if($subprogramName) : - fprintf($fp, " %s\n", $subprogramName); - endif; - if($GLOBALS['addverbose']=='y') : - fprintf($fp, " %s\n", $desc); - if($actors || $producers): - fprintf($fp, " \n"); - if($actors) : - foreach(explode(',', $actors) as $actor): - if(trim($actor)) fprintf($fp, " %s\n", trim($actor)); - endforeach; - endif; - if($producers) : - foreach(explode(',', $producers) as $producer): - if(trim($producer)) fprintf($fp, " %s\n", trim($producer)); - endforeach; - endif; - fprintf($fp, " \n"); - endif; - endif; - if($category) fprintf($fp, " %s\n", $category); - if($contentType) fprintf($fp, " %s\n", $contentType); - if($episode && $GLOBALS['addxmltvns']=='y') fprintf($fp, " %s\n", $episode_ns); - if($episode && $GLOBALS['addxmltvns']!='y') fprintf($fp, " %s\n", $episode_on); - if($rebroadcast) fprintf($fp, " \n"); - if($rating) : - fprintf($fp, " \n"); - fprintf($fp, " %s\n", $rating); - fprintf($fp, " \n"); - endif; - fprintf($fp, " \n"); -} - -function getWeb($url, $params, $method) { - $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_RETURNTRANSFER, True); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $GLOBALS['timeout']); - curl_setopt($ch, CURLOPT_HEADER, False); - curl_setopt($ch, CURLOPT_FAILONERROR, True); - curl_setopt($ch, CURLOPT_USERAGENT, $GLOBALS['ua']); - $response = curl_exec($ch); - if(curl_error($ch) && $GLOBALS['debug']) printError($url." ".curl_error($ch)); - curl_close($ch); - return $response; -} - -function printLog($string) { - if(php_sapi_name() == "cli"): - fwrite(STDERR, $string."\n"); - else: - header("Content-Type: text/plain; charset=utf-8"); - print($string."\n"); - endif; -} - -function printError($string) { - if(php_sapi_name() == "cli"): - fwrite(STDERR, "Error : ".$string."\n"); - else: - header("Content-Type: text/plain; charset=utf-8"); - print("Error : ".$string."\n"); - endif; -} - -function _microtime() { - list($usec, $sec) = explode(" ", microtime()); - return ($sec.(int)($usec*1000)); -} - -function startsWith($haystack, $needle) { - return !strncmp($haystack, $needle, strlen($needle)); -} - -function converthtmlspecialchars($match) { - return '

'.htmlspecialchars($match[1]); -} - -//사용방법 -$usage = <<