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

Update to API 17 #388

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ def show_tvguide_detail(channel=None, date=None):
from resources.lib.modules.tvguide import TvGuide
TvGuide().show_tvguide_detail(channel, date)

@routing.route('/catalog/detail/<item>')
def show_detail(item):
""" Show a program from the catalog """
from resources.lib.modules.catalog import Catalog
Catalog().show_detail(item)

@routing.route('/catalog/program/<program>')
def show_catalog_program(program):
Expand Down
80 changes: 79 additions & 1 deletion resources/lib/modules/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from resources.lib import kodiutils
from resources.lib.modules import CHANNELS
from resources.lib.modules.menu import Menu
from resources.lib.vtmgo import STOREFRONT_MAIN, STOREFRONT_MOVIES, STOREFRONT_SHORTIES, Category
from resources.lib.vtmgo import STOREFRONT_MAIN, STOREFRONT_MOVIES, STOREFRONT_SHORTIES, Category, Program, Movie
from resources.lib.vtmgo.exceptions import UnavailableException
from resources.lib.vtmgo.vtmgo import CACHE_PREVENT, ApiUpdateRequired, VtmGo
from resources.lib.vtmgo.vtmgoauth import VtmGoAuth
Expand All @@ -24,6 +24,84 @@ def __init__(self):
auth = VtmGoAuth(kodiutils.get_tokens_path())
self._api = VtmGo(auth.get_tokens())

def show_detail(self, detail):
""" Show a detail from the catalog
:type detail: str
"""
try:
detail_obj = self._api.get_detail(detail, cache=CACHE_PREVENT) # Use CACHE_PREVENT since we want fresh data
except UnavailableException:
kodiutils.ok_dialog(message=kodiutils.localize(30717)) # This program is not available in the VTM GO catalogue.
kodiutils.end_of_directory()
return

if isinstance(detail_obj, Program):
program_obj = detail_obj
program = detail

# Go directly to the season when we have only one season
if len(program_obj.seasons) == 1:
self.show_program_season(program, list(program_obj.seasons.values())[0].number)
return

studio = CHANNELS.get(program_obj.channel, {}).get('studio_icon')

listing = []

# Add an '* All seasons' entry when configured in Kodi
if kodiutils.get_global_setting('videolibrary.showallitems') is True:
listing.append(kodiutils.TitleItem(
title='* %s' % kodiutils.localize(30204), # * All seasons
path=kodiutils.url_for('show_catalog_program_season', program=program, season=-1),
art_dict=dict(
poster=program_obj.poster,
thumb=program_obj.thumb,
landscape=program_obj.thumb,
fanart=program_obj.fanart,
),
info_dict=dict(
mediatype='season',
tvshowtitle=program_obj.name,
title=kodiutils.localize(30204), # All seasons
tagline=program_obj.description,
set=program_obj.name,
studio=studio,
mpaa=', '.join(program_obj.legal) if hasattr(program_obj, 'legal') and program_obj.legal else kodiutils.localize(30216), # All ages
),
))

# Add the seasons
for season in list(program_obj.seasons.values()):
listing.append(kodiutils.TitleItem(
title=kodiutils.localize(30205, season=season.number), # Season {season}
path=kodiutils.url_for('show_catalog_program_season', program=program, season=season.number),
art_dict=dict(
poster=program_obj.poster,
thumb=program_obj.thumb,
landscape=program_obj.thumb,
fanart=program_obj.fanart,
),
info_dict=dict(
mediatype='season',
tvshowtitle=program_obj.name,
title=kodiutils.localize(30205, season=season.number), # Season {season}
tagline=program_obj.description,
set=program_obj.name,
studio=studio,
mpaa=', '.join(program_obj.legal) if hasattr(program_obj, 'legal') and program_obj.legal else kodiutils.localize(30216), # All ages
),
))

# Sort by label. Some programs return seasons unordered.
kodiutils.show_listing(listing, program_obj.name, content='tvshows', sort=['label'])
return

if isinstance(detail_obj, Movie):
listing = []
listing.append(Menu.generate_titleitem(detail_obj))
kodiutils.show_listing(listing, 30017, content='files', sort=['unsorted', 'label', 'year', 'duration'])
return

