Merge pull request #73 from wonipapa/devel

Devel
This commit is contained in:
wonipapa 2018-01-02 12:16:59 +09:00 committed by GitHub
commit 3ca07e6415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 60 deletions

View File

@ -1,7 +1,6 @@
# EPG2XML # EPG2XML
이 프로그램은 EPG(Electronic Program Guide)를 웹상의 여러 소스에서 가져와서 XML로 출력하는 프로그램으로 python2.7 및 php5.4.45 이상에서 사용 가능하도록 제작되었다. 이 프로그램은 EPG(Electronic Program Guide)를 웹상의 여러 소스에서 가져와서 XML로 출력하는 프로그램으로 python2.7 및 php5.4.45 이상에서 사용 가능하도록 제작되었다.
python3과 php 5.4.45 이하에서는 정상적인 작동을 보장하지 못한다. python3과 php 5.4.45 이하에서는 정상적인 작동을 보장하지 못한다. 또한 외부의 소스를 분석하여 EPG 정보를 가공하여 보여주는 것이므로 외부 소스 사이트가 변경되거나 삭제되면 문제가 발생할 수 있다.
또한 외부의 소스를 분석하여 EPG 정보를 가공하여 보여주는 것이므로 외부 소스 사이트가 변경되거나 삭제되면 문제가 발생할 수 있다.
## 개발자 후원하기 ## 개발자 후원하기
https://www.facebook.com/chericface https://www.facebook.com/chericface
@ -119,6 +118,8 @@ https://github.com/wonipapa/epg2xml/wiki
https://github.com/wonipapa/epg2xml/wiki/FAQ https://github.com/wonipapa/epg2xml/wiki/FAQ
## 변경사항 ## 변경사항
### Version 1.2.4
- ISCS 함수 수정
### Version 1.2.3 ### Version 1.2.3
- PHP 버전통합 - PHP 버전통합
- PYTHON 버전 html Parser 변수 추가(libxml지원안하는 기기 편의 지원) - PYTHON 버전 html Parser 변수 추가(libxml지원안하는 기기 편의 지원)

View File

