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

Small cleanup #125

Merged
merged 1 commit into from
Nov 4, 2019
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
4 changes: 1 addition & 3 deletions resources/lib/modules/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,8 @@ def show_continuewatching(self):
titleitem = self._menu.generate_titleitem(item, progress=True)

# Add Program Name to title since this list contains episodes from multiple programs
title = '%s - %s' % (titleitem.info_dict.get('tvshowtitle'), titleitem.info_dict.get('title'))
titleitem.title = title
title = '%s - %dx%02d - %s' % (titleitem.info_dict.get('tvshowtitle'), titleitem.info_dict.get('season'), titleitem.info_dict.get('episode'), titleitem.info_dict.get('title'))
titleitem.info_dict['title'] = title

listing.append(titleitem)

# Sort categories by default like in VTM GO.
Expand Down
68 changes: 16 additions & 52 deletions resources/lib/modules/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ def format_plot(self, obj):
"""
plot = ''

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

if hasattr(obj, 'epg'):
if obj.epg:
plot += self._kodi.localize(30213, # Now
Expand All @@ -148,6 +144,7 @@ def format_plot(self, obj):
start=obj.epg[1].start.strftime('%H:%M'),
end=obj.epg[1].end.strftime('%H:%M'),
title=obj.epg[1].title) + "\n"
plot += '\n'

# Add remaining
if hasattr(obj, 'remaining') and obj.remaining is not None:
Expand All @@ -163,12 +160,17 @@ def format_plot(self, obj):
plot += '» ' + self._kodi.localize(30211, months=int(obj.remaining / 30.5)) + "\n" # X months remaining
else:
plot += '» ' + self._kodi.localize(30212, days=obj.remaining) + "\n" # X days remaining
plot += '\n'

# Add geo-blocked message
if hasattr(obj, 'geoblocked') and obj.geoblocked:
plot += self._kodi.localize(30207) # Geo-blocked
plot += '\n'

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

return plot.rstrip()

def generate_titleitem(self, item, progress=False):
Expand All @@ -179,10 +181,13 @@ def generate_titleitem(self, item, progress=False):
"""
art_dict = {
'thumb': item.cover,
'cover': item.cover,
}
info_dict = {
'title': item.name,
'plot': item.description,
'plot': self.format_plot(item),
'studio': CHANNELS.get(item.channel, {}).get('studio_icon'),
'mpaa': ', '.join(item.legal) if hasattr(item, 'legal') and item.legal else self._kodi.localize(30216),
}
prop_dict = {}

Expand All @@ -204,16 +209,13 @@ def generate_titleitem(self, item, progress=False):
)]

art_dict.update({
'fanart': item.cover,
'fanart': item.image,
})
info_dict.update({
'mediatype': 'movie',
'plot': self.format_plot(item),
'duration': item.duration,
'year': item.year,
'aired': item.aired,
'studio': CHANNELS.get(item.channel, {}).get('studio_icon'),
'mpaa': ', '.join(item.legal) if hasattr(item, 'legal') and item.legal else self._kodi.localize(30216),
})

return TitleItem(title=item.name,
Expand Down Expand Up @@ -246,15 +248,10 @@ def generate_titleitem(self, item, progress=False):
)]

art_dict.update({
'fanart': item.cover,
'banner': item.cover,
'fanart': item.image,
})
info_dict.update({
'mediatype': None,
'title': item.name,
'plot': self.format_plot(item),
'studio': CHANNELS.get(item.channel, {}).get('studio_icon'),
'mpaa': ', '.join(item.legal) if hasattr(item, 'legal') and item.legal else self._kodi.localize(30216),
'season': len(item.seasons),
})

Expand All @@ -274,20 +271,18 @@ def generate_titleitem(self, item, progress=False):
self._kodi.url_for('show_catalog_program', program=item.program_id)
)]

art_dict.update({
'fanart': item.cover,
})
info_dict.update({
'mediatype': 'episode',
'tvshowtitle': item.program_name,
'title': item.name,
'plot': self.format_plot(item),
'duration': item.duration,
'season': item.season,
'episode': item.number,
'mediatype': 'episode',
'set': item.program_name,
'studio': item.channel,
'aired': item.aired,
'mpaa': ', '.join(item.legal) if hasattr(item, 'legal') and item.legal else self._kodi.localize(30216),
})

