Merge pull request #66 from wonipapa/devel

Update 1.2.3p4
This commit is contained in:
wonipapa 2017-11-29 11:51:59 +09:00 committed by GitHub
commit 3af1a6b97b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 181 additions and 33 deletions

View File

@ -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();
foreach(range(1, $GLOBALS['period']) as $k) :
$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;
@ -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) {

View File

@ -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,6 +214,7 @@ def GetEPGFromEPG(ChannelInfo):
else: pass
except (requests.exceptions.RequestException) as e:
if(debug): printError(ChannelName + str(e))
if(epginfo) :
epgzip(epginfo)
# Get EPG data from KT
@ -256,6 +260,7 @@ def GetEPGFromKT(ChannelInfo):
except (requests.exceptions.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
epgzip(epginfo)
# Get EPG data from LG
@ -305,6 +310,7 @@ def GetEPGFromLG(ChannelInfo):
except (requests.exceptions.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
epgzip(epginfo)
# Get EPG data from SK
@ -416,6 +422,7 @@ def GetEPGFromSKB(ChannelInfo):
except (requests.exceptions.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
epgzip(epginfo)
# Get EPG data from SKY
@ -510,6 +517,7 @@ def GetEPGFromNaver(ChannelInfo):
except (requests.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
epgzip(epginfo)
# Get EPG data from ISCS
@ -562,6 +570,7 @@ def GetEPGFromIscs(ChannelInfo):
except (requests.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
for i in epginfo:
if not i in epginfo2:
epginfo2.append(i)
@ -611,6 +620,7 @@ def GetEPGFromHcn(ChannelInfo):
except (requests.exceptions.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
epgzip(epginfo)
# Get EPG data from POOQ
@ -661,6 +671,7 @@ def GetEPGFromPooq(ChannelInfo):
except (requests.exceptions.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
epgzip(epginfo)
# Get EPG data from EVERYON
@ -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,6 +942,7 @@ def GetEPGFromKbs(ChannelInfo):
except (requests.exceptions.RequestException) as e:
if(debug): printError(ChannelName + str(e))
else: pass
if(epginfo) :
epgzip(epginfo)
# Get EPG data from ARIRANG