diff --git a/README.md b/README.md index 0ad2c5b..15607ba 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # EPG2XML 이 프로그램은 EPG(Electronic Program Guide)를 웹상의 여러 소스에서 가져와서 XML로 출력하는 프로그램으로 python2.7 및 php5.4.45 이상에서 사용 가능하도록 제작되었다. -python3과 php 5.4.45 이하에서는 정상적인 작동을 보장하지 못한다. -또한 외부의 소스를 분석하여 EPG 정보를 가공하여 보여주는 것이므로 외부 소스 사이트가 변경되거나 삭제되면 문제가 발생할 수 있다. +python3과 php 5.4.45 이하에서는 정상적인 작동을 보장하지 못한다. 또한 외부의 소스를 분석하여 EPG 정보를 가공하여 보여주는 것이므로 외부 소스 사이트가 변경되거나 삭제되면 문제가 발생할 수 있다. ## 개발자 후원하기 https://www.facebook.com/chericface @@ -119,6 +118,8 @@ https://github.com/wonipapa/epg2xml/wiki https://github.com/wonipapa/epg2xml/wiki/FAQ ## 변경사항 +### Version 1.2.4 + - ISCS 함수 수정 ### Version 1.2.3 - PHP 버전통합 - PYTHON 버전 html Parser 변수 추가(libxml지원안하는 기기 편의 지원) diff --git a/epg2xml-web.php b/epg2xml-web.php index 84f05b6..4e4382b 100644 --- a/epg2xml-web.php +++ b/epg2xml-web.php @@ -3,7 +3,7 @@ @date_default_timezone_set('Asia/Seoul'); error_reporting(E_ALL ^ E_NOTICE); @set_time_limit(0); -define("VERSION", "1.2.3p5"); +define("VERSION", "1.2.4"); $debug = False; $ua = "'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'"; $timeout = 5; @@ -968,12 +968,11 @@ function GetEPGFromIscs($ChannelInfo) { $epginfo2 = array(); foreach(range(1, $GLOBALS['period']) as $k) : $istomorrow = False; - $url = "http://m.iscs.co.kr/sub/02/data.asp"; + $url = "https://www.iscs.co.kr/service/sub/ajax_channel_view.asp"; $day = date("Y-m-d", strtotime("+".($k - 1)." days")); $params = array( - 'Exec_Mode' => 'view', - 'Source_Id' => $ServiceId, - 'Ch_Day' => $day + 's_idx' => $ServiceId, + 'c_date' => $day ); $params = http_build_query($params); $method = "POST"; @@ -985,38 +984,43 @@ 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['total']) == 0) : + if($data['result'] == 0) : if($GLOBALS['debug']) : printError($ChannelName.CHANNEL_ERROR); endif; else : - $programs = $data['list']; - foreach($programs as $program) : - $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; - $rebroadcast = False; - $rating = 0; - if(startsWith($program['Time'], '1') || startsWith($program['Time'], '2')) $istomorrow = True; - if(startsWith($program['Time'], '0') && $istomorrow == True) : - $startTime = date("YmdHis", strtotime($day." +1 days"." ".$program['Time'])); - else : - $startTime = date("YmdHis", strtotime($day." ".$program['Time'])); - endif; - $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'] == '모든연령'): + $response = $data['html']; + $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; - 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; + $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[5])) $subprogramName = trim($matches[5]) ?: ""; + if(isset($matches[3])) $episode = $matches[3] ?: ""; + if(isset($matches[7])) $rebroadcast = $matches[7] ? 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); + usleep(1000); + endforeach; + else : + if($GLOBALS['debug']) printError($ChannelName.CONTENT_ERROR); + endif; endif; } catch(Exception $e) { if($GLOBALS['debug']) printError($e->getMessage()); @@ -1295,7 +1299,7 @@ function GetEPGFromOksusu($ChannelInfo) { } } -// Get EPG data from MBC +// Get EPG data from MBC Radio function GetEPGFromMbc($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; @@ -1367,7 +1371,7 @@ function GetEPGFromMbc($ChannelInfo) { endforeach; } -// Get EPG data from MIL +// Get EPG data from MIL Radio function GetEPGFromMil($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; @@ -1439,7 +1443,7 @@ function GetEPGFromMil($ChannelInfo) { endforeach; } -// Get EPG data from IFM +// Get EPG data from IFM Radio function GetEPGFromIfm($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; @@ -1507,7 +1511,7 @@ function GetEPGFromIfm($ChannelInfo) { endforeach; } -// Get EPG data from KBS +// Get EPG data from KBS Radio function GetEPGFromKbs($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; @@ -1565,6 +1569,7 @@ function GetEPGFromKbs($ChannelInfo) { if($epginfo) epgzip($epginfo); } +// Get EPG data from Arirang Radio function GetEPGFromArirang($ChannelInfo) { $ChannelId = $ChannelInfo[0]; $ChannelName = $ChannelInfo[1]; diff --git a/epg2xml.py b/epg2xml.py index b397da7..3681992 100644 --- a/epg2xml.py +++ b/epg2xml.py @@ -44,7 +44,7 @@ if not sys.version_info[:2] == (2, 7): sys.exit() # Set variable -__version__ = '1.2.3p5' +__version__ = '1.2.4' debug = False today = datetime.date.today() 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': '*/*'} @@ -390,7 +390,6 @@ def GetEPGFromSKB(ChannelInfo): data = re.sub('now on','',data) pattern = '(.*)<\/span>' data = re.sub(pattern, partial(replacement, tag='span'), data) - #print(data) strainer = SoupStrainer('div', {'id':'dawn'}) soup = BeautifulSoup(data, htmlparser, parse_only=strainer, from_encoding='utf-8') html = soup.find_all('li') if soup.find_all('li') else '' @@ -527,40 +526,38 @@ def GetEPGFromIscs(ChannelInfo): ServiceId = ChannelInfo[3] epginfo = [] epginfo2 = [] - url='http://m.iscs.co.kr/sub/02/data.asp' + url='https://www.iscs.co.kr/service/sub/ajax_channel_view.asp' for k in range(period): istomorrow = False day = today + datetime.timedelta(days=k) - params = {'Exec_Mode': 'view', 'Source_Id': ServiceId, 'Ch_Day': day} + params = {'s_idx': ServiceId, 'c_date': day} response = requests.post(url, data=params, headers=ua, timeout=timeout) response.raise_for_status() json_data = response.text try: data = json.loads(json_data, encoding='utf-8') - if(data['total'] > 0 ): - programs = data['list'] - for program in programs: + if(data['result'] > 0 ): + htmls = data['html'] + strainer = SoupStrainer('tbody') + soup = BeautifulSoup(htmls, htmlparser, parse_only=strainer) + html = soup.find_all('tr') if soup.find_all('tr') else '' + for row in html: startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = '' rebroadcast = False rating = 0 - if program['Time'].startswith('1') or program['Time'].startswith('2'): - istomorrow = True - if program['Time'].startswith('0') and istomorrow == True: - startTime = str(day + datetime.timedelta(days=1)) + ' ' + program['Time'] - else: - startTime = str(day) + ' ' + program['Time'] + startTime = str(day) + ' ' + row.find('td', {'class':'time'}).text startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M') startTime = startTime.strftime('%Y%m%d%H%M%S') pattern = '^(.*?)(?:\(([\d,]+)회\))?(?:\((재)\))?$'; - matches = re.match(pattern, program['Pg_Name'].decode('string_escape').strip()) + matches = re.match(pattern, row.find('td', {'class':'name'}).text.strip().encode('utf-8')) if not(matches is None) : programName = matches.group(1) if matches.group(1) else '' episode = matches.group(2) if matches.group(2) else '' rebroadcast = True if matches.group(3) else False - if program['Rating'].decode('string_escape').strip() == '모든연령': + if row.find('span', {'class':'ru5'}).text.strip() == '전체관람': rating = 0 else: - rating = program['Rating'].replace('세이상','') + rating = row.find('span', {'class':'ru5'}).text.strip().replace('세이상','') #ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating epginfo.append([ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating]) time.sleep(0.001) @@ -652,7 +649,7 @@ def GetEPGFromPooq(ChannelInfo): startTime = program['startDate'] + ' ' + program['startTime'] startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M') startTime = startTime.strftime('%Y%m%d%H%M%S') - programName = program['programTitle'].replace("\r\n", "").encode('utf-8'); + programName = program['programTitle'].replace("\r\n", "").encode('utf-8') pattern = '^(.*?)(?:([\d,]+)회)?(?:\((재)\))?$' matches = re.match(pattern, programName) if not(matches is None) : @@ -769,7 +766,7 @@ def GetEPGFromOksusu(ChannelInfo): if(debug): printError(ChannelName + str(e)) else: pass -# Get EPG data from MBC +# Get EPG data from MBC Radio def GetEPGFromMbc(ChannelInfo): ChannelId = ChannelInfo[0] ChannelName = ChannelInfo[1] @@ -811,7 +808,7 @@ def GetEPGFromMbc(ChannelInfo): if(debug): printError(ChannelName + str(e)) else: pass -# Get EPG data from MIL +# Get EPG data from MIL Radio def GetEPGFromMil(ChannelInfo): ChannelId = ChannelInfo[0] ChannelName = ChannelInfo[1] @@ -860,7 +857,7 @@ def GetEPGFromMil(ChannelInfo): if(debug): printError(ChannelName + str(e)) else: pass -# Get EPG data from IFM +# Get EPG data from IFM Radio def GetEPGFromIfm(ChannelInfo): ChannelId = ChannelInfo[0] ChannelName = ChannelInfo[1] @@ -905,7 +902,7 @@ def GetEPGFromIfm(ChannelInfo): if(debug): printError(ChannelName + str(e)) else: pass -# Get EPG data from KBS +# Get EPG data from KBS Radio def GetEPGFromKbs(ChannelInfo): ChannelId = ChannelInfo[0] ChannelName = ChannelInfo[1] @@ -945,7 +942,7 @@ def GetEPGFromKbs(ChannelInfo): if(epginfo) : epgzip(epginfo) -# Get EPG data from ARIRANG +# Get EPG data from ARIRANG Radio def GetEPGFromArirang(ChannelInfo): ChannelId = ChannelInfo[0] ChannelName = ChannelInfo[1]