diff --git a/.gitignore b/.gitignore index 4527fc7..ab3e8ce 100644 --- a/.gitignore +++ b/.gitignore @@ -162,4 +162,3 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -data/* diff --git a/README.md b/README.md index 1aa2120..42bcae9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # MyJCOM2XMLTV -This is only tested with `Python 3.13` \ No newline at end of file +Who knows. \ No newline at end of file diff --git a/constants.py b/constants.py deleted file mode 100644 index 8deddc1..0000000 --- a/constants.py +++ /dev/null @@ -1,54 +0,0 @@ -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('' - '{}' - '' - '\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, audio, subtitles): - self.programmes.append('' - '{}' - '{}' - '{}' - '\n'.format(start, stop, channel, title, desc, category)) - - def create(self): - with open('data/epg.xml', mode='w', encoding='UTF-8') as epg: - epg.write('\n') - epg.write('\n') - epg.write('\n') - for channel in self.channels: - epg.write(channel) - for prg in self.programmes: - epg.write(prg) - epg.write('') - - def _show_channels(self): - print(self.channels) - - def _show_programmes(self): - print(self.programmes) diff --git a/run.py b/run.py deleted file mode 100644 index 5c4da38..0000000 --- a/run.py +++ /dev/null @@ -1,87 +0,0 @@ -import json -from datetime import datetime, timedelta -from os.path import exists as file_exists -from urllib.request import Request, urlopen - -from constants import XMLTV, CITY - -date = datetime.today() -guide = XMLTV() - - -def fix(inp: str) -> str: - out = inp.replace('&', '&') - out = out.replace('<', '<') - out = out.replace('>', '>') - - return out - - -def genre(_: str) -> str: - genres = json.load(open('data/genre.json', encoding='utf-8')) - - for gen in genres: - if _ == gen: - return genres[gen] - - return '未知' - - -if not file_exists('data/channels.xml'): - c_area = CITY.OSAKA1 - c_adult = 'true' - - for c_type in [2, 3, 5, 120]: # GR / BS / BS4K / CS - req_channels = Request('https://tvguide.myjcom.jp/api/mypage/getEpgChannelList/?channelType={}&area={}&channelGenre=&course=&chart=&is_adult={}'.format(c_type, c_area, c_adult)) - req_channels.add_header('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36') # This is required, otherwise we get a 403: Forbidden error. - channel_data = urlopen(req_channels).read() - channel_data = json.loads(channel_data) - - for ch in channel_data['header']: - chid = '{}_{}_{}_{}'.format(ch['channel_type'], - ch['channel_id'], - ch['network_id'], - datetime.today().strftime('%Y%m%d')) - j1 = '200_00010_0_{}'.format(datetime.today().strftime('%Y%m%d')) - j2 = '200_00055_0_{}'.format(datetime.today().strftime('%Y%m%d')) - - if j1 not in chid and j2 not in chid: - guide.add_channel(chid[0:chid.rfind('_')], ch['channel_name'], ch['logo_url']) - print('Added channel:', ch['channel_name']) - - guide.write_channels() -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(date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), - date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'), date.strftime('%Y%m%d'))) - req.add_header('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36') - data = urlopen(req).read() - data = json.loads(data) - - 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']) - - date += timedelta(days=1) - -guide.create()