if progress and item.watched:
info_dict.update({
'playcount': 1,
Expand All @@ -300,37 +295,6 @@ def generate_titleitem(self, item, progress=False):
'width': 1920,
}

# Get program and episode details from cache
program = self._vtm_go.get_program(item.program_id, cache=True)
if program:
episode = self._vtm_go.get_episode_from_program(program, item.episode_id)
if episode:
art_dict.update({
'fanart': episode.cover,
'banner': episode.cover,
})
info_dict.update({
'tvshowtitle': program.name,
'title': episode.name,
'plot': self.format_plot(episode),
'duration': episode.duration,
'season': episode.season,
'episode': episode.number,
'set': program.name,
'studio': episode.channel,
'aired': episode.aired,
'mpaa': ', '.join(episode.legal) if hasattr(episode, 'legal') and episode.legal else self._kodi.localize(30216),
})

if progress and item.watched:
info_dict.update({
'playcount': 1,
})

stream_dict.update({
'duration': episode.duration,
})

# Add progress info
if progress and not item.watched and item.progress:
prop_dict.update({
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from time import time

from xbmc import Monitor
from resources.lib.kodiwrapper import KodiWrapper, LOG_INFO
from resources.lib.vtmgo.vtmgo import VtmGo
from xbmc import Monitor


class BackgroundService(Monitor):
Expand Down
39 changes: 33 additions & 6 deletions resources/lib/vtmgo/vtmgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ def __repr__(self):
class Movie:
""" Defines a Movie """

def __init__(self, movie_id=None, name=None, description=None, year=None, cover=None, duration=None, remaining=None, geoblocked=None,
def __init__(self, movie_id=None, name=None, description=None, year=None, cover=None, image=None, duration=None, remaining=None, geoblocked=None,
channel=None, legal=None, aired=None, my_list=None):
"""
:type movie_id: str
:type name: str
:type description: str
:type year: int
:type cover: str
:type image: str
:type duration: int
:type remaining: str
:type geoblocked: bool
Expand All @@ -102,6 +103,7 @@ def __init__(self, movie_id=None, name=None, description=None, year=None, cover=
self.description = description if description else ''
self.year = year
self.cover = cover
self.image = image
self.duration = duration
self.remaining = remaining
self.geoblocked = geoblocked
Expand All @@ -117,12 +119,13 @@ def __repr__(self):
class Program:
""" Defines a Program """

def __init__(self, program_id=None, name=None, description=None, cover=None, seasons=None, geoblocked=None, channel=None, legal=None, my_list=None):
def __init__(self, program_id=None, name=None, description=None, cover=None, image=None, seasons=None, geoblocked=None, channel=None, legal=None, my_list=None):
"""
:type program_id: str
:type name: str
:type description: str
:type cover: str
:type image: str
:type seasons: dict[int, Season]
:type geoblocked: bool
:type channel: str
Expand All @@ -133,6 +136,7 @@ def __init__(self, program_id=None, name=None, description=None, cover=None, sea
self.name = name
self.description = description if description else ''
self.cover = cover
self.image = image
self.seasons = seasons if seasons else {}
self.geoblocked = geoblocked
self.channel = channel
Expand Down Expand Up @@ -259,23 +263,29 @@ def get_recommendations(self):
if item.get('target', {}).get('type') == self.CONTENT_TYPE_MOVIE:
movie = self.get_movie(item.get('target', {}).get('id'), cache=True)
if movie:
# We have a cover from the overview that we don't have in the details
movie.cover = item.get('imageUrl')
items.append(movie)
else:
items.append(Movie(
movie_id=item.get('target', {}).get('id'),
name=item.get('title'),
cover=item.get('imageUrl'),
image=item.get('imageUrl'),
geoblocked=item.get('geoBlocked'),
))
elif item.get('target', {}).get('type') == self.CONTENT_TYPE_PROGRAM:
program = self.get_program(item.get('target', {}).get('id'), cache=True)
if program:
# We have a cover from the overview that we don't have in the details
program.cover = item.get('imageUrl')
items.append(program)
else:
items.append(Program(
program_id=item.get('target', {}).get('id'),
name=item.get('title'),
cover=item.get('imageUrl'),
image=item.get('imageUrl'),
geoblocked=item.get('geoBlocked'),
))

Expand All @@ -302,44 +312,54 @@ def get_swimlane(self, swimlane=None):
if item.get('target', {}).get('type') == self.CONTENT_TYPE_MOVIE:
movie = self.get_movie(item.get('target', {}).get('id'), cache=True)
if movie:
# We have a cover from the overview that we don't have in the details
movie.cover = item.get('imageUrl')
items.append(movie)
else:
items.append(Movie(
movie_id=item.get('target', {}).get('id'),
name=item.get('title'),
geoblocked=item.get('geoBlocked'),
cover=item.get('imageUrl'),
image=item.get('imageUrl'),
))

elif item.get('target', {}).get('type') == self.CONTENT_TYPE_PROGRAM:
program = self.get_program(item.get('target', {}).get('id'), cache=True)
if program:
# We have a cover from the overview that we don't have in the details
program.cover = item.get('imageUrl')
items.append(program)
else:
items.append(Program(
program_id=item.get('target', {}).get('id'),
name=item.get('title'),
geoblocked=item.get('geoBlocked'),
cover=item.get('imageUrl'),
image=item.get('imageUrl'),
))

elif item.get('target', {}).get('type') == self.CONTENT_TYPE_EPISODE:
if swimlane == 'continue-watching':
title = '%dx%02d' % (item.get('target', {}).get('seasonIndex'), item.get('target', {}).get('episodeIndex'))
# We need to fetch the episode, since the overview is lacking the plot
episode = self.get_episode(item.get('target', {}).get('id'))
if episode:
plot = episode.description
else:
title = item.get('title')
plot = None

items.append(Episode(
episode_id=item.get('target', {}).get('id'),
program_id=item.get('target', {}).get('programId'),
program_name=item.get('target', {}).get('programName'),
number=item.get('target', {}).get('episodeIndex'),
season=item.get('target', {}).get('seasonIndex'),
name=title,
name=item.get('title'),
description=plot,
geoblocked=item.get('geoBlocked'),
cover=item.get('imageUrl'),
progress=item.get('playerPositionSeconds'),
watched=False,
remaining=item.get('remainingDaysAvailable'),
))

return items
Expand Down Expand Up @@ -430,6 +450,8 @@ def get_items(self, category=None, cache=False):
if item.get('target', {}).get('type') == self.CONTENT_TYPE_MOVIE:
movie = self.get_movie(item.get('target', {}).get('id'), cache=True)
if movie:
# We have a cover from the overview that we don't have in the details
movie.cover = item.get('imageUrl')
items.append(movie)
else:
items.append(Movie(
Expand All @@ -441,6 +463,8 @@ def get_items(self, category=None, cache=False):
elif item.get('target', {}).get('type') == self.CONTENT_TYPE_PROGRAM:
program = self.get_program(item.get('target', {}).get('id'), cache=True)
if program:
# We have a cover from the overview that we don't have in the details
program.cover = item.get('imageUrl')
items.append(program)
else:
items.append(Program(
Expand Down Expand Up @@ -476,6 +500,7 @@ def get_movie(self, movie_id, cache=False):
description=movie.get('description'),
duration=movie.get('durationSeconds'),
cover=movie.get('bigPhotoUrl'),
image=movie.get('bigPhotoUrl'),
year=movie.get('productionYear'),
geoblocked=movie.get('geoBlocked'),
remaining=movie.get('remainingDaysAvailable'),
Expand Down Expand Up @@ -542,6 +567,7 @@ def get_program(self, program_id, cache=False):
name=program.get('name'),
description=program.get('description'),
cover=program.get('bigPhotoUrl'),
image=program.get('bigPhotoUrl'),
geoblocked=program.get('geoBlocked'),
seasons=seasons,
channel=channel,
Expand Down Expand Up @@ -581,6 +607,7 @@ def get_episode(self, episode_id):
season=episode.get('seasonIndex'),
name=episode.get('name'),
description=episode.get('description'),
geoblocked=episode.get('geoBlocked'),
cover=episode.get('bigPhotoUrl'),
progress=episode.get('playerPositionSeconds'),
)
Expand Down