From fab83e733a1ea0938c79534dc314206e932fbe42 Mon Sep 17 00:00:00 2001 From: Yuuki Date: Thu, 2 Jan 2025 20:52:38 +0900 Subject: [PATCH] Updated `add_programme` to support attributes and show icons if they exist. --- constants.py | 21 ++++++++++++++------- run.py | 22 ++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/constants.py b/constants.py index 8deddc1..02576b4 100644 --- a/constants.py +++ b/constants.py @@ -29,12 +29,19 @@ class XMLTV: 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, audio, subtitles): - self.programmes.append('' - '{}' - '{}' - '{}' - '\n'.format(start, stop, channel, title, desc, category)) + def add_programme(self, channel, title, desc, start, stop, category, attr, icon): + programme = ''.format(start, stop, channel) + programme += '{}'.format(title) + programme += '{}'.format(desc) + programme += '{}'.format(category) + if icon: programme += ''.format(icon) + if 'stereo' in attr: programme += '' + if 'mono' in attr: programme += '' + if 'hd' in attr: programme += '' + if 'cp1' in attr: programme += '' + programme += '\n' + + self.programmes.append(programme) def create(self): with open('data/epg.xml', mode='w', encoding='UTF-8') as epg: @@ -42,7 +49,7 @@ class XMLTV: epg.write('\n') epg.write('\n') for channel in self.channels: - epg.write(channel) + epg.write(f'{channel}\n') for prg in self.programmes: epg.write(prg) epg.write('') diff --git a/run.py b/run.py index a0ebf71..904ebde 100644 --- a/run.py +++ b/run.py @@ -56,7 +56,6 @@ else: guide.channels = open('data/channels.xml', mode='r', encoding='UTF-8').read().splitlines() for x in range(0, 7): - # Data for channel EPG req = Request('https://tvguide.myjcom.jp/api/getEpgInfo/?channels=2_40960_32112_{}%2C2_2056_32721_{}%2C2_43056_32086_{}%2C2_2064_32722_{}%2C2_42032_32102_{}%2C2_2072_32723_{}%2C2_41008_32118_{}%2C2_2080_32724_{}%2C2_2088_32725_{}%2C3_101_4_{}%2C3_103_4_{}%2C3_141_4_{}%2C3_151_4_{}%2C3_161_4_{}%2C3_171_4_{}%2C3_181_4_{}%2C3_191_4_{}%2C3_192_4_{}%2C3_193_4_{}%2C3_101_11_{}%2C3_141_11_{}%2C3_151_11_{}%2C3_161_11_{}%2C3_171_11_{}%2C3_181_11_{}%2C3_191_11_{}%2C120_200_4_{}%2C120_201_4_{}%2C120_202_4_{}%2C120_032_65406_{}%2C120_140_65406_{}%2C120_172_65406_{}%2C120_192_65406_{}%2C120_129_65406_{}%2C120_203_65406_{}%2C120_103_65406_{}%2C120_179_65406_{}%2C120_033_65406_{}%2C120_034_65406_{}%2C120_037_65406_{}%2C120_152_65406_{}%2C120_227_65534_{}%2C120_180_65406_{}%2C120_185_65406_{}%2C120_249_65406_{}%2C120_102_65406_{}%2C120_257_65534_{}%2C120_038_65406_{}%2C120_156_65406_{}%2C120_150_65406_{}%2C120_175_65406_{}%2C120_161_65406_{}%2C120_265_65406_{}%2C120_147_65406_{}%2C120_128_65406_{}%2C120_146_65406_{}%2C120_167_65406_{}%2C120_166_65406_{}%2C120_168_65406_{}%2C120_169_65406_{}%2C120_158_65406_{}%2C120_132_65534_{}%2C120_106_65406_{}%2C120_411_65527_{}%2C120_412_65527_{}%2C120_413_65527_{}%2C120_414_65527_{}%2C120_415_65527_{}%2C120_416_65527_{}%2C120_417_65527_{}%2C120_419_65527_{}%2C120_039_65406_{}%2C120_122_65534_{}%2C120_155_65406_{}%2C120_133_65534_{}%2C120_151_65406_{}%2C120_125_65534_{}%2C120_159_65406_{}%2C120_173_65406_{}%2C120_127_65406_{}%2C120_195_65406_{}%2C120_131_65534_{}%2C120_126_65406_{}%2C120_135_65534_{}%2C120_144_65406_{}%2C120_141_65406_{}%2C120_176_65406_{}%2C120_123_65534_{}%2C120_157_65406_{}%2C120_148_65406_{}%2C120_153_65406_{}%2C120_149_65406_{}%2C120_163_65406_{}%2C120_171_65406_{}%2C120_183_65406_{}%2C120_182_65406_{}%2C120_130_65406_{}%2C120_134_65534_{}%2C120_142_65406_{}%2C120_121_65534_{}%2C120_186_65406_{}%2C120_196_65406_{}%2C120_145_65406_{}%2C120_160_65406_{}%2C120_137_65406_{}%2C120_138_65406_{}%2C120_139_65406_{}%2C120_136_65406_{}%2C120_184_65406_{}%2C120_190_65406_{}%2C120_188_65406_{}%2C120_181_65406_{}%2C120_154_65406_{}%2C120_174_65406_{}%2C120_191_65406_{}%2C120_143_65406_{}%2C120_187_65406_{}%2C120_104_65406_{}%2C120_105_65406_{}%2C120_170_65406_{}%2C120_164_65406_{}%2C120_165_65406_{}%2C120_287_65534_{}%2C120_288_65406_{}%2C120_035_65406_{}%2C120_036_65406_{}%2C120_290_65534_{}%2C120_291_65534_{}%2C120_293_65534_{}%2C120_292_65534_{}%2C120_294_65406_{}%2C120_295_65406_{}&rectime=&rec4k=' .format(ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, ymd, @@ -71,15 +70,18 @@ for x in range(0, 7): for chid in data: for epg_data in data[chid]: - guide.add_programme(chid[0:chid.rfind('_')], - fix(epg_data['title']), - fix(epg_data['commentary']), - epg_data['programStart'], - epg_data['programEnd'], - genre(epg_data['sortGenre']), - epg_data['attr'][0], - None) - print('Added EPG info for', epg_data['title']) + channel = chid[0:chid.rfind('_')] + title = epg_data['title'] + comment = epg_data['commentary'] + start = epg_data['programStart'] + end = epg_data['programEnd'] + gen = genre(epg_data['sortGenre']) + attr = epg_data['attr'] + icon = 'https://tvguide.myjcom.jp/{}'.format(epg_data['imgPath']) if int(epg_data['hasImage']) == 1 else None + + guide.add_programme(channel, title, comment, start, end, gen, attr, icon) + + print('Added EPG info for', title) date += timedelta(days=1)