2020-03-19 16:45:31 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
""" Channels module """
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from resources.lib import kodiutils
|
|
|
|
from resources.lib.kodiutils import TitleItem
|
|
|
|
from resources.lib.viervijfzes import CHANNELS, STREAM_DICT
|
2020-04-20 08:59:10 +02:00
|
|
|
from resources.lib.viervijfzes.auth import AuthApi
|
2021-02-01 08:53:13 +01:00
|
|
|
from resources.lib.viervijfzes.content import ContentApi
|
2020-03-19 16:45:31 +01:00
|
|
|
|
2020-10-26 10:25:57 +01:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Channels:
|
|
|
|
""" Menu code related to channels """
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
""" Initialise object """
|
2020-04-20 08:59:10 +02:00
|
|
|
auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path())
|
|
|
|
self._api = ContentApi(auth, cache_path=kodiutils.get_cache_path())
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def show_channels():
|
|
|
|
""" Shows TV channels """
|
|
|
|
listing = []
|
|
|
|
for i, key in enumerate(CHANNELS): # pylint: disable=unused-variable
|
|
|
|
channel = CHANNELS[key]
|
|
|
|
|
|
|
|
# Lookup the high resolution logo based on the channel name
|
|
|
|
icon = '{path}/resources/logos/{logo}'.format(path=kodiutils.addon_path(), logo=channel.get('logo'))
|
|
|
|
fanart = '{path}/resources/logos/{logo}'.format(path=kodiutils.addon_path(), logo=channel.get('background'))
|
|
|
|
|
|
|
|
context_menu = [
|
|
|
|
(
|
|
|
|
kodiutils.localize(30053, channel=channel.get('name')), # TV Guide for {channel}
|
|
|
|
'Container.Update(%s)' %
|
2020-04-20 08:59:10 +02:00
|
|
|
kodiutils.url_for('show_channel_tvguide', channel=channel.get('epg'))
|
2020-03-19 16:45:31 +01:00
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
listing.append(
|
2020-03-20 13:53:21 +01:00
|
|
|
TitleItem(
|
|
|
|
title=channel.get('name'),
|
|
|
|
path=kodiutils.url_for('show_channel_menu', channel=key),
|
|
|
|
art_dict={
|
|
|
|
'icon': icon,
|
|
|
|
'thumb': icon,
|
|
|
|
'fanart': fanart,
|
|
|
|
},
|
|
|
|
info_dict={
|
|
|
|
'plot': None,
|
|
|
|
'playcount': 0,
|
|
|
|
'mediatype': 'video',
|
|
|
|
},
|
|
|
|
stream_dict=STREAM_DICT,
|
|
|
|
context_menu=context_menu
|
|
|
|
),
|
2020-03-19 16:45:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30007)
|
|
|
|
|
|
|
|
@staticmethod
|
2020-04-20 08:59:10 +02:00
|
|
|
def show_channel_menu(channel):
|
2020-03-19 16:45:31 +01:00
|
|
|
""" Shows a TV channel
|
2020-04-20 08:59:10 +02:00
|
|
|
:type channel: str
|
2020-03-19 16:45:31 +01:00
|
|
|
"""
|
2020-04-20 08:59:10 +02:00
|
|
|
channel_info = CHANNELS[channel]
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
# Lookup the high resolution logo based on the channel name
|
2020-04-20 08:59:10 +02:00
|
|
|
fanart = '{path}/resources/logos/{logo}'.format(path=kodiutils.addon_path(), logo=channel_info.get('background'))
|
2020-03-19 16:45:31 +01:00
|
|
|
|
2021-02-01 08:53:13 +01:00
|
|
|
listing = []
|
|
|
|
|
|
|
|
if channel_info.get('epg_id'):
|
|
|
|
listing.append(
|
|
|
|
TitleItem(
|
|
|
|
title=kodiutils.localize(30053, channel=channel_info.get('name')), # TV Guide for {channel}
|
|
|
|
path=kodiutils.url_for('show_channel_tvguide', channel=channel),
|
|
|
|
art_dict={
|
|
|
|
'icon': 'DefaultAddonTvInfo.png',
|
|
|
|
'fanart': fanart,
|
|
|
|
},
|
|
|
|
info_dict={
|
|
|
|
'plot': kodiutils.localize(30054, channel=channel_info.get('name')), # Browse the TV Guide for {channel}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
listing.append(
|
2020-03-20 13:53:21 +01:00
|
|
|
TitleItem(
|
2020-04-20 08:59:10 +02:00
|
|
|
title=kodiutils.localize(30055, channel=channel_info.get('name')), # Catalog for {channel}
|
|
|
|
path=kodiutils.url_for('show_channel_catalog', channel=channel),
|
2020-03-20 13:53:21 +01:00
|
|
|
art_dict={
|
|
|
|
'icon': 'DefaultMovieTitle.png',
|
|
|
|
'fanart': fanart,
|
|
|
|
},
|
|
|
|
info_dict={
|
2020-04-20 08:59:10 +02:00
|
|
|
'plot': kodiutils.localize(30056, channel=channel_info.get('name')), # Browse the Catalog for {channel}
|
2020-03-20 13:53:21 +01:00
|
|
|
}
|
2021-02-01 08:53:13 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
# listing.append(
|
|
|
|
# TitleItem(
|
|
|
|
# title=kodiutils.localize(30057, channel=channel_info.get('name')), # Categories for {channel}
|
|
|
|
# path=kodiutils.url_for('show_channel_categories', channel=channel),
|
|
|
|
# art_dict={
|
|
|
|
# 'icon': 'DefaultGenre.png',
|
|
|
|
# 'fanart': fanart,
|
|
|
|
# },
|
|
|
|
# info_dict={
|
|
|
|
# 'plot': kodiutils.localize(30058, channel=channel_info.get('name')), # Browse the Categories for {channel}
|
|
|
|
# }
|
|
|
|
# )
|
|
|
|
# )
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
# Add YouTube channels
|
|
|
|
if kodiutils.get_cond_visibility('System.HasAddon(plugin.video.youtube)') != 0:
|
2020-04-20 08:59:10 +02:00
|
|
|
for youtube in channel_info.get('youtube', []):
|
2020-03-19 16:45:31 +01:00
|
|
|
listing.append(
|
2020-03-20 13:53:21 +01:00
|
|
|
TitleItem(
|
|
|
|
title=kodiutils.localize(30206, label=youtube.get('label')), # Watch {label} on YouTube
|
|
|
|
path=youtube.get('path'),
|
|
|
|
info_dict={
|
|
|
|
'plot': kodiutils.localize(30206, label=youtube.get('label')), # Watch {label} on YouTube
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 16:45:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30007, sort=['unsorted'])
|
2020-04-20 08:59:10 +02:00
|
|
|
|
2021-02-01 08:53:13 +01:00
|
|
|
# def show_channel_categories(self, channel):
|
|
|
|
# """ Shows the categories of a channel
|
|
|
|
# :type channel: str
|
|
|
|
# """
|
|
|
|
# categories = self._api.get_categories(channel)
|
|
|
|
#
|
|
|
|
# listing = [
|
|
|
|
# TitleItem(
|
|
|
|
# title=category.title,
|
|
|
|
# path=kodiutils.url_for('show_channel_category', channel=category.channel, category=category.uuid),
|
|
|
|
# art_dict={
|
|
|
|
# 'icon': 'DefaultGenre.png',
|
|
|
|
# },
|
|
|
|
# ) for category in categories
|
|
|
|
# ]
|
|
|
|
#
|
|
|
|
# kodiutils.show_listing(listing, 30007, sort=['unsorted'])
|
|
|
|
|
|
|
|
# def show_channel_category(self, channel, category_id):
|
|
|
|
# """ Shows a selected category of a channel
|
|
|
|
# :type channel: str
|
|
|
|
# :type category_id: str
|
|
|
|
# """
|
|
|
|
# categories = self._api.get_categories(channel)
|
|
|
|
#
|
|
|
|
# # Extract selected category
|
|
|
|
# category = next(category for category in categories if category.uuid == category_id)
|
|
|
|
# if not category:
|
|
|
|
# raise Exception('Unknown category')
|
|
|
|
#
|
|
|
|
# # Add programs
|
|
|
|
# listing_programs = []
|
|
|
|
# for item in category.programs:
|
|
|
|
# program = self._api.get_program(item.path, CACHE_ONLY) # Get program details, but from cache only
|
|
|
|
#
|
|
|
|
# if program:
|
|
|
|
# listing_programs.append(Menu.generate_titleitem(program))
|
|
|
|
# else:
|
|
|
|
# listing_programs.append(Menu.generate_titleitem(item))
|
|
|
|
#
|
|
|
|
# # Add episodes
|
|
|
|
# listing_episodes = []
|
|
|
|
# for item in category.episodes:
|
|
|
|
# # We don't have the Program Name without making a request to the page, so we use CACHE_AUTO instead of CACHE_ONLY.
|
|
|
|
# # This will make a request for each item in this view (about 12 items), but it goes quite fast.
|
|
|
|
# # Results are cached, so this will only happen once.
|
|
|
|
# episode = self._api.get_episode(item.path, CACHE_AUTO)
|
|
|
|
#
|
|
|
|
# if episode:
|
|
|
|
# listing_episodes.append(Menu.generate_titleitem(episode))
|
|
|
|
# else:
|
|
|
|
# listing_episodes.append(Menu.generate_titleitem(item))
|
|
|
|
#
|
|
|
|
# kodiutils.show_listing(listing_programs + listing_episodes, 30007, content='tvshows', sort=['unsorted'])
|