KODI를 위해서 CDATA 삭제

서브타이틀 추가
This commit is contained in:
wonipapa 2016-11-09 18:36:30 +09:00
parent 1b66072a87
commit 0c18720ac6

View File

@ -7,17 +7,16 @@ import httplib
import urllib import urllib
import json import json
import datetime import datetime
from bs4 import BeautifulSoup from bs4 import BeautifulSoup, SoupStrainer
import codecs import codecs
import socket import socket
import re import re
from xml.sax.saxutils import escape, unescape from xml.sax.saxutils import escape, unescape
import argparse import argparse
reload(sys) reload(sys)
sys.setdefaultencoding('utf-8') sys.setdefaultencoding('utf-8')
__version__ = '1.0.3' __version__ = '1.0.4'
# Set My Configuration # Set My Configuration
default_icon_url = '' # TV channel icon url (ex : http://www.example.com/Channels) default_icon_url = '' # TV channel icon url (ex : http://www.example.com/Channels)
@ -48,15 +47,14 @@ def getEpg():
# Print Channel information # Print Channel information
for ChannelInfo in ChannelInfos: for ChannelInfo in ChannelInfos:
ChannelId = ChannelInfo[0] ChannelId = ChannelInfo[0]
ChannelName = ChannelInfo[1] ChannelName = escape(ChannelInfo[1])
ChannelSource = ChannelInfo[2] ChannelSource = ChannelInfo[2]
ChannelServiceId = ChannelInfo[3] ChannelServiceId = ChannelInfo[3]
writeXML('\t<channel id="%s">' % (ChannelId)) writeXML(' <channel id="%s">' % (ChannelId))
writeXML('\t\t<display-name><![CDATA[%s]]></display-name>' % (ChannelName)) writeXML(' <display-name>%s</display-name>' % (ChannelName))
if IconUrl: if IconUrl:
writeXML('\t\t<icon src="%s/%s.png" />' % (IconUrl, ChannelId)) writeXML(' <icon src="%s/%s.png" />' % (IconUrl, ChannelId))
writeXML('\t</channel>') writeXML(' </channel>')
# Print Program Information # Print Program Information
for ChannelInfo in ChannelInfos: for ChannelInfo in ChannelInfos:
@ -78,8 +76,6 @@ def getEpg():
# Get EPG data from epg.co.kr # Get EPG data from epg.co.kr
def GetEPGFromEPG(ChannelInfos): def GetEPGFromEPG(ChannelInfos):
pattern = "Preview\('(.*?)','(.*?)','(.*?)','(.*?)','(.*?)','(.*?)','(.*?)'\)\">.*?<\/a>(.*?)<\/td>"
p = re.compile(pattern)
ChannelInfo = [ChannelInfos[i:i+5] for i in range(0, len(ChannelInfos),5)] ChannelInfo = [ChannelInfos[i:i+5] for i in range(0, len(ChannelInfos),5)]
html = [] html = []
@ -92,44 +88,37 @@ def GetEPGFromEPG(ChannelInfos):
url = 'http://schedule.epg.co.kr/php/guide/schedule_day_on.php?%snext=&old_sub_channel_group=110&old_sub_channel_group=110&old_top_channel_group=2&search_sub_category=&search_sub_channel_group=110&search_top_category=&search_top_channel_group=2&selectday=%s&selectday2=%s&weekchannel=&ymd=%s' % (churl, day, day, day) url = 'http://schedule.epg.co.kr/php/guide/schedule_day_on.php?%snext=&old_sub_channel_group=110&old_sub_channel_group=110&old_top_channel_group=2&search_sub_category=&search_sub_channel_group=110&search_top_category=&search_top_channel_group=2&selectday=%s&selectday2=%s&weekchannel=&ymd=%s' % (churl, day, day, day)
u = urllib.urlopen(url).read() u = urllib.urlopen(url).read()
data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore') data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
soup = BeautifulSoup(data,'lxml', from_encoding='utf-8') strainer = SoupStrainer('table', {"width" : "125"})
soup = BeautifulSoup(data, 'lxml', parse_only=strainer, from_encoding='utf-8')
html.append(soup.select('td > a[href^="JavaScript:ViewContent"]')) html.append(soup.select('td > a[href^="JavaScript:ViewContent"]'))
for row in html: for row in html:
for i, cell in enumerate(row): for cell in row:
td = cell.parent td = cell.parent
epgdata = p.findall(str(td)) epgdata = re.findall("[\(]?'(.*?)'[,\)]", str(td))
programName = unescape(epgdata[0][1].decode('string_escape')) programName = unescape(epgdata[2].decode('string_escape'))
channelId = epgdata[0][2] subprogramName = ''
startTime, endTime = unescape(epgdata[0][3]).split('<br>~') channelId = epgdata[3]
startTime, endTime = unescape(epgdata[4]).split('<br>~')
startTime = str(today.year) + '/' + startTime startTime = str(today.year) + '/' + startTime
startTime = datetime.datetime.strptime(startTime, '%Y/%m/%d %p %I:%M') startTime = datetime.datetime.strptime(startTime, '%Y/%m/%d %p %I:%M')
startTime = startTime.strftime('%Y%m%d%H%M%S') startTime = startTime.strftime('%Y%m%d%H%M%S')
endTime = str(today.year) + '/' + endTime endTime = str(today.year) + '/' + endTime
endTime = datetime.datetime.strptime(endTime, '%Y/%m/%d %p %I:%M') endTime = datetime.datetime.strptime(endTime, '%Y/%m/%d %p %I:%M')
endTime = endTime.strftime('%Y%m%d%H%M%S') endTime = endTime.strftime('%Y%m%d%H%M%S')
category = escape(epgdata[0][4]) category = epgdata[5].split('-')[0].strip()
actors = escape(epgdata[0][5]) actors = epgdata[6]
producer = escape(epgdata[0][6]) producers = epgdata[7]
image = epgdata[0][7] matches = re.match('^(.*?)\s*(<(.*)>)?(\(([\d,]+)회\))?$', programName)
checkRebroadcast = re.search('rebroadcast', image) if not (matches is None):
if not (checkRebroadcast is None) : programName = matches.group(1) if matches.group(1) else ''
programName = programName + ' (재방송)' subprogramName = matches.group(3) if matches.group(3) else ''
checkRating = re.findall('7|12|15|19', image) episode = matches.group(5) if matches.group(5) else ''
if len(checkRating) == 0: rating = 0
rating = '전체 연령 시청가' for image in td.findAll('img'):
else: if 'rebroadcast' in image.get('src') : programName = programName + '재방송'
rating = '%s세 이상 시청가' % (checkRating[0]) if 'grade' in image.get('src') : rating = int(image.get('src')[22:].replace('.gif',''))
episode = None desc = ''
checkEpisode = re.search('(?<=\()[\d]+', programName) programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rating':rating}
if not (checkEpisode is None):
episode = int(checkEpisode.group())
desc = programName
if episode : desc = desc + '\n회차 : ' + str(episode) + ''
desc = desc + '\n장르 : ' + category
if actors : desc = desc + '\n출연 : ' + actors
if producer : desc = desc + '\n제작 : ' + producer
desc = desc + '\n등급 : ' + rating
programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'desc':desc, 'actors':actors, 'producer':producer, 'category':category, 'episode':episode, 'rating':rating}
writeProgram(programdata) writeProgram(programdata)
# Get EPG data from KT # Get EPG data from KT
@ -142,30 +131,33 @@ def GetEPGFromKT(ChannelInfo):
url = 'http://tv.olleh.com/renewal_sub/liveTv/pop_schedule_week.asp?ch_name=&ch_no=%s&nowdate=%s&seldate=%s&tab_no=1' % (ServiceId, day, day) url = 'http://tv.olleh.com/renewal_sub/liveTv/pop_schedule_week.asp?ch_name=&ch_no=%s&nowdate=%s&seldate=%s&tab_no=1' % (ServiceId, day, day)
u = urllib.urlopen(url).read() u = urllib.urlopen(url).read()
data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore') data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
soup = BeautifulSoup(data,'lxml', from_encoding='utf-8') strainer = SoupStrainer('table', {'id':'pop_day'})
html = soup.find('table', {'id':'pop_day'}).tbody.findAll('tr') soup = BeautifulSoup(data, 'lxml', parse_only=strainer, from_encoding='utf-8')
html = soup.find('table', {'id':'pop_day'}).tbody.findAll('tr') if soup.find('table', {'id':'pop_day'}) else ''
for row in html: for row in html:
for cell in [row.findAll('td')]: for cell in [row.findAll('td')]:
epginfo.append([cell[1].text, str(day) + ' ' + cell[0].text, cell[4].text, cell[2].text]) epginfo.append([cell[1].text, str(day) + ' ' + cell[0].text, cell[4].text, cell[2].text])
for epg1, epg2 in zip(epginfo, epginfo[1:]): for epg1, epg2 in zip(epginfo, epginfo[1:]):
programName = epg1[0].decode('string_escape') programName = ''
subprogrmaName = ''
matches = re.match('^(.*?)( <(.*)>)?$', epg1[0].decode('string_escape'))
if not (matches is None):
programName = matches.group(1) if matches.group(1) else ''
subprogramName = matches.group(3) if matches.group(3) 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')
endTime = endTime.strftime('%Y%m%d%H%M%S') endTime = endTime.strftime('%Y%m%d%H%M%S')
category = escape(epg1[2]) category = epg1[2]
rating = escape(epg1[3]) rating = 0
if rating == 'all세 이상': matches = re.match('(\d+)', epg1[3])
rating = '전체 연령 시청가' if not(matches is None): rating = int(matches.group())
else: desc = ''
rating = rating + ' 시청가' actors = ''
desc = programName + '\n장르 : ' + category + '\n등급 : ' + rating producers = ''
actors = ''; episode = ''
producer = ''; programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rating':rating}
episode = '';
programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'desc':desc, 'actors':actors, 'producer':producer, 'category':category, 'episode':episode, 'rating':rating}
writeProgram(programdata) writeProgram(programdata)
# Get EPG data from LG # Get EPG data from LG
def GetEPGFromLG(ChannelInfo): def GetEPGFromLG(ChannelInfo):
channelId = ChannelInfo[0] channelId = ChannelInfo[0]
@ -173,30 +165,35 @@ def GetEPGFromLG(ChannelInfo):
epginfo = [] epginfo = []
for k in range(period): for k in range(period):
day = today + datetime.timedelta(days=k) day = today + datetime.timedelta(days=k)
url = 'https://www.uplus.co.kr/css/chgi/chgi/RetrieveTvSchedule.hpi?chnlCd=%s&evntCmpYmd=%s' % (ServiceId, day.strftime('%Y%m%d')) url = 'http://www.uplus.co.kr/css/chgi/chgi/RetrieveTvSchedule.hpi?chnlCd=%s&evntCmpYmd=%s' % (ServiceId, day.strftime('%Y%m%d'))
u = urllib.urlopen(url).read() u = urllib.urlopen(url).read()
data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore') data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
soup = BeautifulSoup(data,'lxml', from_encoding='utf-8') strainer = SoupStrainer('table')
soup = BeautifulSoup(data, 'lxml', parse_only=strainer, from_encoding='utf-8')
html = soup.find('table', {'class':'datatable06'}).tbody.findAll('tr') if soup.find('table', {'class':'datatable06'}) else '' html = soup.find('table', {'class':'datatable06'}).tbody.findAll('tr') if soup.find('table', {'class':'datatable06'}) else ''
for row in html: for row in html:
for cell in [row.findAll('td')]: for cell in [row.findAll('td')]:
epginfo.append([cell[1].text.strip(), str(day) + ' ' + cell[0].text, cell[2].text.strip(), cell[1].find('img', alt=True)['alt'].strip()]) epginfo.append([cell[1].text.strip(), str(day) + ' ' + cell[0].text, cell[2].text.strip(), cell[1].find('img', alt=True)['alt'].strip()])
for epg1, epg2 in zip(epginfo, epginfo[1:]): for epg1, epg2 in zip(epginfo, epginfo[1:]):
programName = epg1[0].decode('string_escape') programName = ''
subprogramName = ''
episode = ''
matches = re.match('^(.*?)(\(([\d,]+)회\))?$', epg1[0].decode('string_escape'))
if not (matches is None):
programName = matches.group(1) if matches.group(1) else ''
episode = int(matches.group(3)) if matches.group(3) 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")
endTime = endTime.strftime("%Y%m%d%H%M%S") endTime = endTime.strftime("%Y%m%d%H%M%S")
category = escape(epg1[2]) category = epg1[2]
rating = escape(epg1[3]) rating = 0
desc = programName + '\n장르 : ' + category + '\n등급 : ' + rating matches = re.match('(\d+)세이상 관람가', epg1[3].encode('utf-8'))
actors = ''; if not(matches is None): rating = int(matches.group(1))
producer = ''; desc = ''
episode = None actors = ''
checkEpisode = re.search('(?<=\()[\d]+', programName) producers = ''
if not (checkEpisode is None): programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rating':rating}
episode = int(checkEpisode.group())
programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'desc':desc, 'actors':actors, 'producer':producer, 'category':category, 'episode':episode, 'rating':rating}
writeProgram(programdata) writeProgram(programdata)
# Get EPG data from SK # Get EPG data from SK
@ -209,36 +206,28 @@ def GetEPGFromSK(ChannelInfo):
data = json.loads(u, encoding='utf-8') data = json.loads(u, encoding='utf-8')
programs = data['channel']['programs'] programs = data['channel']['programs']
for program in programs: for program in programs:
programName = program['programName'] programName = ''
if programName: subprogramName = ''
programName = programName.replace('(재)', ' (재방송)') episode = ''
actors = program['actorName'] rebroadcast = ''
if actors: actors = escape(actors) matches = re.match('^(.*?)(?:\s*[\(<]([\d,회]+)[\)>])?(?:\s*<([^<]*?)>)?(\((재)\))?$', program['programName'].replace('...', '>').encode('utf-8'))
producer = program['directorName'] if not (matches is None):
if producer: producer = escape(producer) 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 ''
rebroadcast = 'Y' if matches.group(5) else 'N'
if rebroadcast == 'Y': programName = programName + ' (재방송)'
actors = program['actorName'].replace('...','').strip(', ') if program['actorName'] else ''
producers = program['directorName'].replace('...','').strip(', ') if program['directorName'] else ''
startTime = datetime.datetime.fromtimestamp(int(program['startTime'])/1000) startTime = datetime.datetime.fromtimestamp(int(program['startTime'])/1000)
startTime = startTime.strftime('%Y%m%d%H%M%S') startTime = startTime.strftime('%Y%m%d%H%M%S')
endTime = datetime.datetime.fromtimestamp(int(program['endTime'])/1000) endTime = datetime.datetime.fromtimestamp(int(program['endTime'])/1000)
endTime = endTime.strftime('%Y%m%d%H%M%S') endTime = endTime.strftime('%Y%m%d%H%M%S')
category = program['mainGenreName'] + '-' + program['subGenreName'] category = program['mainGenreName']
if category: category = escape(category) rating = int(program['ratingCd']) if program['programName'] else 0
rating = program['ratingCd'] desc = ''
if rating == '0': if program['synopsis'] : desc = program['synopsis']
rating = '전체 시청가' programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rating':rating}
else :
rating = '%s세 이상 시청가' % (rating)
episode = None
checkEpisode = re.search('(?<=\()[\d]+', programName)
if not (checkEpisode is None):
episode = int(checkEpisode.group())
desc = programName
if episode : desc = desc + '\n회차 : ' + str(episode) + ''
desc = desc + '\n장르 : ' + category
if actors : desc = desc + '\n출연 : ' + actors
if producer : desc = desc + '\n제작 : ' + producer
desc = desc + '\n등급 : ' + rating
if program['synopsis'] : desc = desc + '\n' + program['synopsis']
programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'desc':desc, 'actors':actors, 'producer':producer, 'category':category, 'episode':episode, 'rating':rating}
writeProgram(programdata) writeProgram(programdata)
# Get EPG data from SKY # Get EPG data from SKY
@ -252,37 +241,25 @@ def GetEPGFromSKY(ChannelInfo):
data = json.loads(u, encoding='utf-8') data = json.loads(u, encoding='utf-8')
programs = data['scheduleListIn'] programs = data['scheduleListIn']
for program in {v['starttime']:v for v in programs}.values(): for program in {v['starttime']:v for v in programs}.values():
programName = unescape(program['program_name']).replace('lt;','<').replace('gt;','>').replace('amp;','&') programName = unescape(program['program_name']).replace('lt;','<').replace('gt;','>').replace('amp;','&') if program['program_name'] else ''
rebroadcast = program['rebroad'] subprogramName = unescape(program['program_subname']).replace('lt;','<').replace('gt;','>').replace('amp;','&') if program['program_subname'] else ''
rebroadcast = program['rebroad'] if program['rebroad'] else ''
if rebroadcast == 'Y': programName = programName + ' (재방송)' if rebroadcast == 'Y': programName = programName + ' (재방송)'
actors = program['cast'] actors = program['cast'].replace('...','').strip(', ') if program['cast'] else ''
if actors: actors = escape(actors) producers = program['dirt'].replace('...','').strip(', ') if program['dirt'] else ''
producer = program['dirt']
if producer: producer = escape(producer)
startTime = program['starttime'] startTime = program['starttime']
endTime = program['endtime'] endTime = program['endtime']
category = program['program_category1'] + '/' + program['program_category2'] category = program['program_category1']
if category: category = escape(category) rating = int(program['grade']) if program['grade'] else ''
rating = escape(program['grade']) episode = program['episode_id'] if program['episode_id'] else ''
if rating == '0':
rating = '전체 시청가'
else :
rating = '%s세 이상 시청가' % (rating)
episode = program['episode_id']
if episode : episode = int(episode) if episode : episode = int(episode)
description = program['description'] description = unescape(program['description']).replace('lt;','<').replace('gt;','>').replace('amp;','&') if program['description'] else ''
if description: description = unescape(description).replace('lt;','<').replace('gt;','>').replace('amp;','&') if description: description = unescape(description).replace('lt;','<').replace('gt;','>').replace('amp;','&')
summary = program['summary'] summary = unescape(program['summary']).replace('lt;','<').replace('gt;','>').replace('amp;','&') if program['summary'] else ''
if summary: summary = unescape(summary).replace('lt;','<').replace('gt;','>').replace('amp;','&') desc = ''
desc = programName if description: desc = description
if episode : desc = desc + '\n회차 : ' + str(episode) + ''
desc = desc + '\n장르 : ' + category
if actors : desc = desc + '\n출연 : ' + actors
if producer : desc = desc + '\n제작 : ' + producer
desc = desc + '\n등급 : ' + rating
if description: desc = desc + '\n' + description
if summary : desc = desc + '\n' + summary if summary : desc = desc + '\n' + summary
programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'desc':desc, 'actors':actors, 'producer':producer, 'category':category, 'episode':episode, 'rating':rating} programdata = {'channelId':channelId, 'startTime':startTime, 'endTime':endTime, 'programName':programName, 'subprogramName':subprogramName, 'desc':desc, 'actors':actors, 'producers':producers, 'category':category, 'episode':episode, 'rating':rating}
writeProgram(programdata) writeProgram(programdata)
# Write Program # Write Program
@ -290,33 +267,53 @@ def writeProgram(programdata):
channelId = programdata['channelId'] channelId = programdata['channelId']
startTime = programdata['startTime'] startTime = programdata['startTime']
endTime = programdata['endTime'] endTime = programdata['endTime']
programName = programdata['programName'] programName = escape(programdata['programName'])
desc = programdata['desc'] subprogramName = escape(programdata['subprogramName'])
actors = programdata['actors'] actors = escape(programdata['actors'])
producer = programdata['producer'] producers = escape(programdata['producers'])
category = programdata['category'] category = escape(programdata['category'])
episode = programdata['episode'] episode = programdata['episode']
rating = programdata['rating'] if programdata['rating'] == 0 :
rating = '전체 관람가'
else :
rating = '%s세 이상 관람가' % (programdata['rating'])
desc = programName
if subprogramName : desc = desc + '\n부제 : ' + subprogramName
if episode : desc = desc + '\n회차 : ' + str(episode) + ''
desc = desc + '\n장르 : ' + category
if actors : desc = desc + '\n출연 : ' + actors
if producers : desc = desc + '\n제작 : ' + producers
desc = desc + '\n등급 : ' + rating
if programdata['desc'] : desc = desc + '\n' + escape(programdata['desc'])
contentTypeDict={'교양':'Arts / Culture (without music)', '만화':'Cartoons / Puppets', '교육':'Education / Science / Factual topics', '취미':'Leisure hobbies', '드라마':'Movie / Drama', '영화':'Movie / Drama', '음악':'Music / Ballet / Dance', '뉴스':'News / Current affairs', '다큐':'Documentary', '시사/다큐':'Documentary', '연예':'Show / Game show', '스포츠':'Sports', '홈쇼핑':'Advertisement / Shopping'} contentTypeDict={'교양':'Arts / Culture (without music)', '만화':'Cartoons / Puppets', '교육':'Education / Science / Factual topics', '취미':'Leisure hobbies', '드라마':'Movie / Drama', '영화':'Movie / Drama', '음악':'Music / Ballet / Dance', '뉴스':'News / Current affairs', '다큐':'Documentary', '시사/다큐':'Documentary', '연예':'Show / Game show', '스포츠':'Sports', '홈쇼핑':'Advertisement / Shopping'}
contentType = '' contentType = ''
for key, value in contentTypeDict.iteritems(): for key, value in contentTypeDict.iteritems():
if category.startswith(key): if category.startswith(key):
contentType = value contentType = value
print '\t<programme start="%s +0900" stop="%s +0900" channel="%s">' % (startTime, endTime,channelId) print ' <programme start="%s +0900" stop="%s +0900" channel="%s">' % (startTime, endTime,channelId)
print '\t\t<title lang="kr"><![CDATA[%s]]></title>' % (programName) print ' <title lang="kr">%s</title>' % (programName)
print '\t\t<desc lang="kr"><![CDATA[%s]]></desc>' % (desc) if subprogramName :
if actors or producer: print ' <sub-title lang="kr">%s</sub-title>' % (subprogramName)
print '\t\t<credits>' print ' <desc lang="kr">%s</desc>' % (desc)
if actors: print '\t\t\t<actor>%s</actor>' % (actors) if actors or producers:
if producer: print '\t\t\t<producer>%s</producer>' % (producer) print ' <credits>'
print '\t\t</credits>' if actors:
print '\t\t<category lang="kr">%s</category>' % (category) for actor in actors.split(','):
print '\t\t<category lang="en">%s</category>' % (contentType) if actor: print ' <actor>%s</actor>' % (actor)
if producers:
for producer in producers.split(','):
if producer: print ' <producer>%s</producer>' % (producer)
print ' </credits>'
if category: print ' <category lang="kr">%s</category>' % (category)
if contentType: print ' <category lang="en">%s</category>' % (contentType)
if episode: if episode:
print '\t\t<episode-num system="onscreen">%s</episode-num>' % (episode) print ' <episode-num system="onscreen">%s</episode-num>' % (episode)
print '\t\t<rating system="KMRB">\n\t\t\t<value>%s</value>\n\t\t</rating>' % (rating) if rating:
print '\t</programme>' print ' <rating system="KMRB">'
print ' <value>%s</value>' % (rating)
print ' </rating>'
print ' </programme>'
# Write XML # Write XML
def writeXML(data): def writeXML(data):
print data print data
@ -344,7 +341,7 @@ if args.iptv:
if args.limit: if args.limit:
period = args.limit period = args.limit
else: else:
period = default_fetch_limit; period = default_fetch_limit
if args.icon: if args.icon:
IconUrl = args.icon IconUrl = args.icon
@ -357,9 +354,8 @@ elif args.socket:
sock.connect(args.socket) sock.connect(args.socket)
sockfile = sock.makefile('w+') sockfile = sock.makefile('w+')
sys.stdout = sockfile sys.stdout = sockfile
writeXML('<?xml version="1.0" encoding="UTF-8"?>') writeXML('<?xml version="1.0" encoding="UTF-8"?>')
writeXML('<!DOCTYPE tv SYSTEM "xmltv.dtd">') writeXML('<!DOCTYPE tv SYSTEM "xmltv.dtd">\n')
writeXML('<tv generator-info-name="xmltv">') writeXML('<tv generator-info-name="epg2xml.py">')
getEpg() getEpg()
writeXML('</tv>') writeXML('</tv>')