Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TV-Guide information to live stream plot #234

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions resources/lib/vrtplayer/tvguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def show_tvguide(self, params):

def show_date_menu(self):
now = datetime.now(dateutil.tz.tzlocal())
# Daily EPG information shows information from 6AM until 6AM
if now.hour < 6:
now += timedelta(days=-1)
date_items = []
for i in range(7, -31, -1):
day = now + timedelta(days=i)
Expand Down Expand Up @@ -171,6 +174,45 @@ def show_episodes(self, date, channel):
))
return episode_items

def episode_description(self, episode):
return '{start} - {end}\n{title}'.format(**episode)

def live_description(self, channel):
now = datetime.now(dateutil.tz.tzlocal())
# Daily EPG information shows information from 6AM until 6AM
if now.hour < 6:
now += timedelta(days=-1)
api_url = now.strftime(self.VRT_TVGUIDE)
self._kodi.log_notice('URL get: ' + api_url, 'Verbose')
schedule = json.loads(urlopen(api_url).read())
name = channel
try:
channel = next(c for c in CHANNELS if c.get('name') == name)
episodes = iter(schedule[channel.get('id')])
except StopIteration:
return ''

description = ''
prev_episode = None
while True:
try:
episode = next(episodes)
except StopIteration:
break
start_date = dateutil.parser.parse(episode.get('startTime'))
end_date = dateutil.parser.parse(episode.get('endTime'))
if start_date < now <= end_date: # Now playing
if prev_episode:
description += '[COLOR gray]%s[/COLOR]\n' % self.episode_description(prev_episode)
description += '[COLOR yellow][B]%s[/B][/COLOR]\n' % self.episode_description(episode)
break
prev_episode = episode
try:
description += '%s\n' % self.episode_description(next(episodes))
except StopIteration:
pass
return description

def parse(self, date, now):
if date == 'today':
return now
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/vrtplayer/vrtplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def show_livestream_items(self):
self.show_channels(action=actions.PLAY, channels=['een', 'canvas', 'sporza', 'ketnet-jr', 'ketnet', 'stubru', 'mnm'])

def show_channels(self, action=actions.PLAY, channels=None):
from resources.lib.vrtplayer import CHANNELS
from resources.lib.vrtplayer import CHANNELS, tvguide
_tvguide = tvguide.TVGuide(self._kodi)

fanart_path = 'resource://resource.images.studios.white/%(studio)s.png'
icon_path = 'resource://resource.images.studios.white/%(studio)s.png'
Expand All @@ -139,8 +140,7 @@ def show_channels(self, action=actions.PLAY, channels=None):
is_playable = True
if channel.get('name') in ['een', 'canvas', 'ketnet']:
fanart = self._apihelper.get_live_screenshot(channel.get('name'))
plot = '%s\n%s' % (self._kodi.localize(30201),
self._kodi.localize(30102) % channel.get('label'))
plot = _tvguide.live_description(channel.get('name')) or self._kodi.localize(30102) % channel.get('label')
else:
plot = self._kodi.localize(30102) % channel.get('label')
if channel.get('live_stream_url'):
Expand Down
8 changes: 8 additions & 0 deletions test/tvguidetests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ def test_tvguide_episode_menu(self):
episode_items = self._tvguide.show_episodes(date, channel)
self.assertTrue(episode_items)

def test_livetv_description(self):
description = self._tvguide.live_description('een')
print(description)
description = self._tvguide.live_description('canvas')
print(description)
description = self._tvguide.live_description('ketnet')
print(description)


if __name__ == '__main__':
unittest.main()