From 3a0e90cc9edb5b58b2a2416b165c85971d7dd948 Mon Sep 17 00:00:00 2001 From: wonipapa Date: Thu, 23 Mar 2017 15:49:26 +0900 Subject: [PATCH] Update epg2xml.php --- epg2xml.php | 200 +++++++++++++++++++++++++--------------------------- 1 file changed, 98 insertions(+), 102 deletions(-) diff --git a/epg2xml.php b/epg2xml.php index 2178ec2..03a883c 100644 --- a/epg2xml.php +++ b/epg2xml.php @@ -1,6 +1,6 @@ #!/usr/bin/env php getMessage()); + exit; + } + endif; + } + catch(Exception $e) { + printError($e->getMessage()); + exit; + } + if(empty($MyISP)) : //ISP 선택없을 시 사용법 출력 + printError("epg2xml.json 파일의 MyISP항목이 없습니다."); exit; else : - if(in_array($args['i'], array("KT", "LG", "SK"))) : //ISP 선택 - $MyISP = $args['i']; - if($args['d'] === False || $args['display'] === False ) : - if($args['o'] || $args['outfile'] || $args['s'] || $args['socket']) : - print($usage); - print("epg2xml.php: error: one of the arguments -v/--version -d/--display -o/--outfile -s/--socket is required\n"); - exit; - endif; - $output = "display"; - elseif(empty($args['o']) === False || empty($args['outfile']) === False) : - if($args['d'] === False || $args['display'] === False || $args['s'] || $args['socket']) : - print($usage); - print("epg2xml.php: error: one of the arguments -v/--version -d/--display -o/--outfile -s/--socket is required\n"); - exit; - endif; - $output = "file"; - $outfile = $args['o'] ?: $args['outfile']; - elseif(empty($args['s']) === False || empty($args['socket']) === False) : - if($args['d'] === False || $args['display'] === False || $args['o'] || $args['outfile']) : - print($usage); - print("epg2xml.php: error: one of the arguments -v/--version -d/--display -o/--outfile -s/--socket is required\n"); - exit; - endif; - $output = "socket"; - $socket = $args['s'] ?: $args['socket']; - else : - print($usage); - print("epg2xml.php: error: one of the arguments -v/--version -d/--display -o/--outfile -s/--socket is required\n"); + if(in_array($MyISP, array("KT", "LG", "SK"))) : //ISP 선택 + if(empty($default_output)) : + printError("epg2xml.json 파일의 output항목이 없습니다."); exit; - endif; - if(empty($args['l']) === False || empty($args['limit']) === False) : - if(in_array($args['l'], array(1, 2, 3, 4, 5, 6, 7)) || in_array($args['limit'], array(1, 2, 3, 4, 5, 6, 7))) : - $period = $args['l'] ?: $args['limit']; + else : + if(in_array($default_output, array("d", "o", "s"))) : + switch ($default_output) : + case "d" : + $output = "display"; + break; + case "o" : + $output = "file"; + break; + case "s" : + $output = "socket"; + break; + endswitch; else : - print($usage); - print("epg2xml.php: error: argument -l/--limit: invalid choice: ".$args['l']." (choose from 1, 2, 3, 4, 5, 6, 7)\n"); + printError("output는 d, o, s만 가능합니다."); exit; endif; endif; - if(empty($args['icon']) === False) : - $IconUrl = $args['icon']; + if(is_null($default_icon_url) == True) : + printError("epg2xml.json 파일의 default_icon_url항목이 없습니다."); + exit; + else : + $IconUrl = $default_icon_url; endif; - if(empty($args['episode']) === False) : - if(in_array($args['episode'], array("y", "n"))) : - $episode = $args['episode']; + if(empty($default_rebroadcast)) : + printError("epg2xml.json 파일의 default_rebroadcast항목이 없습니다."); + exit; + else : + if(in_array($default_rebroadcast, array("y", "n"))) : + $rebroadcast = $default_rebroadcast; else : - print($usage); - print("epg2xml.php: argument --episode: invalid choice: 'a' (choose from 'y', 'n')\n"); + printError("default_rebroadcast는 y, n만 가능합니다."); exit; endif; - endif; - if(empty($args['rebroadcast']) === False) : - if(in_array($args['rebroadcast'], array("y", "n"))) : - $rebroadcast = $args['rebroadcast']; + endif; + if(empty($default_episode)) : + printError("epg2xml.json 파일의 default_episode항목이 없습니다."); + exit; + else : + if(in_array($default_episode, array("y", "n"))) : + $episode = $default_episode; else : - print($usage); - print("epg2xml.php: argument --rebroadcast: invalid choice: 'a' (choose from 'y', 'n')\n"); + printError("default_episode는 y, n만 가능합니다."); exit; endif; - endif; - if(empty($args['verbose']) === False) : - if(in_array($args['verbose'], array("y", "n"))) : - $verbose = $args['verbose']; + endif; + if(empty($default_verbose)) : + printError("epg2xml.json 파일의 default_verbose항목이 없습니다."); + exit; + else : + if(in_array($default_verbose, array("y", "n"))) : + $verbose = $default_verbose; else : - print($usage); - print("epg2xml.php: argument --verbose: invalid choice: 'a' (choose from 'y', 'n')\n"); + printError("default_verbose는 y, n만 가능합니다."); exit; endif; - endif; + endif; + if(empty($default_fetch_limit)) : + printError("epg2xml.json 파일의 default_fetch_limit항목이 없습니다."); + exit; + else : + if(in_array($default_fetch_limit, array(1, 2, 3, 4, 5, 6, 7))) : + $period = $default_fetch_limit; + else : + printError("default_fetch_limit는 1, 2, 3, 4, 5, 6, 7만 가능합니다."); + exit; + endif; + endif; else : - print($usage); - print("epg2xml.php: error: argument -i: invalid choice: '".$args1['i']."' (choose from 'KT', 'LG', 'SK')\n"); + printError("MyISP는 KT, LG, SK만 가능합니다."); exit; endif; endif; @@ -183,7 +178,8 @@ elseif($output == "file") : fclose($fp); elseif($output == "socket") : $socket = $socket ?: $default_xml_socket; - $fp = fsockopen('unix:///volume1/@appstore/tvheadend-testing/var/epggrab/xmltv.sock', -1, $errno, $errstr, 30); + $socket = "unix://".$socket; + $fp = fsockopen($socket, -1, $errno, $errstr, 30); getEpg(); fclose($fp); endif; @@ -195,11 +191,11 @@ function getEPG() { try { $f = @file_get_contents($Channelfile); // Read Channel Information file if($f === False) : - throw new Exception(JSON_FILE_ERROR); + throw new Exception("Chanel.".JSON_FILE_ERROR); else : try { $Channeldatas = json_decode($f, TRUE); - if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR); + if(json_last_error() != JSON_ERROR_NONE) throw new Exception("Channel.".JSON_SYNTAX_ERROR); } catch(Exception $e) { printError($e->getMessage());