Pass genre, program title and episode number to IPTV Manager. (#31)

This commit is contained in:
Michaël Arnauts 2020-06-09 10:51:59 +02:00 committed by GitHub
parent 3902a93aa1
commit 6e30322f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 3 deletions

View File

@ -78,7 +78,11 @@ class IPTVManager:
start=program.start.isoformat(), start=program.start.isoformat(),
stop=(program.start + timedelta(seconds=program.duration)).isoformat(), stop=(program.start + timedelta(seconds=program.duration)).isoformat(),
title=program.program_title, title=program.program_title,
subtitle=program.episode_title,
description=program.description, description=program.description,
episode='S%dE%d' % (program.season, program.number) if program.season and program.number else None,
genre=program.genre,
genre_id=program.genre_id,
image=program.cover, image=program.cover,
stream=kodiutils.url_for('play_from_page', stream=kodiutils.url_for('play_from_page',
channel=key, channel=key,

View File

@ -13,13 +13,32 @@ import requests
_LOGGER = logging.getLogger('epg-api') _LOGGER = logging.getLogger('epg-api')
GENRE_MAPPING = {
'Detective': 0x11,
'Dramaserie': 0x15,
'Fantasy': 0x13,
'Human Interest': 0x00,
'Informatief': 0x20,
'Komedie': 0x14,
'Komische serie': 0x14,
'Kookprogramma': '',
'Misdaadserie': 0x15,
'Politieserie': 0x17,
'Reality': 0x31,
'Science Fiction': 0x13,
'Show': 0x30,
'Thriller': 0x11,
'Voetbal': 0x43,
}
class EpgProgram: class EpgProgram:
""" Defines a Program in the EPG. """ """ Defines a Program in the EPG. """
# pylint: disable=invalid-name # pylint: disable=invalid-name
def __init__(self, channel, program_title, episode_title, episode_title_original, number, season, genre, start, won_id, won_program_id, program_description, def __init__(self, channel, program_title, episode_title, episode_title_original, number, season, genre, start,
description, duration, program_url, video_url, cover, airing): won_id, won_program_id, program_description, description, duration, program_url, video_url, cover,
airing):
self.channel = channel self.channel = channel
self.program_title = program_title self.program_title = program_title
self.episode_title = episode_title self.episode_title = episode_title
@ -38,6 +57,11 @@ class EpgProgram:
self.cover = cover self.cover = cover
self.airing = airing self.airing = airing
if GENRE_MAPPING.get(self.genre):
self.genre_id = GENRE_MAPPING.get(self.genre)
else:
self.genre_id = None
def __repr__(self): def __repr__(self):
return "%r" % self.__dict__ return "%r" % self.__dict__
@ -51,6 +75,8 @@ class EpgApi:
'zes': 'https://www.zestv.be/api/epg/{date}', 'zes': 'https://www.zestv.be/api/epg/{date}',
} }
EPG_NO_BROADCAST = 'Geen uitzending'
def __init__(self): def __init__(self):
""" Initialise object """ """ Initialise object """
self._session = requests.session() self._session = requests.session()
@ -79,7 +105,7 @@ class EpgApi:
data = json.loads(response) data = json.loads(response)
# Parse the results # Parse the results
return [self._parse_program(channel, x) for x in data] return [self._parse_program(channel, x) for x in data if x.get('program_title') != self.EPG_NO_BROADCAST]
@staticmethod @staticmethod
def _parse_program(channel, data): def _parse_program(channel, data):

View File

@ -53,6 +53,18 @@ class TestEpg(unittest.TestCase):
episode = api.get_episode(epg_program.channel, epg_program.video_url) episode = api.get_episode(epg_program.channel, epg_program.video_url)
self.assertIsInstance(episode, Episode) self.assertIsInstance(episode, Episode)
# def test_map_epg_genre(self):
# genres = []
# for channel in ['vier', 'vijf', 'zes']:
# for day in ['yesterday', 'today', 'tomorrow']:
# programs = self._epg.get_epg(channel, day)
#
# for program in programs:
# if program.genre not in genres:
# genres.append(program.genre)
#
# print(genres)
#
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()