commit
3af1a6b97b
113
epg2xml-web.php
113
epg2xml-web.php
@ -2,9 +2,8 @@
|
||||
@mb_internal_encoding("UTF-8");
|
||||
@date_default_timezone_set('Asia/Seoul');
|
||||
error_reporting(E_ALL ^ E_NOTICE);
|
||||
|
||||
@set_time_limit(0);
|
||||
define("VERSION", "1.2.3p3");
|
||||
define("VERSION", "1.2.3p4");
|
||||
$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;
|
||||
@ -415,10 +414,10 @@ function getEPG() {
|
||||
GetEPGFromIscs($ChannelInfo);
|
||||
elseif($ChannelSource == 'HCN') :
|
||||
GetEPGFromHcn($ChannelInfo);
|
||||
elseif($ChannelSource == 'POOQ') :
|
||||
GetEPGFromPooq($ChannelInfo);
|
||||
elseif($ChannelSource == 'EVERYON') :
|
||||
GetEPGFromEveryon($ChannelInfo);
|
||||
elseif($ChannelSource == 'OKSUSU') :
|
||||
GetEPGFromOksusu($ChannelInfo);
|
||||
elseif($ChannelSource == 'MBC') :
|
||||
GetEPGFromMbc($ChannelInfo);
|
||||
elseif($ChannelSource == 'MIL'):
|
||||
@ -523,7 +522,7 @@ function GetEPGFromEPG($ChannelInfo) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from KT
|
||||
@ -588,7 +587,7 @@ function GetEPGFromKT($ChannelInfo) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from LG
|
||||
@ -649,7 +648,7 @@ function GetEPGFromLG($ChannelInfo) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from SK
|
||||
@ -796,7 +795,7 @@ function GetEPGFromSKB($ChannelInfo) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from SKY
|
||||
@ -893,8 +892,8 @@ function GetEPGFromNaver($ChannelInfo) {
|
||||
$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) :
|
||||
$url = "https://search.naver.com/p/csearch/content/batchrender_ssl.nhn";
|
||||
$day = date("Ymd", strtotime("+".($k - 1)." days"));
|
||||
$totaldate[] = $day;
|
||||
endforeach;
|
||||
@ -955,7 +954,7 @@ function GetEPGFromNaver($ChannelInfo) {
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from Iscs
|
||||
@ -1026,7 +1025,7 @@ function GetEPGFromIscs($ChannelInfo) {
|
||||
}
|
||||
endforeach;
|
||||
$epginfo= array_map("unserialize", array_unique(array_map("serialize", $epginfo)));
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from Hcn
|
||||
@ -1083,7 +1082,7 @@ function GetEPGFromHcn($ChannelInfo) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from POOQ
|
||||
@ -1154,7 +1153,7 @@ function GetEPGFromPooq($ChannelInfo) {
|
||||
} catch (Exception $e) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
# Get EPG data from EVERYON
|
||||
@ -1207,7 +1206,91 @@ function GetEPGFromEveryon($ChannelInfo) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
// Get EPG data from OKSUSU
|
||||
function GetEPGFromOksusu($ChannelInfo) {
|
||||
$ChannelId = $ChannelInfo[0];
|
||||
$ChannelName = $ChannelInfo[1];
|
||||
$ServiceId = $ChannelInfo[3];
|
||||
$today = date("Ymd");
|
||||
$lastday = date("Ymd", strtotime("+".($GLOBALS['period'] - 1)." days"));
|
||||
$url = "http://seg.oksusu.com:8080/seg/index.php'";
|
||||
$params = array(
|
||||
'svc_id' => $ServiceId,
|
||||
'start_time' => $today.'00',
|
||||
'end_time' => $lastday.'24',
|
||||
'tgroup' => 'oksusutest_02|null',
|
||||
'IF' => 'IF-NSMEPG-003',
|
||||
'response_format' => 'json',
|
||||
'm' => 'ch_epg',
|
||||
'ver' => '1.0'
|
||||
);
|
||||
$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 MBC
|
||||
@ -1477,7 +1560,7 @@ function GetEPGFromKbs($ChannelInfo) {
|
||||
if($GLOBALS['debug']) printError($e->getMessage());
|
||||
}
|
||||
endforeach;
|
||||
epgzip($epginfo);
|
||||
if($epginfo) epgzip($epginfo);
|
||||
}
|
||||
|
||||
function GetEPGFromArirang($ChannelInfo) {
|
||||
|
101
epg2xml.py
101
epg2xml.py
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
import imp
|
||||
import os
|
||||
@ -43,7 +44,7 @@ if not sys.version_info[:2] == (2, 7):
|
||||
sys.exit()
|
||||
|
||||
# Set variable
|
||||
__version__ = '1.2.3p3'
|
||||
__version__ = '1.2.3p4'
|
||||
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': '*/*'}
|
||||
@ -137,6 +138,8 @@ def getEpg():
|
||||
GetEPGFromPooq(ChannelInfo)
|
||||
elif ChannelSource == 'EVERYON':
|
||||
GetEPGFromEveryon(ChannelInfo)
|
||||
elif ChannelSource == 'OKSUSU':
|
||||
GetEPGFromOksusu(ChannelInfo)
|
||||
elif ChannelSource == 'MBC':
|
||||
GetEPGFromMbc(ChannelInfo)
|
||||
elif ChannelSource == 'MIL':
|
||||
@ -211,7 +214,8 @@ def GetEPGFromEPG(ChannelInfo):
|
||||
else: pass
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from KT
|
||||
def GetEPGFromKT(ChannelInfo):
|
||||
@ -256,7 +260,8 @@ def GetEPGFromKT(ChannelInfo):
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from LG
|
||||
def GetEPGFromLG(ChannelInfo):
|
||||
@ -305,7 +310,8 @@ def GetEPGFromLG(ChannelInfo):
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from SK
|
||||
def GetEPGFromSK(ChannelInfo):
|
||||
@ -416,7 +422,8 @@ def GetEPGFromSKB(ChannelInfo):
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from SKY
|
||||
def GetEPGFromSKY(ChannelInfo):
|
||||
@ -510,7 +517,8 @@ def GetEPGFromNaver(ChannelInfo):
|
||||
except (requests.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from ISCS
|
||||
def GetEPGFromIscs(ChannelInfo):
|
||||
@ -562,11 +570,12 @@ def GetEPGFromIscs(ChannelInfo):
|
||||
except (requests.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
for i in epginfo:
|
||||
if not i in epginfo2:
|
||||
epginfo2.append(i)
|
||||
epginfo = epginfo2
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
for i in epginfo:
|
||||
if not i in epginfo2:
|
||||
epginfo2.append(i)
|
||||
epginfo = epginfo2
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from HCN
|
||||
def GetEPGFromHcn(ChannelInfo):
|
||||
@ -611,7 +620,8 @@ def GetEPGFromHcn(ChannelInfo):
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from POOQ
|
||||
def GetEPGFromPooq(ChannelInfo):
|
||||
@ -661,7 +671,8 @@ def GetEPGFromPooq(ChannelInfo):
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from EVERYON
|
||||
def GetEPGFromEveryon(ChannelInfo):
|
||||
@ -701,10 +712,63 @@ def GetEPGFromEveryon(ChannelInfo):
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
a = epgzip(epginfo)
|
||||
for i, j in a:
|
||||
print(i[1], j[1])
|
||||
print(i[2], j[2])
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from OKSUSU
|
||||
def GetEPGFromOksusu(ChannelInfo):
|
||||
ChannelId = ChannelInfo[0]
|
||||
ChannelName = ChannelInfo[1]
|
||||
ServiceId = ChannelInfo[3]
|
||||
lastday = today + datetime.timedelta(days=period-1)
|
||||
url = 'http://seg.oksusu.com:8080/seg/index.php'
|
||||
params = {'svc_id': ServiceId, 'start_time': today.strftime('%Y%m%d') + '00', 'end_time': lastday.strftime('%Y%m%d') + '24', 'tgroup': 'oksusutest_02|null', 'IF': 'IF-NSMEPG-003', 'response_format': 'json', 'm': 'ch_epg', 'ver': '1.0'}
|
||||
try:
|
||||
response = requests.get(url, params=params, headers=ua, timeout=timeout)
|
||||
response.raise_for_status()
|
||||
json_data = response.text
|
||||
try:
|
||||
data = json.loads(json_data, encoding='utf-8')
|
||||
if (data['channel'] is None) :
|
||||
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
else :
|
||||
programs = data['channel']['programs']
|
||||
for program in programs:
|
||||
startTime = endTime = programName = subprogramName = desc = actors = producers = category = episode = ''
|
||||
rebroadcast = False
|
||||
rating = 0
|
||||
programName = program['programName'].replace('...', '>').encode('utf-8')
|
||||
pattern = '^(.*?)(?:\s*[\(<]([\d,회]+)[\)>])?(?:\s*<([^<]*?)>)?(\((재)\))?$'
|
||||
matches = re.match(pattern, programName)
|
||||
if not (matches is None):
|
||||
programName = matches.group(1).strip() if matches.group(1) else ''
|
||||
subprogramName = matches.group(3).strip() if matches.group(3) else ''
|
||||
episode = matches.group(2).replace('회', '') if matches.group(2) else ''
|
||||
episode = '' if episode== '0' else episode
|
||||
rebroadcast = True if matches.group(5) else False
|
||||
startTime = datetime.datetime.fromtimestamp(int(program['startTime'])/1000)
|
||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||
endTime = datetime.datetime.fromtimestamp(int(program['endTime'])/1000)
|
||||
endTime = endTime.strftime('%Y%m%d%H%M%S')
|
||||
desc = program['synopsis'] if program['synopsis'] else ''
|
||||
actors = program['actorName'].replace('...','').strip(', ') if program['actorName'] else ''
|
||||
producers = program['directorName'].replace('...','').strip(', ') if program['directorName'] else ''
|
||||
if not (program['mainGenreName'] is None) :
|
||||
category = program['mainGenreName']
|
||||
rating = int(program['ratingCd']) if program['ratingCd'] else 0
|
||||
if(rating == 1):
|
||||
rating = 0
|
||||
programdata = {'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)
|
||||
time.sleep(0.001)
|
||||
except ValueError:
|
||||
if(debug): printError(ChannelName + CONTENT_ERROR)
|
||||
else: pass
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
|
||||
# Get EPG data from MBC
|
||||
def GetEPGFromMbc(ChannelInfo):
|
||||
ChannelId = ChannelInfo[0]
|
||||
@ -878,7 +942,8 @@ def GetEPGFromKbs(ChannelInfo):
|
||||
except (requests.exceptions.RequestException) as e:
|
||||
if(debug): printError(ChannelName + str(e))
|
||||
else: pass
|
||||
epgzip(epginfo)
|
||||
if(epginfo) :
|
||||
epgzip(epginfo)
|
||||
|
||||
# Get EPG data from ARIRANG
|
||||
def GetEPGFromArirang(ChannelInfo):
|
||||
|
Loading…
x
Reference in New Issue
Block a user