버전 1.0.2
This commit is contained in:
parent
4ea4ee4d04
commit
4793813e10
432
epg2xml.py
432
epg2xml.py
@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import httplib
|
||||||
import urllib
|
import urllib
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
@ -10,67 +11,50 @@ from bs4 import BeautifulSoup
|
|||||||
import codecs
|
import codecs
|
||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
from xml.sax.saxutils import escape
|
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.1'
|
__version__ = '1.0.2'
|
||||||
|
|
||||||
# Set My Configuration
|
# Set My Configuration
|
||||||
MyISP = 'ChangeThis' # 사용하는 IPTV선택 (ex :KT, LG, SK)
|
default_icon_url = '' # TV channel icon url (ex : http://www.example.com/Channels)
|
||||||
userid = 'ChangeThis' #tvheadend admin 아이디 (ex : admin)
|
default_fetch_limit = 2 # epg 데이터 가져오는 기간
|
||||||
userpw = 'ChangeThis' #tvheadedn admin 비밀번호 (ex : admin)
|
default_xml_filename = 'xmltv.xml' # epg 저장시 기본 저장 이름 (ex: /home/tvheadend/xmltv.xml)
|
||||||
host = 'ChangeThis' #tvheadend 서버 내부 IP (ex: 192.168.0.2)
|
default_xml_socket = 'xmltv.sock' # External XMLTV 사용시 기본 소켓 이름 (ex: /home/tvheadend/xmltv.sock)
|
||||||
port = '9981' #tvheadend port
|
|
||||||
ChDelimiter = '-SD' #HD채널과 SD 채널 구분자
|
|
||||||
offset = 500 # SD Channel Offset Number - SD 채널 사용시 HD 채널과 번호차
|
|
||||||
iconurl = '' #TV channel icon url (ex : http://www.example.com/Channels)
|
|
||||||
default_xml_filename='xmltv.xml' # epg 저장시 기본 저장 이름 (ex: /home/tvheadend/xmltv.xml)
|
|
||||||
default_xml_socket='xmltv.sock' # External XMLTV 사용시 기본 소켓 이름 (ex: /home/tvheadend/xmltv.sock)
|
|
||||||
# Set My Configuration
|
# Set My Configuration
|
||||||
|
|
||||||
hostinfo = userid + ':' + userpw + '@' + host + ':' + port
|
|
||||||
|
|
||||||
# Set date
|
# Set date
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
nextday = today + datetime.timedelta(days=1)
|
|
||||||
|
|
||||||
# Get Enabled Channel information
|
|
||||||
def getMyChannel():
|
|
||||||
MyChannelNumber = []
|
|
||||||
MyChannelurl = 'http://%s/api/channel/grid?all=1&dir=ASC&limit=999999999&sort=number&start=0' % (hostinfo)
|
|
||||||
MyChannels = json.loads(urllib.urlopen(MyChannelurl).read())
|
|
||||||
for i, MyChannel in enumerate(MyChannels['entries']):
|
|
||||||
if MyChannel['enabled']:
|
|
||||||
if ChDelimiter in MyChannel['name']:
|
|
||||||
MyChannelNumber.append(MyChannel['number'] - offset)
|
|
||||||
else:
|
|
||||||
MyChannelNumber.append(MyChannel['number'])
|
|
||||||
return list(set(MyChannelNumber))
|
|
||||||
|
|
||||||
# Get epg data
|
# Get epg data
|
||||||
def getEpg(channelnumber):
|
def getEpg():
|
||||||
Channelfile = os.path.dirname(os.path.abspath(__file__)) + '/' + MyISP + 'Ch.json'
|
Channelfile = os.path.dirname(os.path.abspath(__file__)) + '/Channel.json'
|
||||||
ChannelInfos = []
|
ChannelInfos = []
|
||||||
SiteEPG = [] #For epg.co.kr
|
SiteEPG = [] #For epg.co.kr
|
||||||
with open(Channelfile) as f: # Read Channel Information file
|
with open(Channelfile) as f: # Read Channel Information file
|
||||||
Channeldata = json.load(f)
|
Channeldata = json.load(f)
|
||||||
for chinfo in Channeldata:
|
for chinfo in Channeldata:
|
||||||
for i in channelnumber:
|
if chinfo['Enabled'] == 1 :
|
||||||
if i == chinfo[MyISP+'Ch']:
|
if MyISP == 'KT' and not( chinfo['KTCh'] is None) :
|
||||||
ChannelInfos.append([chinfo['Id'], chinfo['Name'], chinfo['Source'], chinfo['ServiceId']])
|
ChannelInfos.append([chinfo['Id'], chinfo['Name'], chinfo['Source'], chinfo['ServiceId']])
|
||||||
|
elif MyISP == 'LG' and not( chinfo['LGCh'] is None) :
|
||||||
|
ChannelInfos.append([chinfo['Id'], chinfo['Name'], chinfo['Source'], chinfo['ServiceId']])
|
||||||
|
elif MyISP == 'SK' and not( chinfo['SKCh'] is None) :
|
||||||
|
ChannelInfos.append([chinfo['Id'], chinfo['Name'], chinfo['Source'], chinfo['ServiceId']])
|
||||||
|
|
||||||
# Print Channel information
|
# Print Channel information
|
||||||
for ChannelInfo in ChannelInfos:
|
for ChannelInfo in ChannelInfos:
|
||||||
ChannelId = ChannelInfo[0]
|
ChannelId = ChannelInfo[0]
|
||||||
ChannelName = escape(ChannelInfo[1])
|
ChannelName = ChannelInfo[1]
|
||||||
ChannelSource = ChannelInfo[2]
|
ChannelSource = ChannelInfo[2]
|
||||||
ChannelServiceId = ChannelInfo[3]
|
ChannelServiceId = ChannelInfo[3]
|
||||||
writeXML('\t<channel id="%s">' % (ChannelId))
|
writeXML('\t<channel id="%s">' % (ChannelId))
|
||||||
writeXML('\t\t<display-name>%s</display-name>' % (ChannelName))
|
writeXML('\t\t<display-name><![CDATA[%s]]></display-name>' % (ChannelName))
|
||||||
if iconurl:
|
if IconUrl:
|
||||||
writeXML('\t\t<icon src="%s/%s.png" />' % (iconurl, ChannelId))
|
writeXML('\t\t<icon src="%s/%s.png" />' % (IconUrl, ChannelId))
|
||||||
writeXML('\t</channel>')
|
writeXML('\t</channel>')
|
||||||
|
|
||||||
|
|
||||||
@ -97,108 +81,82 @@ def GetEPGFromEPG(ChannelInfos):
|
|||||||
pattern = "Preview\('(.*?)','(.*?)','(.*?)','(.*?)','(.*?)','(.*?)','(.*?)'\)\">.*?<\/a>(.*?)<\/td>"
|
pattern = "Preview\('(.*?)','(.*?)','(.*?)','(.*?)','(.*?)','(.*?)','(.*?)'\)\">.*?<\/a>(.*?)<\/td>"
|
||||||
p = re.compile(pattern)
|
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 = []
|
||||||
for i in range(len(ChannelInfo)):
|
for i in range(len(ChannelInfo)):
|
||||||
churl = ''
|
churl = ''
|
||||||
for j in range(len(ChannelInfo[i])):
|
for j in range(len(ChannelInfo[i])):
|
||||||
churl += 'checkchannel%5B' + str(ChannelInfo[i][j][3]) + '%5D=' + str(ChannelInfo[i][j][0]) + '&'
|
churl += 'checkchannel%5B' + str(ChannelInfo[i][j][3]) + '%5D=' + str(ChannelInfo[i][j][0]) + '&'
|
||||||
|
for k in range(period):
|
||||||
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, today, today, today)
|
day = today + datetime.timedelta(days=k)
|
||||||
u = urllib.urlopen(url).read()
|
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)
|
||||||
data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
u = urllib.urlopen(url).read()
|
||||||
soup = BeautifulSoup(data,'lxml', from_encoding='utf-8')
|
data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
||||||
html = soup.select('td > a[href^="JavaScript:ViewContent"]')
|
soup = BeautifulSoup(data,'lxml', from_encoding='utf-8')
|
||||||
|
html.append(soup.select('td > a[href^="JavaScript:ViewContent"]'))
|
||||||
for i, cell in enumerate(html):
|
for row in html:
|
||||||
td = cell.parent
|
for i, cell in enumerate(row):
|
||||||
epgdata = p.findall(str(td))
|
td = cell.parent
|
||||||
programName = escape(epgdata[0][1])
|
epgdata = p.findall(str(td))
|
||||||
channelId = epgdata[0][2]
|
programName = unescape(epgdata[0][1].decode('string_escape'))
|
||||||
startTime, endTime = epgdata[0][3].split('<br>~')
|
channelId = epgdata[0][2]
|
||||||
startTime = str(today.year) + '/' + startTime
|
startTime, endTime = unescape(epgdata[0][3]).split('<br>~')
|
||||||
startTime = datetime.datetime.strptime(startTime, "%Y/%m/%d %p %I:%M")
|
startTime = str(today.year) + '/' + startTime
|
||||||
startTime = startTime.strftime("%Y%m%d%H%M%S")
|
startTime = datetime.datetime.strptime(startTime, '%Y/%m/%d %p %I:%M')
|
||||||
endTime = str(today.year) + '/' + endTime
|
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||||
endTime = datetime.datetime.strptime(endTime, "%Y/%m/%d %p %I:%M")
|
endTime = str(today.year) + '/' + endTime
|
||||||
endTime = endTime.strftime("%Y%m%d%H%M%S")
|
endTime = datetime.datetime.strptime(endTime, '%Y/%m/%d %p %I:%M')
|
||||||
category = escape(epgdata[0][4])
|
endTime = endTime.strftime('%Y%m%d%H%M%S')
|
||||||
actors = escape(epgdata[0][5])
|
category = escape(epgdata[0][4])
|
||||||
producer = escape(epgdata[0][6])
|
actors = escape(epgdata[0][5])
|
||||||
image = epgdata[0][7]
|
producer = escape(epgdata[0][6])
|
||||||
checkRebroadcast = re.search('rebroadcast', image)
|
image = epgdata[0][7]
|
||||||
if not (checkRebroadcast is None) :
|
checkRebroadcast = re.search('rebroadcast', image)
|
||||||
programName = programName + ' (재방송)'
|
if not (checkRebroadcast is None) :
|
||||||
checkRating = re.findall('7|12|15|19', image)
|
programName = programName + ' (재방송)'
|
||||||
if len(checkRating) == 0:
|
checkRating = re.findall('7|12|15|19', image)
|
||||||
rating = '모든 연령 시청가'
|
if len(checkRating) == 0:
|
||||||
else:
|
rating = '전체 연령 시청가'
|
||||||
rating = '%s세 이상 시청가' % (checkRating[0])
|
else:
|
||||||
|
rating = '%s세 이상 시청가' % (checkRating[0])
|
||||||
episode = None
|
episode = None
|
||||||
checkEpisode = re.search('(?<=\()[\d]+', programName)
|
checkEpisode = re.search('(?<=\()[\d]+', programName)
|
||||||
if not (checkEpisode is None):
|
if not (checkEpisode is None):
|
||||||
episode = int(checkEpisode.group())
|
episode = int(checkEpisode.group())
|
||||||
|
desc = programName
|
||||||
desc = programName
|
if episode : desc = desc + '\n회차 : ' + str(episode) + '회'
|
||||||
if episode : desc = desc + '\n회차 : ' + str(episode) + '회'
|
desc = desc + '\n장르 : ' + category
|
||||||
desc = desc + '\n장르 : ' + category
|
if actors : desc = desc + '\n출연 : ' + actors
|
||||||
if actors : desc = desc + '\n출연 : ' + actors
|
if producer : desc = desc + '\n제작 : ' + producer
|
||||||
if producer : desc = desc + '\n제작 : ' + producer
|
desc = desc + '\n등급 : ' + rating
|
||||||
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}
|
||||||
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
|
||||||
def GetEPGFromKT(ChannelInfo):
|
def GetEPGFromKT(ChannelInfo):
|
||||||
channelId = ChannelInfo[0]
|
channelId = ChannelInfo[0]
|
||||||
ServiceId = ChannelInfo[3]
|
ServiceId = ChannelInfo[3]
|
||||||
|
epginfo = []
|
||||||
todayurl = 'http://tv.olleh.com/renewal_sub/liveTv/pop_schedule_week.asp?ch_name=&ch_no=%s&nowdate=%s&seldate=%s&tab_no=1' %(ServiceId, today, today)
|
for k in range(period):
|
||||||
nextdayurl = 'http://tv.olleh.com/renewal_sub/liveTv/pop_schedule_week.asp?ch_name=&ch_no=%s&nowdate=%s&seldate=%s&tab_no=1' % (ServiceId, nextday, nextday)
|
day = today + datetime.timedelta(days=k)
|
||||||
u1 = urllib.urlopen(todayurl).read()
|
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)
|
||||||
data1 = unicode(u1, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
u = urllib.urlopen(url).read()
|
||||||
soup1 = BeautifulSoup(data1,'lxml', from_encoding='utf-8')
|
data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
||||||
|
soup = BeautifulSoup(data,'lxml', from_encoding='utf-8')
|
||||||
u2 = urllib.urlopen(nextdayurl).read()
|
html = soup.find('table', {'id':'pop_day'}).tbody.findAll('tr')
|
||||||
data2 = unicode(u2, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
for row in html:
|
||||||
soup2 = BeautifulSoup(data2,'lxml', from_encoding='utf-8')
|
for cell in [row.findAll('td')]:
|
||||||
|
epginfo.append([cell[1].text, str(day) + ' ' + cell[0].text, cell[4].text, cell[2].text])
|
||||||
html = soup1.find('table', {'id':'pop_day'}).tbody.findAll('tr')
|
for epg1, epg2 in zip(epginfo, epginfo[1:]):
|
||||||
html1 = soup2.find('table', {'id':'pop_day'}).tbody.findAll('tr')
|
programName = epg1[0].decode('string_escape')
|
||||||
if not (html1 is None) and len(html1) > 0:
|
startTime = datetime.datetime.strptime(epg1[1], '%Y-%m-%d %H:%M')
|
||||||
html2 = soup2.find('table', {'id':'pop_day'}).tbody.findAll('tr')[0]
|
startTime = startTime.strftime('%Y%m%d%H%M%S')
|
||||||
else :
|
endTime = datetime.datetime.strptime(epg2[1], '%Y-%m-%d %H:%M')
|
||||||
html2 = """
|
endTime = endTime.strftime('%Y%m%d%H%M%S')
|
||||||
<tr>
|
category = escape(epg1[2])
|
||||||
<td class="alignC">00:00</td>
|
rating = escape(epg1[3])
|
||||||
<td></td>
|
|
||||||
<td class="alignC"></td>
|
|
||||||
<td class="alignC">
|
|
||||||
<span class="tvGuideLv tvGuideSd"></span>
|
|
||||||
</td>
|
|
||||||
<td class="alignC"></td>
|
|
||||||
</tr>
|
|
||||||
"""
|
|
||||||
html2 = BeautifulSoup(html2,'lxml', from_encoding='utf-8').findAll('tr')[0]
|
|
||||||
html.append(html2)
|
|
||||||
|
|
||||||
for row1, row2 in zip(html, html[1:]):
|
|
||||||
for cell1, cell2 in zip([row1.findAll('td')], [row2.findAll('td')]):
|
|
||||||
programName = escape(cell1[1].text).encode('utf-8')
|
|
||||||
startTime = cell1[0].text
|
|
||||||
startTime = str(today) + ' ' + startTime
|
|
||||||
startTime = datetime.datetime.strptime(startTime, "%Y-%m-%d %H:%M")
|
|
||||||
startTime = startTime.strftime("%Y%m%d%H%M%S")
|
|
||||||
endTime = cell2[0].text
|
|
||||||
if endTime == '00:00' :
|
|
||||||
endTime = str(nextday) + ' ' + endTime
|
|
||||||
else :
|
|
||||||
endTime = str(today) + ' ' + endTime
|
|
||||||
endTime = datetime.datetime.strptime(endTime, "%Y-%m-%d %H:%M")
|
|
||||||
endTime = endTime.strftime("%Y%m%d%H%M%S")
|
|
||||||
category = escape(cell1[4].text).encode('utf-8')
|
|
||||||
rating = escape(cell1[2].text).encode('utf-8')
|
|
||||||
if rating == 'all세 이상':
|
if rating == 'all세 이상':
|
||||||
rating = '모든 연령 시청가'
|
rating = '전체 연령 시청가'
|
||||||
else:
|
else:
|
||||||
rating = rating + ' 시청가'
|
rating = rating + ' 시청가'
|
||||||
desc = programName + '\n장르 : ' + category + '\n등급 : ' + rating
|
desc = programName + '\n장르 : ' + category + '\n등급 : ' + rating
|
||||||
@ -208,37 +166,65 @@ def GetEPGFromKT(ChannelInfo):
|
|||||||
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, '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):
|
||||||
pass
|
channelId = ChannelInfo[0]
|
||||||
|
ServiceId = ChannelInfo[3]
|
||||||
|
epginfo = []
|
||||||
|
for k in range(period):
|
||||||
|
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'))
|
||||||
|
u = urllib.urlopen(url).read()
|
||||||
|
data = unicode(u, 'euc-kr', 'ignore').encode('utf-8', 'ignore')
|
||||||
|
soup = BeautifulSoup(data,'lxml', from_encoding='utf-8')
|
||||||
|
html = soup.find('table', {'class':'datatable06'}).tbody.findAll('tr')
|
||||||
|
for row in html:
|
||||||
|
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()])
|
||||||
|
for epg1, epg2 in zip(epginfo, epginfo[1:]):
|
||||||
|
programName = epg1[0].decode('string_escape')
|
||||||
|
startTime = datetime.datetime.strptime(epg1[1], "%Y-%m-%d %H:%M")
|
||||||
|
startTime = startTime.strftime("%Y%m%d%H%M%S")
|
||||||
|
endTime = datetime.datetime.strptime(epg2[1], "%Y-%m-%d %H:%M")
|
||||||
|
endTime = endTime.strftime("%Y%m%d%H%M%S")
|
||||||
|
category = escape(epg1[2])
|
||||||
|
rating = escape(epg1[3])
|
||||||
|
desc = programName + '\n장르 : ' + category + '\n등급 : ' + rating
|
||||||
|
actors = '';
|
||||||
|
producer = '';
|
||||||
|
episode = None
|
||||||
|
checkEpisode = re.search('(?<=\()[\d]+', programName)
|
||||||
|
if not (checkEpisode is None):
|
||||||
|
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)
|
||||||
|
|
||||||
# Get EPG data from SK
|
# Get EPG data from SK
|
||||||
def GetEPGFromSK(ChannelInfo):
|
def GetEPGFromSK(ChannelInfo):
|
||||||
channelId = ChannelInfo[0]
|
channelId = ChannelInfo[0]
|
||||||
ServiceId = ChannelInfo[3]
|
ServiceId = ChannelInfo[3]
|
||||||
url = 'http://m.btvplus.co.kr/Common/Inc/IFGetData.asp?variable=IF_LIVECHART_DETAIL&pcode=|^|start_time=%s00|^|end_time=%s24|^|svc_id=%s'%(today.strftime("%Y%m%d"), today.strftime("%Y%m%d"), ServiceId)
|
lastday = today + datetime.timedelta(days=period-1)
|
||||||
|
url = 'http://m.btvplus.co.kr/Common/Inc/IFGetData.asp?variable=IF_LIVECHART_DETAIL&pcode=|^|start_time=%s00|^|end_time=%s24|^|svc_id=%s' % (today.strftime("%Y%m%d"), lastday.strftime("%Y%m%d"), ServiceId)
|
||||||
u = urllib.urlopen(url).read()
|
u = urllib.urlopen(url).read()
|
||||||
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 = program['programName']
|
||||||
if programName:
|
if programName:
|
||||||
programName = escape(programName)
|
|
||||||
programName = programName.replace('(재)', ' (재방송)')
|
programName = programName.replace('(재)', ' (재방송)')
|
||||||
actors = program['actorName']
|
actors = program['actorName']
|
||||||
if actors: actors = escape(actors)
|
if actors: actors = escape(actors)
|
||||||
producer = program['directorName']
|
producer = program['directorName']
|
||||||
if producer: producer = escape(producer)
|
if producer: producer = escape(producer)
|
||||||
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']
|
category = program['mainGenreName'] + '-' + program['subGenreName']
|
||||||
if category: category = escape(category)
|
if category: category = escape(category)
|
||||||
rating = program['ratingCd']
|
rating = program['ratingCd']
|
||||||
if rating == '0':
|
if rating == '0':
|
||||||
rating = '모든 연령 시청가'
|
rating = '전체 시청가'
|
||||||
else :
|
else :
|
||||||
rating = '%s세 이상 시청가' % (rating)
|
rating = '%s세 이상 시청가' % (rating)
|
||||||
episode = None
|
episode = None
|
||||||
@ -251,7 +237,7 @@ def GetEPGFromSK(ChannelInfo):
|
|||||||
if actors : desc = desc + '\n출연 : ' + actors
|
if actors : desc = desc + '\n출연 : ' + actors
|
||||||
if producer : desc = desc + '\n제작 : ' + producer
|
if producer : desc = desc + '\n제작 : ' + producer
|
||||||
desc = desc + '\n등급 : ' + rating
|
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}
|
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)
|
||||||
|
|
||||||
@ -259,86 +245,111 @@ def GetEPGFromSK(ChannelInfo):
|
|||||||
def GetEPGFromSKY(ChannelInfo):
|
def GetEPGFromSKY(ChannelInfo):
|
||||||
channelId = ChannelInfo[0]
|
channelId = ChannelInfo[0]
|
||||||
ServiceId = ChannelInfo[3]
|
ServiceId = ChannelInfo[3]
|
||||||
url = 'http://www.skylife.co.kr/channel/epg/channelScheduleList.do?area=in&inFd_channel_id=%s&inairdate=%s&indate_type=now' % (ServiceId, today)
|
for k in range(period):
|
||||||
u = urllib.urlopen(url).read()
|
day = today + datetime.timedelta(days=k)
|
||||||
data = json.loads(u)
|
url = 'http://www.skylife.co.kr/channel/epg/channelScheduleList.do?area=in&inFd_channel_id=%s&inairdate=%s&indate_type=now' % (ServiceId, day)
|
||||||
programs = data['scheduleListIn']
|
u = urllib.urlopen(url).read()
|
||||||
|
data = json.loads(u, encoding='utf-8')
|
||||||
for program in programs:
|
programs = data['scheduleListIn']
|
||||||
programName = program['program_name']
|
for program in {v['starttime']:v for v in programs}.values():
|
||||||
if programName: programName = escape(programName)
|
programName = unescape(program['program_name']).replace('lt;','<').replace('gt;','>').replace('amp;','&')
|
||||||
rebroadcast = program['rebroad']
|
rebroadcast = program['rebroad']
|
||||||
if rebroadcast == 'Y': programName = programName + ' (재방송)'
|
if rebroadcast == 'Y': programName = programName + ' (재방송)'
|
||||||
actors = program['cast']
|
actors = program['cast']
|
||||||
if actors: actors = escape(actors)
|
if actors: actors = escape(actors)
|
||||||
producer = program['dirt']
|
producer = program['dirt']
|
||||||
if producer: producer = escape(producer)
|
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'] + '/' + program['program_category2']
|
||||||
if category: category = escape(category)
|
if category: category = escape(category)
|
||||||
rating = escape(program['grade'])
|
rating = escape(program['grade'])
|
||||||
if rating == '0':
|
if rating == '0':
|
||||||
rating = '모든 연령 시청가'
|
rating = '전체 시청가'
|
||||||
else :
|
else :
|
||||||
rating = '%s세 이상 시청가' % (rating)
|
rating = '%s세 이상 시청가' % (rating)
|
||||||
episode = program['episode_id']
|
episode = program['episode_id']
|
||||||
if episode : episode = int(episode)
|
if episode : episode = int(episode)
|
||||||
description = program['description']
|
description = program['description']
|
||||||
if description: description = escape(description)
|
if description: description = unescape(description).replace('lt;','<').replace('gt;','>').replace('amp;','&')
|
||||||
summary = program['summary']
|
summary = program['summary']
|
||||||
if summary: summary = escape(summary)
|
if summary: summary = unescape(summary).replace('lt;','<').replace('gt;','>').replace('amp;','&')
|
||||||
desc = programName
|
desc = programName
|
||||||
if episode : desc = desc + '\n회차 : ' + str(episode) + '회'
|
if episode : desc = desc + '\n회차 : ' + str(episode) + '회'
|
||||||
desc = desc + '\n장르 : ' + category
|
desc = desc + '\n장르 : ' + category
|
||||||
if actors : desc = desc + '\n출연 : ' + actors
|
if actors : desc = desc + '\n출연 : ' + actors
|
||||||
if producer : desc = desc + '\n제작 : ' + producer
|
if producer : desc = desc + '\n제작 : ' + producer
|
||||||
desc = desc + '\n등급 : ' + rating
|
desc = desc + '\n등급 : ' + rating
|
||||||
if description: desc = desc + '\n' + description
|
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, 'desc':desc, 'actors':actors, 'producer':producer, 'category':category, 'episode':episode, 'rating':rating}
|
writeProgram(programdata)
|
||||||
writeProgram(programdata)
|
|
||||||
|
|
||||||
# Write Program
|
# Write Program
|
||||||
def writeProgram(programdata):
|
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 = programdata['programName']
|
||||||
desc = programdata['desc']
|
desc = programdata['desc']
|
||||||
actors = programdata['actors']
|
actors = programdata['actors']
|
||||||
producer = programdata['producer']
|
producer = programdata['producer']
|
||||||
category = programdata['category']
|
category = programdata['category']
|
||||||
episode = programdata['episode']
|
episode = programdata['episode']
|
||||||
rating = programdata['rating']
|
rating = programdata['rating']
|
||||||
print '\t<programme start="%s +0900" stop="%s +0900" channel="%s">' % (startTime, endTime,channelId)
|
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'}
|
||||||
print '\t\t<title lang="kr">%s</title>' % (programName)
|
contentType = ''
|
||||||
print '\t\t<desc lang="kr">%s</desc>' % (desc)
|
for key, value in contentTypeDict.iteritems():
|
||||||
if actors or producer:
|
if category.startswith(key):
|
||||||
print '\t\t<credits>'
|
contentType = value
|
||||||
if actors: print '\t\t\t<actor>%s</actor>' % (actors)
|
print '\t<programme start="%s +0900" stop="%s +0900" channel="%s">' % (startTime, endTime,channelId)
|
||||||
if producer: print '\t\t\t<producer>%s</producer>' % (producer)
|
print '\t\t<title lang="kr"><![CDATA[%s]]></title>' % (programName)
|
||||||
print '\t\t</credits>'
|
print '\t\t<desc lang="kr"><![CDATA[%s]]></desc>' % (desc)
|
||||||
print '\t\t<category lang="kr">%s</category>' %(category)
|
if actors or producer:
|
||||||
if episode:
|
print '\t\t<credits>'
|
||||||
print '\t\t<episode-num system="onscreen">%s</episode-num>' % (episode)
|
if actors: print '\t\t\t<actor>%s</actor>' % (actors)
|
||||||
print '\t\t<rating system="KMRB">\n\t\t\t<value>%s</value>\n\t\t</rating>' % (rating)
|
if producer: print '\t\t\t<producer>%s</producer>' % (producer)
|
||||||
print '\t</programme>'
|
print '\t\t</credits>'
|
||||||
|
print '\t\t<category lang="kr">%s</category>' % (category)
|
||||||
|
print '\t\t<category lang="en">%s</category>' % (contentType)
|
||||||
|
if episode:
|
||||||
|
print '\t\t<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)
|
||||||
|
print '\t</programme>'
|
||||||
|
|
||||||
# Write XML
|
# Write XML
|
||||||
def writeXML(data):
|
def writeXML(data):
|
||||||
print data
|
print data
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description=u'EPG 정보를 출력하는 방법을 결정')
|
parser = argparse.ArgumentParser(description='EPG 정보를 출력하는 방법을 선택한다')
|
||||||
cmds = parser.add_mutually_exclusive_group(required=True)
|
argu1 = parser.add_argument_group(description='IPTV 선택')
|
||||||
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
|
argu1.add_argument('-i', dest = 'iptv', choices = ['KT', 'LG', 'SK'], help = '사용하는 IPTV : KT, LG, SK', required = True)
|
||||||
cmds.add_argument('-d', '--display', action='store_true', help='EPG 정보 화면출력')
|
argu2 = parser.add_mutually_exclusive_group(required = True)
|
||||||
cmds.add_argument('-o', '--outfile', metavar=default_xml_filename, nargs='?', const=default_xml_filename, help='EPG 정보 저장')
|
argu2.add_argument('-v', '--version', action = 'version', version = '%(prog)s version : ' + __version__)
|
||||||
cmds.add_argument('-s', '--socket', metavar=default_xml_socket, nargs='?', const=default_xml_socket, help='xmltv.sock(External: XMLTV)로 EPG정보 전송')
|
argu2.add_argument('-d', '--display', action = 'store_true', help = 'EPG 정보 화면출력')
|
||||||
|
argu2.add_argument('-o', '--outfile', metavar = default_xml_filename, nargs = '?', const = default_xml_filename, help = 'EPG 정보 저장')
|
||||||
|
argu2.add_argument('-s', '--socket', metavar = default_xml_socket, nargs = '?', const = default_xml_socket, help = 'xmltv.sock(External: XMLTV)로 EPG정보 전송')
|
||||||
|
argu3 = parser.add_argument_group('추가옵션')
|
||||||
|
argu3.add_argument('-l', '--limit', dest='limit', type = int, metavar = "1-7", choices = range(1,8), help = 'EPG 정보를 가져올 기간, 기본값: '+ str(default_fetch_limit), default = default_fetch_limit)
|
||||||
|
argu3.add_argument('--icon', dest='icon', metavar = "http://www.example.com/icon", help = '채널 아이콘 URL, 기본값: '+ default_icon_url, default = default_icon_url)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.iptv:
|
||||||
|
if any(args.iptv in s for s in ['KT', 'LG', 'SK']):
|
||||||
|
MyISP = args.iptv
|
||||||
|
else:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if args.limit:
|
||||||
|
period = args.limit
|
||||||
|
else:
|
||||||
|
period = default_fetch_limit;
|
||||||
|
|
||||||
|
if args.icon:
|
||||||
|
IconUrl = args.icon
|
||||||
|
else :
|
||||||
|
IconUrl = default_icon_url
|
||||||
if args.outfile:
|
if args.outfile:
|
||||||
sys.stdout = codecs.open(args.outfile, 'w+', encoding='utf-8')
|
sys.stdout = codecs.open(args.outfile, 'w+', encoding='utf-8')
|
||||||
elif args.socket:
|
elif args.socket:
|
||||||
@ -347,11 +358,8 @@ elif args.socket:
|
|||||||
sockfile = sock.makefile('w+')
|
sockfile = sock.makefile('w+')
|
||||||
sys.stdout = sockfile
|
sys.stdout = sockfile
|
||||||
|
|
||||||
MyChannelNumber = getMyChannel()
|
|
||||||
|
|
||||||
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">')
|
||||||
writeXML('<tv source-info-url="localhost" source-info-name="xmltv" generator-info-name="xmltv">')
|
writeXML('<tv generator-info-name="xmltv">')
|
||||||
getEpg(MyChannelNumber)
|
getEpg()
|
||||||
writeXML('</tv>')
|
writeXML('</tv>')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user