@ -3,7 +3,7 @@
@date_default_timezone_set('Asia/Seoul'); @date_default_timezone_set('Asia/Seoul');
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
@set_time_limit(0); @set_time_limit(0);
define("VERSION", "1.2.3p5"); define("VERSION", "1.2.4");
$debug = False; $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'"; $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; $timeout = 5;
@ -968,12 +968,11 @@ function GetEPGFromIscs($ChannelInfo) {
$epginfo2 = array(); $epginfo2 = array();
foreach(range(1, $GLOBALS['period']) as $k) : foreach(range(1, $GLOBALS['period']) as $k) :
$istomorrow = False; $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")); $day = date("Y-m-d", strtotime("+".($k - 1)." days"));
$params = array( $params = array(
'Exec_Mode' => 'view', 's_idx' => $ServiceId,
'Source_Id' => $ServiceId, 'c_date' => $day
'Ch_Day' => $day
); );
$params = http_build_query($params); $params = http_build_query($params);
$method = "POST"; $method = "POST";
@ -985,38 +984,43 @@ function GetEPGFromIscs($ChannelInfo) {
try { try {
$data = json_decode($response, TRUE); $data = json_decode($response, TRUE);
if(json_last_error() != JSON_ERROR_NONE) throw new Exception(JSON_SYNTAX_ERROR); 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']) : if($GLOBALS['debug']) :
printError($ChannelName.CHANNEL_ERROR); printError($ChannelName.CHANNEL_ERROR);
endif; endif;
else : else :
$programs = $data['list']; $response = $data['html'];
foreach($programs as $program) : $dom = new DomDocument;
$startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = ""; libxml_use_internal_errors(True);
$rebroadcast = False;
$rating = 0; if($dom->loadHTML('<?xml encoding="utf-8" ?>'.$response)):
if(startsWith($program['Time'], '1') || startsWith($program['Time'], '2')) $istomorrow = True; $xpath = new DomXPath($dom);
if(startsWith($program['Time'], '0') && $istomorrow == True) : $query = "//tbody/tr";
$startTime = date("YmdHis", strtotime($day." +1 days"." ".$program['Time'])); $rows = $xpath->query($query);
else : foreach($rows as $row) :
$startTime = date("YmdHis", strtotime($day." ".$program['Time'])); $startTime = $endTime = $programName = $subprogramName = $desc = $actors = $producers = $category = $episode = "";
endif; $rebroadcast = False;
$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; $rating = 0;
else: $cells = $row->getElementsByTagName('td');
$rating = str_replace("세이상","", $program['Rating']); $startTime = $cells->item(0)->nodeValue ?: "";
endif; $startTime = date("YmdHis", strtotime($day." ".$startTime));
//ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating $programName = trim($cells->item(1)->nodeValue) ?: "";
$epginfo[] = array($ChannelId, $startTime, $programName, $subprogramName, $desc, $actors, $producers, $category, $episode, $rebroadcast, $rating); $pattern = '/^(.*?)(\(([\d,]+)회\))?(<(.*)>)?(\((재)\))?$/';
usleep(1000); preg_match($pattern, $programName, $matches);
endforeach; 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; endif;
} catch(Exception $e) { } catch(Exception $e) {
if($GLOBALS['debug']) printError($e->getMessage()); 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) { function GetEPGFromMbc($ChannelInfo) {
$ChannelId = $ChannelInfo[0]; $ChannelId = $ChannelInfo[0];
$ChannelName = $ChannelInfo[1]; $ChannelName = $ChannelInfo[1];
@ -1367,7 +1371,7 @@ function GetEPGFromMbc($ChannelInfo) {
endforeach; endforeach;
} }
// Get EPG data from MIL // Get EPG data from MIL Radio
function GetEPGFromMil($ChannelInfo) { function GetEPGFromMil($ChannelInfo) {
$ChannelId = $ChannelInfo[0]; $ChannelId = $ChannelInfo[0];
$ChannelName = $ChannelInfo[1]; $ChannelName = $ChannelInfo[1];
@ -1439,7 +1443,7 @@ function GetEPGFromMil($ChannelInfo) {
endforeach; endforeach;
} }
// Get EPG data from IFM // Get EPG data from IFM Radio
function GetEPGFromIfm($ChannelInfo) { function GetEPGFromIfm($ChannelInfo) {
$ChannelId = $ChannelInfo[0]; $ChannelId = $ChannelInfo[0];
$ChannelName = $ChannelInfo[1]; $ChannelName = $ChannelInfo[1];
@ -1507,7 +1511,7 @@ function GetEPGFromIfm($ChannelInfo) {
endforeach; endforeach;
} }
// Get EPG data from KBS // Get EPG data from KBS Radio
function GetEPGFromKbs($ChannelInfo) { function GetEPGFromKbs($ChannelInfo) {
$ChannelId = $ChannelInfo[0]; $ChannelId = $ChannelInfo[0];
$ChannelName = $ChannelInfo[1]; $ChannelName = $ChannelInfo[1];
@ -1565,6 +1569,7 @@ function GetEPGFromKbs($ChannelInfo) {
if($epginfo) epgzip($epginfo); if($epginfo) epgzip($epginfo);
} }
// Get EPG data from Arirang Radio
function GetEPGFromArirang($ChannelInfo) { function GetEPGFromArirang($ChannelInfo) {
$ChannelId = $ChannelInfo[0]; $ChannelId = $ChannelInfo[0];
$ChannelName = $ChannelInfo[1]; $ChannelName = $ChannelInfo[1];

View File

@ -44,7 +44,7 @@ if not sys.version_info[:2] == (2, 7):
sys.exit() sys.exit()
# Set variable # Set variable
__version__ = '1.2.3p5' __version__ = '1.2.4'
debug = False debug = False
today = datetime.date.today() 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': '*/*'} 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('<span class="nowon">now on</span>','',data) data = re.sub('<span class="nowon">now on</span>','',data)
pattern = '<span>(.*)<\/span>' pattern = '<span>(.*)<\/span>'
data = re.sub(pattern, partial(replacement, tag='span'), data) data = re.sub(pattern, partial(replacement, tag='span'), data)
#print(data)
strainer = SoupStrainer('div', {'id':'dawn'}) strainer = SoupStrainer('div', {'id':'dawn'})
soup = BeautifulSoup(data, htmlparser, parse_only=strainer, from_encoding='utf-8') soup = BeautifulSoup(data, htmlparser, parse_only=strainer, from_encoding='utf-8')
html = soup.find_all('li') if soup.find_all('li') else '' html = soup.find_all('li') if soup.find_all('li') else ''
@ -527,40 +526,38 @@ def GetEPGFromIscs(ChannelInfo):
ServiceId = ChannelInfo[3] ServiceId = ChannelInfo[3]
epginfo = [] epginfo = []
epginfo2 = [] 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): for k in range(period):
istomorrow = False istomorrow = False
day = today + datetime.timedelta(days=k) 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 = requests.post(url, data=params, headers=ua, timeout=timeout)
response.raise_for_status() response.raise_for_status()
json_data = response.text json_data = response.text
try: try:
data = json.loads(json_data, encoding='utf-8') data = json.loads(json_data, encoding='utf-8')
if(data['total'] > 0 ): if(data['result'] > 0 ):
programs = data['list'] htmls = data['html']
for program in programs: 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 = '' startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
rebroadcast = False rebroadcast = False
rating = 0 rating = 0
if program['Time'].startswith('1') or program['Time'].startswith('2'): startTime = str(day) + ' ' + row.find('td', {'class':'time'}).text
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 = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M') startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M')
startTime = startTime.strftime('%Y%m%d%H%M%S') startTime = startTime.strftime('%Y%m%d%H%M%S')
pattern = '^(.*?)(?:\(([\d,]+)회\))?(?:\((재)\))?$'; 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) : if not(matches is None) :
programName = matches.group(1) if matches.group(1) else '' programName = matches.group(1) if matches.group(1) else ''
episode = matches.group(2) if matches.group(2) else '' episode = matches.group(2) if matches.group(2) else ''
rebroadcast = True if matches.group(3) else False 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 rating = 0
else: 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 #ChannelId, startTime, programName, subprogramName, desc, actors, producers, category, episode, rebroadcast, rating
epginfo.append([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) time.sleep(0.001)
@ -652,7 +649,7 @@ def GetEPGFromPooq(ChannelInfo):
startTime = program['startDate'] + ' ' + program['startTime'] startTime = program['startDate'] + ' ' + program['startTime']
startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M') startTime = datetime.datetime.strptime(startTime, '%Y-%m-%d %H:%M')
startTime = startTime.strftime('%Y%m%d%H%M%S') 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,]+)회)?(?:\((재)\))?$' pattern = '^(.*?)(?:([\d,]+)회)?(?:\((재)\))?$'
matches = re.match(pattern, programName) matches = re.match(pattern, programName)
if not(matches is None) : if not(matches is None) :
@ -769,7 +766,7 @@ def GetEPGFromOksusu(ChannelInfo):
if(debug): printError(ChannelName + str(e)) if(debug): printError(ChannelName + str(e))
else: pass else: pass
# Get EPG data from MBC # Get EPG data from MBC Radio
def GetEPGFromMbc(ChannelInfo): def GetEPGFromMbc(ChannelInfo):
ChannelId = ChannelInfo[0] ChannelId = ChannelInfo[0]
ChannelName = ChannelInfo[1] ChannelName = ChannelInfo[1]
@ -811,7 +808,7 @@ def GetEPGFromMbc(ChannelInfo):
if(debug): printError(ChannelName + str(e)) if(debug): printError(ChannelName + str(e))
else: pass else: pass
# Get EPG data from MIL # Get EPG data from MIL Radio
def GetEPGFromMil(ChannelInfo): def GetEPGFromMil(ChannelInfo):
ChannelId = ChannelInfo[0] ChannelId = ChannelInfo[0]
ChannelName = ChannelInfo[1] ChannelName = ChannelInfo[1]
@ -860,7 +857,7 @@ def GetEPGFromMil(ChannelInfo):
if(debug): printError(ChannelName + str(e)) if(debug): printError(ChannelName + str(e))
else: pass else: pass
# Get EPG data from IFM # Get EPG data from IFM Radio
def GetEPGFromIfm(ChannelInfo): def GetEPGFromIfm(ChannelInfo):
ChannelId = ChannelInfo[0] ChannelId = ChannelInfo[0]
ChannelName = ChannelInfo[1] ChannelName = ChannelInfo[1]
@ -905,7 +902,7 @@ def GetEPGFromIfm(ChannelInfo):
if(debug): printError(ChannelName + str(e)) if(debug): printError(ChannelName + str(e))
else: pass else: pass
# Get EPG data from KBS # Get EPG data from KBS Radio
def GetEPGFromKbs(ChannelInfo): def GetEPGFromKbs(ChannelInfo):
ChannelId = ChannelInfo[0] ChannelId = ChannelInfo[0]
ChannelName = ChannelInfo[1] ChannelName = ChannelInfo[1]
@ -945,7 +942,7 @@ def GetEPGFromKbs(ChannelInfo):
if(epginfo) : if(epginfo) :
epgzip(epginfo) epgzip(epginfo)
# Get EPG data from ARIRANG # Get EPG data from ARIRANG Radio
def GetEPGFromArirang(ChannelInfo): def GetEPGFromArirang(ChannelInfo):
ChannelId = ChannelInfo[0] ChannelId = ChannelInfo[0]
ChannelName = ChannelInfo[1] ChannelName = ChannelInfo[1]