2020-03-19 16:45:31 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
""" Menu code related to channels """
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
from resources.lib import kodiutils
|
|
|
|
from resources.lib.kodiutils import TitleItem
|
2020-05-25 20:41:38 +02:00
|
|
|
from resources.lib.modules.player import Player
|
2020-03-19 16:45:31 +01:00
|
|
|
from resources.lib.viervijfzes import STREAM_DICT
|
|
|
|
from resources.lib.viervijfzes.content import UnavailableException
|
|
|
|
from resources.lib.viervijfzes.epg import EpgApi
|
|
|
|
|
2021-02-17 07:42:24 +01:00
|
|
|
try: # Python 3
|
|
|
|
from urllib.parse import quote
|
|
|
|
except ImportError: # Python 2
|
|
|
|
from urllib import quote
|
|
|
|
|
2020-10-26 10:25:57 +01:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TvGuide:
|
|
|
|
""" Menu code related to the TV Guide """
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
""" Initialise object """
|
|
|
|
self._epg = EpgApi()
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_dates(date_format):
|
|
|
|
""" Return a dict of dates.
|
|
|
|
:rtype: list[dict]
|
|
|
|
"""
|
|
|
|
dates = []
|
|
|
|
today = datetime.today()
|
|
|
|
|
2021-04-23 23:27:55 +02:00
|
|
|
# The API provides 7 days in the past and 8 days in the future
|
|
|
|
for i in range(-7, 8):
|
2020-03-19 16:45:31 +01:00
|
|
|
day = today + timedelta(days=i)
|
|
|
|
|
|
|
|
if i == -1:
|
|
|
|
dates.append({
|
|
|
|
'title': '%s, %s' % (kodiutils.localize(30301), day.strftime(date_format)), # Yesterday
|
|
|
|
'key': 'yesterday',
|
|
|
|
'date': day.strftime('%d.%m.%Y'),
|
|
|
|
'highlight': False,
|
|
|
|
})
|
|
|
|
elif i == 0:
|
|
|
|
dates.append({
|
|
|
|
'title': '%s, %s' % (kodiutils.localize(30302), day.strftime(date_format)), # Today
|
|
|
|
'key': 'today',
|
|
|
|
'date': day.strftime('%d.%m.%Y'),
|
|
|
|
'highlight': True,
|
|
|
|
})
|
|
|
|
elif i == 1:
|
|
|
|
dates.append({
|
|
|
|
'title': '%s, %s' % (kodiutils.localize(30303), day.strftime(date_format)), # Tomorrow
|
|
|
|
'key': 'tomorrow',
|
|
|
|
'date': day.strftime('%d.%m.%Y'),
|
|
|
|
'highlight': False,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
dates.append({
|
|
|
|
'title': day.strftime(date_format),
|
|
|
|
'key': day.strftime('%Y-%m-%d'),
|
|
|
|
'date': day.strftime('%d.%m.%Y'),
|
|
|
|
'highlight': False,
|
|
|
|
})
|
|
|
|
|
|
|
|
return dates
|
|
|
|
|
2020-04-20 08:59:10 +02:00
|
|
|
def show_channel(self, channel):
|
2020-03-19 16:45:31 +01:00
|
|
|
""" Shows the dates in the tv guide
|
|
|
|
:type channel: str
|
|
|
|
"""
|
|
|
|
listing = []
|
|
|
|
for day in self.get_dates('%A %d %B %Y'):
|
|
|
|
if day.get('highlight'):
|
|
|
|
title = '[B]{title}[/B]'.format(title=day.get('title'))
|
|
|
|
else:
|
|
|
|
title = day.get('title')
|
|
|
|
|
|
|
|
listing.append(
|
|
|
|
TitleItem(title=title,
|
2020-04-20 08:59:10 +02:00
|
|
|
path=kodiutils.url_for('show_channel_tvguide_detail', channel=channel, date=day.get('key')),
|
2020-03-19 16:45:31 +01:00
|
|
|
art_dict={
|
|
|
|
'icon': 'DefaultYear.png',
|
|
|
|
'thumb': 'DefaultYear.png',
|
|
|
|
},
|
|
|
|
info_dict={
|
|
|
|
'plot': None,
|
|
|
|
'date': day.get('date'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30013, content='files', sort=['date'])
|
|
|
|
|
2020-04-20 08:59:10 +02:00
|
|
|
def show_detail(self, channel=None, date=None):
|
2020-03-19 16:45:31 +01:00
|
|
|
""" Shows the programs of a specific date in the tv guide
|
|
|
|
:type channel: str
|
|
|
|
:type date: str
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
programs = self._epg.get_epg(channel=channel, date=date)
|
|
|
|
except UnavailableException as ex:
|
|
|
|
kodiutils.notification(message=str(ex))
|
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
|
|
|
listing = []
|
|
|
|
for program in programs:
|
|
|
|
if program.program_url:
|
|
|
|
context_menu = [(
|
|
|
|
kodiutils.localize(30102), # Go to Program
|
|
|
|
'Container.Update(%s)' %
|
|
|
|
kodiutils.url_for('show_catalog_program', channel=channel, program=program.program_url)
|
|
|
|
)]
|
|
|
|
else:
|
|
|
|
context_menu = None
|
|
|
|
|
|
|
|
title = '{time} - {title}'.format(
|
|
|
|
time=program.start.strftime('%H:%M'),
|
|
|
|
title=program.program_title
|
|
|
|
)
|
|
|
|
|
|
|
|
if program.airing:
|
|
|
|
title = '[B]{title}[/B]'.format(title=title)
|
|
|
|
|
|
|
|
if program.video_url:
|
|
|
|
path = kodiutils.url_for('play_from_page', channel=channel, page=quote(program.video_url, safe=''))
|
|
|
|
else:
|
2021-04-23 23:27:55 +02:00
|
|
|
path = kodiutils.url_for('play_catalog', uuid='')
|
2020-03-19 16:45:31 +01:00
|
|
|
title = '[COLOR gray]' + title + '[/COLOR]'
|
|
|
|
|
2020-03-24 23:29:16 +01:00
|
|
|
stream_dict = STREAM_DICT.copy()
|
|
|
|
stream_dict.update({
|
|
|
|
'duration': program.duration,
|
|
|
|
})
|
|
|
|
|
|
|
|
info_dict = {
|
|
|
|
'title': title,
|
|
|
|
'plot': program.description,
|
|
|
|
'studio': program.channel,
|
|
|
|
'duration': program.duration,
|
|
|
|
'tvshowtitle': program.program_title,
|
|
|
|
'season': program.season,
|
|
|
|
'episode': program.number,
|
|
|
|
'mediatype': 'episode',
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:45:31 +01:00
|
|
|
listing.append(
|
|
|
|
TitleItem(title=title,
|
|
|
|
path=path,
|
|
|
|
art_dict={
|
2021-03-19 16:45:26 +01:00
|
|
|
'thumb': program.thumb,
|
2020-03-19 16:45:31 +01:00
|
|
|
},
|
2020-03-24 23:29:16 +01:00
|
|
|
info_dict=info_dict,
|
2020-03-20 15:05:49 +01:00
|
|
|
stream_dict=stream_dict,
|
2020-03-19 16:45:31 +01:00
|
|
|
context_menu=context_menu,
|
|
|
|
is_playable=True)
|
|
|
|
)
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30013, content='episodes', sort=['unsorted'])
|
|
|
|
|
|
|
|
def play_epg_datetime(self, channel, timestamp):
|
|
|
|
""" Play a program based on the channel and the timestamp when it was aired
|
|
|
|
:type channel: str
|
|
|
|
:type timestamp: str
|
|
|
|
"""
|
|
|
|
broadcast = self._epg.get_broadcast(channel, timestamp)
|
|
|
|
if not broadcast:
|
2020-05-25 20:41:38 +02:00
|
|
|
kodiutils.ok_dialog(message=kodiutils.localize(30713)) # The requested video was not found in the guide.
|
2020-03-19 16:45:31 +01:00
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
2020-05-25 20:41:38 +02:00
|
|
|
if not broadcast.video_url:
|
|
|
|
kodiutils.ok_dialog(message=kodiutils.localize(30712)) # The video is unavailable and can't be played right now.
|
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
2021-02-01 08:53:13 +01:00
|
|
|
Player().play_from_page(broadcast.video_url)
|