Update epg2xml.py
This commit is contained in:
parent
d4a49e5f97
commit
85e00c856f
29
epg2xml.py
29
epg2xml.py
@ -17,7 +17,7 @@ import pprint
|
|||||||
reload(sys)
|
reload(sys)
|
||||||
sys.setdefaultencoding('utf-8')
|
sys.setdefaultencoding('utf-8')
|
||||||
|
|
||||||
__version__ = '1.1.5'
|
__version__ = '1.1.6'
|
||||||
|
|
||||||
# Set variable
|
# Set variable
|
||||||
debug = False
|
debug = False
|
||||||
@ -54,13 +54,16 @@ def getEpg():
|
|||||||
ChannelName = escape(Channeldata['Name'])
|
ChannelName = escape(Channeldata['Name'])
|
||||||
ChannelSource = Channeldata['Source']
|
ChannelSource = Channeldata['Source']
|
||||||
ChannelServiceId = Channeldata['ServiceId']
|
ChannelServiceId = Channeldata['ServiceId']
|
||||||
ChannelISPName = '[' + str(Channeldata[MyISP+'Ch']) + '] ' + escape(Channeldata[MyISP+' Name'])
|
ChannelNumber = str(Channeldata[MyISP+'Ch']);
|
||||||
|
ChannelISPName = escape(Channeldata[MyISP+' Name'])
|
||||||
ChannelIconUrl = escape(Channeldata['Icon_url'])
|
ChannelIconUrl = escape(Channeldata['Icon_url'])
|
||||||
if not (Channeldata[MyISP+'Ch'] is None):
|
if not (Channeldata[MyISP+'Ch'] is None):
|
||||||
ChannelInfos.append([ChannelId, ChannelName, ChannelSource, ChannelServiceId])
|
ChannelInfos.append([ChannelId, ChannelName, ChannelSource, ChannelServiceId])
|
||||||
print(' <channel id="%s">' % (ChannelId))
|
print(' <channel id="%s">' % (ChannelId))
|
||||||
print(' <display-name>%s</display-name>' % (ChannelName))
|
print(' <display-name>%s</display-name>' % (ChannelName))
|
||||||
print(' <display-name>%s</display-name>' % (ChannelISPName))
|
print(' <display-name>%s</display-name>' % (ChannelISPName))
|
||||||
|
print(' <display-name>%s</display-name>' % (ChannelNumber))
|
||||||
|
print(' <display-name>%s</display-name>' % (ChannelNumber+' '+ChannelISPName))
|
||||||
if IconUrl:
|
if IconUrl:
|
||||||
print(' <icon src="%s/%s.png" />' % (IconUrl, ChannelId))
|
print(' <icon src="%s/%s.png" />' % (IconUrl, ChannelId))
|
||||||
else :
|
else :
|
||||||
@ -81,11 +84,11 @@ def getEpg():
|
|||||||
elif ChannelSource == 'LG':
|
elif ChannelSource == 'LG':
|
||||||
GetEPGFromLG(ChannelInfo)
|
GetEPGFromLG(ChannelInfo)
|
||||||
elif ChannelSource == 'SK':
|
elif ChannelSource == 'SK':
|
||||||
GetEPGFromSK(ChannelInfo)
|
GetEPGFromSK(ChannelInfo)
|
||||||
elif ChannelSource == 'SKY':
|
elif ChannelSource == 'SKY':
|
||||||
GetEPGFromSKY(ChannelInfo)
|
GetEPGFromSKY(ChannelInfo)
|
||||||
elif ChannelSource == 'NAVER':
|
elif ChannelSource == 'NAVER':
|
||||||
GetEPGFromNaver(ChannelInfo)
|
GetEPGFromNaver(ChannelInfo)
|
||||||
print('</tv>')
|
print('</tv>')
|
||||||
|
|
||||||
# Get EPG data from epg.co.kr
|
# Get EPG data from epg.co.kr
|
||||||
@ -220,6 +223,7 @@ def GetEPGFromLG(ChannelInfo):
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
html_data = response.content
|
html_data = response.content
|
||||||
data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
data = unicode(html_data, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
||||||
|
data = data.replace('<재>', '<재>')
|
||||||
strainer = SoupStrainer('table')
|
strainer = SoupStrainer('table')
|
||||||
soup = BeautifulSoup(data, 'lxml', parse_only=strainer, from_encoding='utf-8')
|
soup = BeautifulSoup(data, 'lxml', parse_only=strainer, from_encoding='utf-8')
|
||||||
html = soup.find('table', {'class':'datatable06'}).tbody.find_all('tr') if soup.find('table', {'class':'datatable06'}) else ''
|
html = soup.find('table', {'class':'datatable06'}).tbody.find_all('tr') if soup.find('table', {'class':'datatable06'}) else ''
|
||||||
@ -231,10 +235,13 @@ def GetEPGFromLG(ChannelInfo):
|
|||||||
programName = ''
|
programName = ''
|
||||||
subprogramName = ''
|
subprogramName = ''
|
||||||
episode = ''
|
episode = ''
|
||||||
matches = re.match('^(.*?)(\(([\d,]+)회\))?$', epg1[0].decode('string_escape'))
|
matches = re.match('(<재>?)?(.*?)(\[(.*)\])?\s?(\(([\d,]+)회\))?$', epg1[0].decode('string_escape'))
|
||||||
|
rebroadcast = False
|
||||||
if not (matches is None):
|
if not (matches is None):
|
||||||
programName = matches.group(1) if matches.group(1) else ''
|
programName = matches.group(2) if matches.group(2) else ''
|
||||||
episode = matches.group(3) if matches.group(3) else ''
|
subprogramName = matches.group(4) if matches.group(4) else ''
|
||||||
|
rebroadcast = True if matches.group(1) else False
|
||||||
|
episode = matches.group(6) if matches.group(6) else ''
|
||||||
startTime = datetime.datetime.strptime(epg1[1], '%Y-%m-%d %H:%M')
|
startTime = datetime.datetime.strptime(epg1[1], '%Y-%m-%d %H:%M')
|
||||||
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||||
endTime = datetime.datetime.strptime(epg2[1], '%Y-%m-%d %H:%M')
|
endTime = datetime.datetime.strptime(epg2[1], '%Y-%m-%d %H:%M')
|
||||||
@ -243,7 +250,6 @@ def GetEPGFromLG(ChannelInfo):
|
|||||||
desc = ''
|
desc = ''
|
||||||
actors = ''
|
actors = ''
|
||||||
producers = ''
|
producers = ''
|
||||||
rebroadcast = False
|
|
||||||
rating = 0
|
rating = 0
|
||||||
matches = re.match('(\d+)세이상 관람가', epg1[3].encode('utf-8'))
|
matches = re.match('(\d+)세이상 관람가', epg1[3].encode('utf-8'))
|
||||||
if not(matches is None): rating = int(matches.group(1))
|
if not(matches is None): rating = int(matches.group(1))
|
||||||
@ -479,10 +485,6 @@ def printLog(*args):
|
|||||||
def printError(*args):
|
def printError(*args):
|
||||||
print("Error : ", *args, file=sys.stderr)
|
print("Error : ", *args, file=sys.stderr)
|
||||||
|
|
||||||
#parser = argparse.ArgumentParser(description = 'EPG 정보 출력 프로그램')
|
|
||||||
#parser.add_argument('-v', '--version', action = 'version', version = '%(prog)s version : ' + __version__)
|
|
||||||
#parser.parse_args()
|
|
||||||
|
|
||||||
Settingfile = os.path.dirname(os.path.abspath(__file__)) + '/epg2xml.json'
|
Settingfile = os.path.dirname(os.path.abspath(__file__)) + '/epg2xml.json'
|
||||||
ChannelInfos = []
|
ChannelInfos = []
|
||||||
try:
|
try:
|
||||||
@ -505,7 +507,6 @@ except ValueError:
|
|||||||
printError("epg2xml." + JSON_SYNTAX_ERROR)
|
printError("epg2xml." + JSON_SYNTAX_ERROR)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description = 'EPG 정보를 출력하는 방법을 선택한다')
|
parser = argparse.ArgumentParser(description = 'EPG 정보를 출력하는 방법을 선택한다')
|
||||||
argu1 = parser.add_argument_group(description = 'IPTV 선택')
|
argu1 = parser.add_argument_group(description = 'IPTV 선택')
|
||||||
argu1.add_argument('-i', dest = 'MyISP', choices = ['KT', 'LG', 'SK'], help = '사용하는 IPTV : KT, LG, SK', default = MyISP)
|
argu1.add_argument('-i', dest = 'MyISP', choices = ['KT', 'LG', 'SK'], help = '사용하는 IPTV : KT, LG, SK', default = MyISP)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user