def show_program(self, program):
""" Show a program from the catalog
:type program: str
Expand Down
43 changes: 38 additions & 5 deletions resources/lib/modules/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from resources.lib import kodiutils
from resources.lib.modules import CHANNELS
from resources.lib.vtmgo import STOREFRONT_KIDS, STOREFRONT_MAIN, STOREFRONT_MOVIES, STOREFRONT_SHORTIES, Episode, Movie, Program
from resources.lib.vtmgo import STOREFRONT_KIDS, STOREFRONT_MAIN, STOREFRONT_MOVIES, STOREFRONT_SHORTIES, Episode, Movie, Program, Teaser

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -146,7 +146,7 @@ def format_plot(obj):
plot += '\n'

# Add remaining
if hasattr(obj, 'remaining') and obj.remaining is not None:
if hasattr(obj, 'remaining') and obj.remaining:
if obj.remaining == 0:
plot += '» ' + kodiutils.localize(30208) + "\n" # Available until midnight
elif obj.remaining == 1:
Expand All @@ -166,7 +166,7 @@ def format_plot(obj):
plot += kodiutils.localize(30207) # Geo-blocked
plot += '\n'

if hasattr(obj, 'description'):
if hasattr(obj, 'description') and obj.description:
plot += obj.description
plot += '\n\n'

Expand All @@ -188,8 +188,8 @@ def generate_titleitem(cls, item, progress=False):
info_dict = {
'title': item.name,
'plot': cls.format_plot(item),
'studio': CHANNELS.get(item.channel, {}).get('studio_icon'),
'mpaa': ', '.join(item.legal) if hasattr(item, 'legal') and item.legal else kodiutils.localize(30216), # All ages
# 'studio': CHANNELS.get(item.channel, {}).get('studio_icon'),
# 'mpaa': ', '.join(item.legal) if hasattr(item, 'legal') and item.legal else kodiutils.localize(30216), # All ages
}
prop_dict = {}

Expand Down Expand Up @@ -317,4 +317,37 @@ def generate_titleitem(cls, item, progress=False):
is_playable=True,
)

#
# Teaser
#
if isinstance(item, Teaser):
# if item.my_list:
# context_menu = [(
# kodiutils.localize(30101), # Remove from My List
# 'Container.Update(%s)' %
# kodiutils.url_for('mylist_del', content_id=item.program_id)
# )]
# else:
# context_menu = [(
# kodiutils.localize(30100), # Add to My List
# 'Container.Update(%s)' %
# kodiutils.url_for('mylist_add', content_id=item.program_id)
# )]

# info_dict.update({
# 'mediatype': 'tvshow',
# 'year': item.year,
# 'season': len(item.seasons),
# })

return kodiutils.TitleItem(
title=info_dict['title'],
path=kodiutils.url_for('show_detail', item=item.detail_id),
art_dict=art_dict,
info_dict=info_dict,
prop_dict=prop_dict,
# context_menu=context_menu,
)


raise Exception('Unknown video_type')
22 changes: 22 additions & 0 deletions resources/lib/vtmgo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ def __init__(self, category_id=None, title=None, content=None):
def __repr__(self):
return "%r" % self.__dict__

class Teaser:
""" Defines a Teaser """

def __init__(self, detail_id=None, name=None, description=None, poster=None, thumb=None, fanart=None):
"""
:type detail_id: str
:type name: str
:type description: str
:type poster: str
:type thumb: str
:type fanart: str
"""
self.detail_id = detail_id
self.name = name
self.description = description
self.poster = poster
self.thumb = thumb
self.fanart = fanart

def __repr__(self):
return "%r" % self.__dict__


class Movie:
""" Defines a Movie """
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/vtmgo/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# Setup a static session that can be reused for all calls
SESSION = requests.Session()
SESSION.headers = {
'User-Agent': 'VTM_GO/15.231023 (be.vmma.vtm.zenderapp; build:18041; Android 23) okhttp/4.11.0',
'x-app-version': '15',
'User-Agent': 'VTM_GO/17.240626 (be.vmma.vtm.zenderapp; build:19069; Android 28) okhttp/4.12.0',
'x-app-version': '17',
'x-persgroep-mobile-app': 'true',
'x-persgroep-os': 'android',
'x-persgroep-os-version': '28',
Expand Down
Loading
Loading