First attempt at adding multiple cities. Worked in my test.
This commit is contained in:
parent
8b29e68200
commit
c8782672b1
2 changed files with 28 additions and 9 deletions
10
constants.py
10
constants.py
|
@ -35,10 +35,12 @@ class XMLTV:
|
|||
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))
|
||||
if ('<channel id="{}"><display-name>{}</display-name><icon src="{}" /></channel>\n'
|
||||
.format(channel, display_name, icon) not in self.channels):
|
||||
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:
|
||||
|
|
27
run.py
27
run.py
|
@ -42,14 +42,30 @@ def request_url() -> str:
|
|||
return f'{request}&rectime=&rec4k='
|
||||
|
||||
|
||||
# TODO: Find an easier way to do this.
|
||||
if not file_exists('data/channels.xml'):
|
||||
c_area = CITY.OSAKA2.value
|
||||
c_areas = [CITY.OSAKA2.value, CITY.KUMAMOTO.value, CITY.HOKKAIDO.value]
|
||||
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/131.0.0.0 Safari/537.36') # This is required, otherwise we get a 403: Forbidden error.
|
||||
channel_data = urlopen(req_channels).read()
|
||||
for area in c_areas: # GR
|
||||
req = Request('https://tvguide.myjcom.jp/api/mypage/getEpgChannelList/?channelType=2&area={}&channelGenre=&course=&chart=&is_adult={}'.format(area, c_adult))
|
||||
req.add_header('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36')
|
||||
data = urlopen(req).read()
|
||||
data = json.loads(data)
|
||||
|
||||
for ch in data['header']:
|
||||
chid = '{}_{}_{}_{}'.format(ch['channel_type'], ch['channel_id'], ch['network_id'], ymd)
|
||||
j1 = '200_00010_0_{}'.format(ymd)
|
||||
j2 = '200_00055_0_{}'.format(ymd)
|
||||
|
||||
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'])
|
||||
|
||||
for c_type in [3, 5, 120]: # BS / BS4K / CS
|
||||
req = Request('https://tvguide.myjcom.jp/api/mypage/getEpgChannelList/?channelType={}&area=1&channelGenre=&course=&chart=&is_adult={}'.format(c_type, c_adult))
|
||||
req.add_header('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36') # This is required, otherwise we get a 403: Forbidden error.
|
||||
channel_data = urlopen(req).read()
|
||||
channel_data = json.loads(channel_data)
|
||||
|
||||
for ch in channel_data['header']:
|
||||
|
@ -65,6 +81,7 @@ if not file_exists('data/channels.xml'):
|
|||
else:
|
||||
guide.channels = open('data/channels.xml', mode='r', encoding='UTF-8').read().splitlines()
|
||||
|
||||
breakpoint()
|
||||
|
||||
for x in range(0, 7):
|
||||
req = Request(request_url())
|
||||
|
|
Loading…
Add table
Reference in a new issue