Compare commits
3 commits
5de68e5b4c
...
7f28820a24
Author | SHA1 | Date | |
---|---|---|---|
7f28820a24 | |||
8ffe1a7951 | |||
879fa34493 |
4 changed files with 143 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -162,3 +162,4 @@ cython_debug/
|
|||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
data/*
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# MyJCOM2XMLTV
|
||||
|
||||
Who knows.
|
||||
This is only tested with `Python 3.13`
|
54
constants.py
Normal file
54
constants.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
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, audio, subtitles):
|
||||
self.programmes.append('<programme start="{} +0000" stop="{} +0000" channel="{}">'
|
||||
'<title lang="ja">{}</title>'
|
||||
'<desc lang="ja">{}</desc>'
|
||||
'<category lang="ja">{}</category>'
|
||||
'</programme>\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('<?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(channel)
|
||||
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)
|
87
run.py
Normal file
87
run.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
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()
|
Loading…
Add table
Reference in a new issue