2020-03-19 16:45:31 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
""" Catalog 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.modules.menu import Menu
|
2020-03-22 15:37:15 +01:00
|
|
|
from resources.lib.viervijfzes.auth import AuthApi
|
2020-10-26 10:25:57 +01:00
|
|
|
from resources.lib.viervijfzes.content import CACHE_PREVENT, ContentApi, UnavailableException
|
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 Catalog:
|
|
|
|
""" Menu code related to the catalog """
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
""" Initialise object """
|
2021-02-09 20:54:40 +01:00
|
|
|
self._auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path())
|
|
|
|
self._api = ContentApi(self._auth, cache_path=kodiutils.get_cache_path())
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
def show_catalog(self):
|
|
|
|
""" Show all the programs of all channels """
|
|
|
|
try:
|
2021-02-01 08:53:13 +01:00
|
|
|
items = self._api.get_programs()
|
2020-03-19 16:45:31 +01:00
|
|
|
except Exception as ex:
|
|
|
|
kodiutils.notification(message=str(ex))
|
|
|
|
raise
|
|
|
|
|
2020-04-20 08:59:10 +02:00
|
|
|
listing = [Menu.generate_titleitem(item) for item in items]
|
2020-03-19 16:45:31 +01:00
|
|
|
|
2020-03-22 15:37:15 +01:00
|
|
|
# Sort items by title
|
2020-03-19 16:45:31 +01:00
|
|
|
# Used for A-Z listing or when movies and episodes are mixed.
|
2020-03-22 15:37:15 +01:00
|
|
|
kodiutils.show_listing(listing, 30003, content='tvshows', sort='title')
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
def show_catalog_channel(self, channel):
|
|
|
|
""" Show the programs of a specific channel
|
|
|
|
:type channel: str
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
items = self._api.get_programs(channel)
|
|
|
|
except Exception as ex:
|
|
|
|
kodiutils.notification(message=str(ex))
|
|
|
|
raise
|
|
|
|
|
|
|
|
listing = []
|
|
|
|
for item in items:
|
2020-04-20 08:59:10 +02:00
|
|
|
listing.append(Menu.generate_titleitem(item))
|
2020-03-19 16:45:31 +01:00
|
|
|
|
2020-03-22 15:37:15 +01:00
|
|
|
# Sort items by title
|
2020-03-19 16:45:31 +01:00
|
|
|
# Used for A-Z listing or when movies and episodes are mixed.
|
2020-03-22 15:37:15 +01:00
|
|
|
kodiutils.show_listing(listing, 30003, content='tvshows', sort='title')
|
2020-03-19 16:45:31 +01:00
|
|
|
|
2021-02-01 08:53:13 +01:00
|
|
|
def show_program(self, program_id):
|
2020-03-19 16:45:31 +01:00
|
|
|
""" Show a program from the catalog
|
|
|
|
:type program_id: str
|
|
|
|
"""
|
|
|
|
try:
|
2021-02-01 08:53:13 +01:00
|
|
|
program = self._api.get_program(program_id, extract_clips=True, cache=CACHE_PREVENT) # Use CACHE_PREVENT since we want fresh data
|
2020-03-19 16:45:31 +01:00
|
|
|
except UnavailableException:
|
2020-03-21 20:46:14 +01:00
|
|
|
kodiutils.ok_dialog(message=kodiutils.localize(30717)) # This program is not available in the catalogue.
|
2020-03-19 16:45:31 +01:00
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
2020-04-20 08:59:10 +02:00
|
|
|
if not program.episodes and not program.clips:
|
2020-03-21 20:46:14 +01:00
|
|
|
kodiutils.ok_dialog(message=kodiutils.localize(30717)) # This program is not available in the catalogue.
|
2020-03-19 16:45:31 +01:00
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
2020-04-20 08:59:10 +02:00
|
|
|
# Go directly to the season when we have only one season and no clips
|
|
|
|
if not program.clips and len(program.seasons) == 1:
|
2021-02-01 08:53:13 +01:00
|
|
|
self.show_program_season(program_id, list(program.seasons.values())[0].uuid)
|
2020-03-19 16:45:31 +01:00
|
|
|
return
|
|
|
|
|
|
|
|
listing = []
|
|
|
|
|
|
|
|
# Add an '* All seasons' entry when configured in Kodi
|
2020-04-20 08:59:10 +02:00
|
|
|
if program.seasons and kodiutils.get_global_setting('videolibrary.showallitems') is True:
|
2020-03-19 16:45:31 +01:00
|
|
|
listing.append(
|
2020-03-20 13:53:21 +01:00
|
|
|
TitleItem(
|
|
|
|
title='* %s' % kodiutils.localize(30204), # * All seasons
|
2021-02-01 08:53:13 +01:00
|
|
|
path=kodiutils.url_for('show_catalog_program_season', program=program_id, season='-1'),
|
2020-03-20 13:53:21 +01:00
|
|
|
art_dict={
|
2021-03-19 16:45:26 +01:00
|
|
|
'fanart': program.fanart,
|
|
|
|
'poster': program.poster,
|
|
|
|
'landscape': program.thumb,
|
2020-03-20 13:53:21 +01:00
|
|
|
},
|
|
|
|
info_dict={
|
|
|
|
'tvshowtitle': program.title,
|
|
|
|
'title': kodiutils.localize(30204), # All seasons
|
|
|
|
'plot': program.description,
|
|
|
|
'set': program.title,
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 16:45:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Add the seasons
|
2020-03-25 08:08:15 +01:00
|
|
|
for season in list(program.seasons.values()):
|
2020-03-19 16:45:31 +01:00
|
|
|
listing.append(
|
2020-03-20 13:53:21 +01:00
|
|
|
TitleItem(
|
2020-03-25 08:08:15 +01:00
|
|
|
title=season.title, # kodiutils.localize(30205, season=season.number), # Season {season}
|
2021-02-01 08:53:13 +01:00
|
|
|
path=kodiutils.url_for('show_catalog_program_season', program=program_id, season=season.uuid),
|
2020-03-20 13:53:21 +01:00
|
|
|
art_dict={
|
2021-03-19 16:45:26 +01:00
|
|
|
'fanart': program.fanart,
|
|
|
|
'poster': program.poster,
|
|
|
|
'landscape': program.thumb,
|
2020-03-20 13:53:21 +01:00
|
|
|
},
|
|
|
|
info_dict={
|
|
|
|
'tvshowtitle': program.title,
|
2021-10-21 15:19:10 +02:00
|
|
|
'title': kodiutils.localize(30205, season=season.number) if season.number else season.title, # Season {season}
|
2021-02-16 16:57:52 +01:00
|
|
|
'plot': season.description or program.description,
|
2020-03-20 13:53:21 +01:00
|
|
|
'set': program.title,
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 16:45:31 +01:00
|
|
|
)
|
|
|
|
|
2020-04-20 08:59:10 +02:00
|
|
|
# Add Clips
|
|
|
|
if program.clips:
|
|
|
|
listing.append(
|
|
|
|
TitleItem(
|
|
|
|
title=kodiutils.localize(30059, program=program.title), # Clips for {program}
|
2021-02-01 08:53:13 +01:00
|
|
|
path=kodiutils.url_for('show_catalog_program_clips', program=program_id),
|
2020-04-20 08:59:10 +02:00
|
|
|
art_dict={
|
2021-03-19 16:45:26 +01:00
|
|
|
'fanart': program.fanart,
|
|
|
|
'poster': program.poster,
|
|
|
|
'landscape': program.thumb,
|
2020-04-20 08:59:10 +02:00
|
|
|
},
|
|
|
|
info_dict={
|
|
|
|
'tvshowtitle': program.title,
|
|
|
|
'title': kodiutils.localize(30059, program=program.title), # Clips for {program}
|
|
|
|
'plot': kodiutils.localize(30060, program=program.title), # Watch short clips of {program}
|
|
|
|
'set': program.title,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2020-03-19 16:45:31 +01:00
|
|
|
# Sort by label. Some programs return seasons unordered.
|
2020-03-22 15:37:15 +01:00
|
|
|
kodiutils.show_listing(listing, 30003, content='tvshows')
|
2020-03-19 16:45:31 +01:00
|
|
|
|
2021-02-01 08:53:13 +01:00
|
|
|
def show_program_season(self, program_id, season_uuid):
|
2020-03-19 16:45:31 +01:00
|
|
|
""" Show the episodes of a program from the catalog
|
|
|
|
:type program_id: str
|
2020-03-22 15:37:15 +01:00
|
|
|
:type season_uuid: str
|
2020-03-19 16:45:31 +01:00
|
|
|
"""
|
|
|
|
try:
|
2021-02-01 08:53:13 +01:00
|
|
|
program = self._api.get_program(program_id)
|
2020-03-19 16:45:31 +01:00
|
|
|
except UnavailableException:
|
2020-03-21 20:46:14 +01:00
|
|
|
kodiutils.ok_dialog(message=kodiutils.localize(30717)) # This program is not available in the catalogue.
|
2020-03-19 16:45:31 +01:00
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
2020-03-22 15:37:15 +01:00
|
|
|
if season_uuid == "-1":
|
2020-03-19 16:45:31 +01:00
|
|
|
# Show all episodes
|
|
|
|
episodes = program.episodes
|
|
|
|
else:
|
|
|
|
# Show the episodes of the season that was selected
|
2020-03-22 15:37:15 +01:00
|
|
|
episodes = [e for e in program.episodes if e.season_uuid == season_uuid]
|
2020-03-19 16:45:31 +01:00
|
|
|
|
2020-04-20 08:59:10 +02:00
|
|
|
listing = [Menu.generate_titleitem(episode) for episode in episodes]
|
2020-03-19 16:45:31 +01:00
|
|
|
|
|
|
|
# Sort by episode number by default. Takes seasons into account.
|
|
|
|
kodiutils.show_listing(listing, 30003, content='episodes', sort=['episode', 'duration'])
|
2020-04-20 08:59:10 +02:00
|
|
|
|
2021-02-01 08:53:13 +01:00
|
|
|
def show_program_clips(self, program_id):
|
2020-04-20 08:59:10 +02:00
|
|
|
""" Show the clips of a program from the catalog
|
|
|
|
:type program_id: str
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
# We need to query the backend, since we don't cache clips.
|
2021-02-01 08:53:13 +01:00
|
|
|
program = self._api.get_program(program_id, extract_clips=True, cache=CACHE_PREVENT)
|
2020-04-20 08:59:10 +02:00
|
|
|
except UnavailableException:
|
|
|
|
kodiutils.ok_dialog(message=kodiutils.localize(30717)) # This program is not available in the catalogue.
|
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
|
|
|
listing = [Menu.generate_titleitem(episode) for episode in program.clips]
|
|
|
|
|
|
|
|
# Sort like we get our results back.
|
|
|
|
kodiutils.show_listing(listing, 30003, content='episodes')
|
2021-02-09 20:54:40 +01:00
|
|
|
|
2021-02-17 07:42:24 +01:00
|
|
|
def show_categories(self):
|
|
|
|
""" Shows the categories """
|
|
|
|
categories = self._api.get_categories()
|
|
|
|
|
|
|
|
listing = []
|
|
|
|
for category in categories:
|
|
|
|
listing.append(TitleItem(title=category.title,
|
|
|
|
path=kodiutils.url_for('show_category', category=category.uuid),
|
|
|
|
info_dict={
|
|
|
|
'title': category.title,
|
|
|
|
}))
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30003, sort=['title'])
|
|
|
|
|
|
|
|
def show_category(self, uuid):
|
|
|
|
""" Shows a category """
|
|
|
|
programs = self._api.get_category_content(int(uuid))
|
|
|
|
|
|
|
|
listing = [
|
|
|
|
Menu.generate_titleitem(program) for program in programs
|
|
|
|
]
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30003, content='tvshows')
|
|
|
|
|
|
|
|
def show_recommendations(self):
|
|
|
|
""" Shows the recommendations """
|
|
|
|
# "Meest bekeken" has a specific API endpoint, the other categories are scraped from the website.
|
|
|
|
listing = [
|
|
|
|
TitleItem(title='Meest bekeken',
|
|
|
|
path=kodiutils.url_for('show_recommendations_category', category='meest-bekeken'),
|
|
|
|
info_dict={
|
|
|
|
'title': 'Meest bekeken',
|
|
|
|
})
|
|
|
|
]
|
|
|
|
|
|
|
|
recommendations = self._api.get_recommendation_categories()
|
|
|
|
for category in recommendations:
|
|
|
|
listing.append(TitleItem(title=category.title,
|
|
|
|
path=kodiutils.url_for('show_recommendations_category', category=category.uuid),
|
|
|
|
info_dict={
|
|
|
|
'title': category.title,
|
|
|
|
}))
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30005, content='tvshows')
|
|
|
|
|
|
|
|
def show_recommendations_category(self, uuid):
|
|
|
|
""" Shows the a category of the recommendations """
|
|
|
|
if uuid == 'meest-bekeken':
|
|
|
|
programs = self._api.get_popular_programs()
|
|
|
|
episodes = []
|
|
|
|
else:
|
|
|
|
recommendations = self._api.get_recommendation_categories()
|
|
|
|
category = next(category for category in recommendations if category.uuid == uuid)
|
|
|
|
programs = category.programs
|
|
|
|
episodes = category.episodes
|
|
|
|
|
|
|
|
listing = []
|
|
|
|
for episode in episodes:
|
|
|
|
title_item = Menu.generate_titleitem(episode)
|
2021-10-21 15:19:10 +02:00
|
|
|
if episode.program_title:
|
|
|
|
title_item.info_dict['title'] = episode.program_title + ' - ' + title_item.title
|
2021-02-17 07:42:24 +01:00
|
|
|
listing.append(title_item)
|
|
|
|
|
|
|
|
for program in programs:
|
|
|
|
listing.append(Menu.generate_titleitem(program))
|
|
|
|
|
|
|
|
kodiutils.show_listing(listing, 30005, content='tvshows')
|
|
|
|
|
2021-02-09 20:54:40 +01:00
|
|
|
def show_mylist(self):
|
2022-02-03 18:38:34 +01:00
|
|
|
""" Show the programs of My List """
|
|
|
|
mylist = self._api.get_mylist()
|
2021-02-09 20:54:40 +01:00
|
|
|
|
2022-02-03 18:38:34 +01:00
|
|
|
listing = [Menu.generate_titleitem(item) for item in mylist]
|
2021-02-09 20:54:40 +01:00
|
|
|
|
|
|
|
# Sort items by title
|
|
|
|
# Used for A-Z listing or when movies and episodes are mixed.
|
|
|
|
kodiutils.show_listing(listing, 30011, content='tvshows', sort='title')
|
|
|
|
|
|
|
|
def mylist_add(self, uuid):
|
|
|
|
""" Add a program to My List """
|
|
|
|
if not uuid:
|
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
2022-02-03 18:38:34 +01:00
|
|
|
self._api.mylist_add(uuid)
|
2021-02-09 20:54:40 +01:00
|
|
|
|
|
|
|
kodiutils.end_of_directory()
|
|
|
|
|
|
|
|
def mylist_del(self, uuid):
|
|
|
|
""" Remove a program from My List """
|
|
|
|
if not uuid:
|
|
|
|
kodiutils.end_of_directory()
|
|
|
|
return
|
|
|
|
|
2022-02-03 18:38:34 +01:00
|
|
|
self._api.mylist_del(uuid)
|
2021-02-09 20:54:40 +01:00
|
|
|
|
|
|
|
kodiutils.end_of_directory()
|