64 lines
2.6 KiB
Python
64 lines
2.6 KiB
Python
from enum import Enum
|
|
|
|
class CITY(Enum):
|
|
# TODO: Add all these cities: https://c.myjcom.jp/shared/common/js/region/data/cityMaster.js?_=1735632747105
|
|
# TODO: Change these to cities' names
|
|
KYUSHU1 = 35
|
|
KYUSHU2 = 36
|
|
KYUSHU3 = 54
|
|
MIYAGI1 = 52
|
|
OSAKA1 = 40
|
|
OSAKA2 = 46
|
|
TOKYO1 = 19
|
|
TOKYO2 = 100
|
|
TOKYO3 = 222
|
|
|
|
|
|
class XMLTV:
|
|
def __init__(self):
|
|
self.channels = []
|
|
self.programmes = []
|
|
|
|
def add_channel(self, channel, display_name, icon):
|
|
self.channels.append('<channel id="{}">'
|
|
'<display-name>{}</display-name>'
|
|
'<icon src="{}" />'
|
|
'</channel>\n'.format(channel, display_name, icon))
|
|
|
|
def write_channels(self):
|
|
for c in self.channels:
|
|
open('data/channels.xml', mode='a', encoding='UTF-8').write(c)
|
|
|
|
def add_programme(self, channel, title, desc, start, stop, category, attr, icon):
|
|
# TODO: add `duo` attribute (bilingual)
|
|
programme = '<programme start="{} +0000" stop="{} +0000" channel="{}">'.format(start, stop, channel)
|
|
programme += '<title lang="ja">{}</title>'.format(title)
|
|
programme += '<desc>{}</desc>'.format(desc)
|
|
programme += '<category lang="ja">{}</category>'.format(category)
|
|
if icon: programme += '<icon src="{}" />'.format(icon)
|
|
if '5.1' in attr: programme += '<audio><stereo>surround</stereo></audio>'
|
|
if 'stereo' in attr: programme += '<audio><stereo>stereo</stereo></audio>'
|
|
if 'mono' in attr: programme += '<audio><stereo>mono</stereo></audio>'
|
|
if 'hd' in attr: programme += '<video><present>yes</present><aspect>16:9</aspect><quality>HDTV</quality></video>'
|
|
if '4k' in attr: programme += '<video><present>yes></present><aspect>16:9</aspect><quality>3840x2160</quality></video>'
|
|
if 'cp1' in attr: programme += '<subtitles type="teletext" />'
|
|
programme += '</programme>\n'
|
|
|
|
self.programmes.append(programme)
|
|
|
|
def create(self):
|
|
with open('data/epg.xml', mode='w', encoding='UTF-8') as epg:
|
|
epg.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
|
epg.write('<!DOCTYPE tv SYSTEM "xmltv.dtd">\n')
|
|
epg.write('<tv source-info-name="EPG Grabber">\n')
|
|
for channel in self.channels:
|
|
epg.write(f'{channel}\n')
|
|
for prg in self.programmes:
|
|
epg.write(prg)
|
|
epg.write('</tv>')
|
|
|
|
def _show_channels(self):
|
|
print(self.channels)
|
|
|
|
def _show_programmes(self):
|
|
print(self.programmes)
|