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

Differentiate between Label and Title #668

Merged
merged 1 commit into from
Jan 11, 2020
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
23 changes: 12 additions & 11 deletions resources/lib/apihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def tvshow_to_listitem(self, tvshow, program, cache_file):
label += favorite_marker

return TitleItem(
title=label,
label=label,
path=url_for('programs', program=program),
art_dict=self._metadata.get_art(tvshow),
info_dict=self._metadata.get_info_labels(tvshow),
Expand Down Expand Up @@ -170,7 +170,7 @@ def __map_seasons(self, program, seasons, episodes):
# Add an "* All seasons" list item
if get_global_setting('videolibrary.showallitems') is True:
season_items.append(TitleItem(
title=localize(30133), # All seasons
label=localize(30133), # All seasons
path=url_for('programs', program=program, season='allseasons'),
art_dict=self._metadata.get_art(episode, season='allseasons'),
info_dict=info_labels,
Expand All @@ -189,7 +189,7 @@ def __map_seasons(self, program, seasons, episodes):

label = '%s %s' % (localize(30131), season_key) # Season X
season_items.append(TitleItem(
title=label,
label=label,
path=url_for('programs', program=program, season=season_key),
art_dict=self._metadata.get_art(episode, season=True),
info_dict=info_labels,
Expand Down Expand Up @@ -233,10 +233,11 @@ def episode_to_listitem(self, episode, program, cache_file, titletype):
label += favorite_marker + watchlater_marker

info_labels = self._metadata.get_info_labels(episode)
# FIXME: Due to a bug in Kodi, ListItem.Title is used when Sort methods are used, not ListItem.Label
info_labels['title'] = label

return TitleItem(
title=label,
label=label,
path=url_for('play_id', video_id=episode.get('videoId'), publication_id=episode.get('publicationId')),
art_dict=self._metadata.get_art(episode),
info_dict=info_labels,
Expand Down Expand Up @@ -370,7 +371,7 @@ def get_single_episode(self, video_id=None, whatson_id=None, video_url=None):
episode = self.get_single_episode_data(video_id=video_id, whatson_id=whatson_id, video_url=video_url)
if episode:
video_item = TitleItem(
title=self._metadata.get_label(episode),
label=self._metadata.get_label(episode),
art_dict=self._metadata.get_art(episode),
info_dict=self._metadata.get_info_labels(episode),
prop_dict=self._metadata.get_properties(episode),
Expand Down Expand Up @@ -437,7 +438,7 @@ def get_episode_by_air_date(self, channel_name, start_date, end_date=None):

if start_date and end_date:
video_item = TitleItem(
title=self._metadata.get_label(episode_guess_on),
label=self._metadata.get_label(episode_guess_on),
art_dict=self._metadata.get_art(episode_guess_on),
info_dict=self._metadata.get_info_labels(episode_guess_on, channel=channel, date=start_date),
prop_dict=self._metadata.get_properties(episode_guess_on),
Expand All @@ -463,7 +464,7 @@ def get_latest_episode(self, program):
episode = api_data[0]
log(2, str(episode))
video_item = TitleItem(
title=self._metadata.get_label(episode),
label=self._metadata.get_label(episode),
art_dict=self._metadata.get_art(episode),
info_dict=self._metadata.get_info_labels(episode),
prop_dict=self._metadata.get_properties(episode),
Expand Down Expand Up @@ -658,7 +659,7 @@ def list_channels(self, channels=None, live=True):
continue

channel_items.append(TitleItem(
title=label,
label=label,
path=path,
art_dict=art_dict,
info_dict=info_dict,
Expand Down Expand Up @@ -706,7 +707,7 @@ def list_youtube(channels=None):
))

youtube_items.append(TitleItem(
title=label,
label=label,
path=path,
art_dict=art_dict,
info_dict=info_dict,
Expand All @@ -724,7 +725,7 @@ def list_featured(self):
for feature in self.localize_features(FEATURED):
featured_name = feature.get('name')
featured_items.append(TitleItem(
title=featured_name,
label=featured_name,
path=url_for('featured', feature=feature.get('id')),
art_dict=dict(thumb='DefaultCountry.png'),
info_dict=dict(plot='[B]%s[/B]' % feature.get('name'), studio='VRT'),
Expand Down Expand Up @@ -756,7 +757,7 @@ def list_categories(self):
else:
thumbnail = 'DefaultGenre.png'
category_items.append(TitleItem(
title=category.get('name'),
label=category.get('name'),
path=url_for('categories', category=category.get('id')),
art_dict=dict(thumb=thumbnail, icon='DefaultGenre.png'),
info_dict=dict(plot='[B]%s[/B]' % category.get('name'), studio='VRT'),
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/helperobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def __init__(self, stream_url, subtitle_url=None, license_key=None, use_inputstr
class TitleItem:
"""This helper object holds all information to be used with Kodi xbmc's ListItem object"""

def __init__(self, title, path=None, art_dict=None, info_dict=None, stream_dict=None, prop_dict=None, context_menu=None, is_playable=False):
def __init__(self, label, path=None, art_dict=None, info_dict=None, stream_dict=None, prop_dict=None, context_menu=None, is_playable=False):
"""The constructor for the TitleItem class"""
self.title = title
self.label = label
self.path = path
self.art_dict = art_dict
self.info_dict = info_dict
Expand Down
5 changes: 3 additions & 2 deletions resources/lib/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# genre=xbmcplugin.SORT_METHOD_GENRE,
# label=xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE,
label=xbmcplugin.SORT_METHOD_LABEL,
title=xbmcplugin.SORT_METHOD_TITLE,
# none=xbmcplugin.SORT_METHOD_UNSORTED,
# FIXME: We would like to be able to sort by unprefixed title (ignore date/episode prefix)
# title=xbmcplugin.SORT_METHOD_TITLE_IGNORE_THE,
Expand Down Expand Up @@ -186,7 +187,7 @@ def show_listing(list_items, category=None, sort='unsorted', ascending=True, con
is_folder = bool(not title_item.is_playable and title_item.path)
is_playable = bool(title_item.is_playable and title_item.path)

list_item = ListItem(label=title_item.title)
list_item = ListItem(label=title_item.label)

prop_dict = dict(
IsInternetStream='true' if is_playable else 'false',
Expand Down Expand Up @@ -255,7 +256,7 @@ def play(stream, video=None):

play_item = ListItem(path=stream.stream_url)
if video and hasattr(video, 'info_dict'):
play_item.setProperty('subtitle', video.title)
play_item.setProperty('subtitle', video.label)
play_item.setArt(video.art_dict)
play_item.setInfo(
type='video',
Expand Down
68 changes: 57 additions & 11 deletions resources/lib/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,19 @@ def get_date(api_data):
# Not Found
return ''

@staticmethod
def get_aired(api_data):
def get_aired(self, api_data):
"""Get aired string from single item json api data"""

# VRT NU Search API
if api_data.get('type') == 'episode':
from datetime import datetime
import dateutil.tz
# FIXME: Due to a bug in Kodi, ListItem.Year, as shown in Info pane, is based on 'aired' when set
# If this is a oneoff (e.g. movie) and we get a year of release, do not set 'aired'
if api_data.get('programType') == 'oneoff' and self.get_year(api_data):
return ''
aired = ''
if api_data.get('broadcastDate'):
from datetime import datetime
import dateutil.tz
aired = datetime.fromtimestamp(api_data.get('broadcastDate', 0) / 1000, dateutil.tz.UTC).strftime('%Y-%m-%d')
return aired

Expand Down Expand Up @@ -513,6 +516,30 @@ def get_year(api_data):
# Not Found
return ''

def get_mediatype(self, api_data, season=False):
"""Get art dict from single item json api data"""

# VRT NU Search API
if api_data.get('type') == 'episode':
if season:
return 'season'

# If this is a oneoff (e.g. movie) and we get a year of release, do not set 'aired'
if api_data.get('programType') == 'oneoff' and self.get_year(api_data):
return 'movie'

return 'episode'

# VRT NU Suggest API
if api_data.get('type') == 'program':
return '' # NOTE: We do not use 'tvshow' as it won't show as a folder

# VRT NU Schedule API (some are missing vrt.whatson-id)
if api_data.get('vrt.whatson-id') or api_data.get('startTime'):
return 'video'

return ''

@staticmethod
def get_art(api_data, season=False):
"""Get art dict from single item json api data"""
Expand Down Expand Up @@ -570,12 +597,11 @@ def get_info_labels(self, api_data, season=False, date=None, channel=None):

# VRT NU Search API
if api_data.get('type') == 'episode':
titletype = api_data.get('programType')
episode_label = self.get_label(api_data, titletype)
info_labels = dict(
title=episode_label,
title=self.get_title(api_data),
# sorttitle=self.get_title(api_data), # NOTE: Does not appear to work
tvshowtitle=self.get_tvshowtitle(api_data),
date=self.get_date(api_data),
# date=self.get_date(api_data), # NOTE: Not sure when or how this is used
aired=self.get_aired(api_data),
dateadded=self.get_dateadded(api_data),
episode=self.get_episode(api_data),
Expand All @@ -585,7 +611,7 @@ def get_info_labels(self, api_data, season=False, date=None, channel=None):
plotoutline=self.get_plotoutline(api_data, season=season),
tagline=self.get_plotoutline(api_data, season=season),
duration=self.get_duration(api_data),
mediatype=api_data.get('type', 'episode'),
mediatype=self.get_mediatype(api_data, season=season),
studio=self.get_studio(api_data),
year=self.get_year(api_data),
tag=self.get_tag(api_data),
Expand All @@ -597,6 +623,7 @@ def get_info_labels(self, api_data, season=False, date=None, channel=None):
info_labels = dict(
tvshowtitle=self.get_tvshowtitle(api_data),
plot=self.get_plot(api_data),
mediatype=self.get_mediatype(api_data, season=season),
studio=self.get_studio(api_data),
tag=self.get_tag(api_data),
)
Expand All @@ -605,19 +632,38 @@ def get_info_labels(self, api_data, season=False, date=None, channel=None):
# VRT NU Schedule API (some are missing vrt.whatson-id)
if api_data.get('vrt.whatson-id') or api_data.get('startTime'):
info_labels = dict(
title=self.get_label(api_data),
title=self.get_title(api_data),
# sorttitle=self.get_title(api_data), # NOTE: Does not appear to work
tvshowtitle=self.get_tvshowtitle(api_data),
aired=self.get_aired(api_data),
plot=self.get_plot(api_data, date=date),
duration=self.get_duration(api_data),
mediatype=api_data.get('type', 'episode'),
mediatype=self.get_mediatype(api_data, season=season),
studio=channel.get('studio'),
)
return info_labels

# Not Found
return {}

@staticmethod
def get_title(api_data):
"""Get an appropriate video title"""

# VRT NU Search API
if api_data.get('type') == 'episode':
title = api_data.get('title') or api_data.get('shortDescription', '???')

# VRT NU Suggest API
elif api_data.get('type') == 'program':
title = api_data.get('title', '???')

# VRT NU Schedule API (some are missing vrt.whatson-id)
elif api_data.get('vrt.whatson-id') or api_data.get('startTime'):
title = api_data.get('title', '???')

return title

@staticmethod
def get_label(api_data, titletype=None, return_sort=False):
"""Get an appropriate label string matching the type of listing and VRT NU provided displayOptions from single item json api data"""
Expand Down
8 changes: 4 additions & 4 deletions resources/lib/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def search_menu(self):
from helperobjects import TitleItem
menu_items = [
TitleItem(
title=localize(30424), # New search...
label=localize(30424), # New search...
path=url_for('search_query'),
art_dict=dict(thumb='DefaultAddonsSearch.png'),
info_dict=dict(plot=localize(30425)),
Expand All @@ -47,7 +47,7 @@ def search_menu(self):
history = self.read_history()
for keywords in history:
menu_items.append(TitleItem(
title=keywords,
label=keywords,
path=url_for('search_query', keywords=keywords),
art_dict=dict(thumb='DefaultAddonsSearch.png'),
is_playable=False,
Expand All @@ -59,7 +59,7 @@ def search_menu(self):

if history:
menu_items.append(TitleItem(
title=localize(30426), # Clear search history
label=localize(30426), # Clear search history
path=url_for('clear_search'),
info_dict=dict(plot=localize(30427)),
art_dict=dict(thumb='icons/infodialogs/uninstall.png'),
Expand Down Expand Up @@ -93,7 +93,7 @@ def search(self, keywords=None, page=None):
from helperobjects import TitleItem
if len(search_items) == int(get_setting('itemsperpage', 50)):
search_items.append(TitleItem(
title=localize(30300), # More…
label=localize(30300), # More…
path=url_for('search_query', keywords=keywords, page=page + 1),
art_dict=dict(thumb='DefaultAddonSearch.png'),
info_dict=dict(),
Expand Down
17 changes: 9 additions & 8 deletions resources/lib/tvguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_date_items(channel=None):
date_items = []
for offset in range(7, -30, -1):
day = epg + timedelta(days=offset)
title = localize_datelong(day)
label = localize_datelong(day)
date = day.strftime('%Y-%m-%d')

# Highlight today with context of 2 days
Expand All @@ -81,9 +81,9 @@ def get_date_items(channel=None):
if entry.get('permalink'):
date = entry.get('id')
if offset == 0:
title = '[COLOR yellow][B]{name}[/B], {date}[/COLOR]'.format(name=date_name, date=title)
label = '[COLOR yellow][B]{name}[/B], {date}[/COLOR]'.format(name=date_name, date=label)
else:
title = '[B]{name}[/B], {date}'.format(name=date_name, date=title)
label = '[B]{name}[/B], {date}'.format(name=date_name, date=label)

# Show channel list or channel episodes
if channel:
Expand All @@ -93,7 +93,7 @@ def get_date_items(channel=None):

cache_file = 'schedule.%s.json' % date
date_items.append(TitleItem(
title=title,
label=label,
path=path,
art_dict=dict(thumb='DefaultYear.png'),
info_dict=dict(plot=localize_datelong(day)),
Expand Down Expand Up @@ -130,16 +130,16 @@ def get_channel_items(self, date=None, channel=None):
art_dict['thumb'] = 'DefaultTags.png'

if date:
title = chan.get('label')
label = chan.get('label')
path = url_for('tvguide', date=date, channel=chan.get('name'))
plot = '%s\n%s' % (localize(30302, **chan), datelong)
else:
title = '[B]%s[/B]' % localize(30303, **chan)
label = '[B]%s[/B]' % localize(30303, **chan)
path = url_for('tvguide_channel', channel=chan.get('name'))
plot = '%s\n\n%s' % (localize(30302, **chan), self.live_description(chan.get('name')))

channel_items.append(TitleItem(
title=title,
label=label,
path=path,
art_dict=art_dict,
info_dict=dict(plot=plot, studio=chan.get('studio')),
Expand Down Expand Up @@ -181,10 +181,11 @@ def get_episode_items(self, date, channel):
label += favorite_marker + watchlater_marker

info_labels = self._metadata.get_info_labels(episode, date=date, channel=entry)
# FIXME: Due to a bug in Kodi, ListItem.Title is used when Sort methods are used, not ListItem.Label
info_labels['title'] = label

episode_items.append(TitleItem(
title=label,
label=label,
path=path,
art_dict=self._metadata.get_art(episode),
info_dict=info_labels,
Expand Down
Loading