2024-02-01, 14:39
(2024-02-01, 02:01)Fuchs2468 Wrote:Hello!(2024-01-31, 18:35)davorf Wrote: This way I get something similar to HBO Max/Plex interface, which shows unified Continue watching "widget". If anybody needs it, I can share parts of code I've added to skin.helper.widgets package.
Yes, I'm interested, unfortunately I'm not familiar with the "HBO Max/Plex interface", maybe it's an enrichment for the skin.
It basically shows in progress movies and TV shows, plus next episodes of the TV shows you're watching. Here's the screenshot (from the Internet, not mine):
Now, what I've done is: I've combined In progress movies widget (from movies.py) and Next episodes (from episodes.py). There's no need to add In progress episodes, since Next episodes also shows episodes in progress.
* Changes to Kodi\addons\script.skin.helper.widgets\resources\language\resource.language.en_gb\strings.po:
on line 375 I've added
Code:
msgctxt "#32089"
msgid "In progress media and next Episodes"
msgstr ""
* Changes to Kodi\addons\script.skin.helper.widgets\resources\lib\media.py:
on line 47 I've added
Code:
(self.addon.getLocalizedString(32089), "inprogressmediaandnextepisode&mediatype=media", "DefaultMovies.png"),
on line 249 I've added
Code:
def inprogressmediaandnextepisode(self):
''' get in progress media and next episodes '''
all_items = self.movies.inprogress()
''' get next episodes '''
filters = [kodi_constants.FILTER_UNWATCHED]
if self.options["next_inprogress_only"]:
filters = [kodi_constants.FILTER_INPROGRESS]
if self.options.get("tag"):
filters.append({"operator": "contains", "field": "tag", "value": self.options["tag"]})
if self.options.get("path"):
filters.append({"operator": "startswith", "field": "path", "value": self.options["path"]})
# First we get a list of all the inprogress/unwatched TV shows ordered by lastplayed
all_shows = self.metadatautils.kodidb.tvshows(sort=kodi_constants.SORT_LASTPLAYED, filters=filters,
limits=(0, self.options["limit"]))
all_items += self.metadatautils.process_method_on_list(self.get_next_episode_for_show,
[d['tvshowid'] for d in all_shows])
return sorted(all_items, key=itemgetter("lastplayed"), reverse=True)[:self.options["limit"]]
def get_next_episode_for_show(self, show_id):
'''
get last played watched episode for show,
return next unwatched episode after that,
unless nothing after that, then return first episode
'''
filters = []
fields = ["playcount", "season"]
next_episode = None
if not self.options["episodes_enable_specials"]:
filters.append({"field": "season", "operator": "greaterthan", "value": "0"})
# get the next unwatched episode after the last played episode
last_played_episode = self.metadatautils.kodidb.episodes(sort=kodi_constants.SORT_LASTPLAYED,
filters=filters + [kodi_constants.FILTER_WATCHED], limits=(0, 1), tvshowid=show_id, fields=fields)
if last_played_episode:
last_played_episode = last_played_episode[0]
filter_season = last_played_episode["season"] - 1
filter_season = [{"field": "season", "operator": "greaterthan", "value": "%s" % filter_season}]
all_episodes = self.metadatautils.kodidb.episodes(sort=kodi_constants.SORT_EPISODE,
filters=filters + filter_season, tvshowid=show_id, fields=fields)
# find index of last_played_episode in the list all_episodes
try:
for index, episode in enumerate(all_episodes):
if episode['episodeid'] == last_played_episode['episodeid']:
i = 1
while True:
if int(all_episodes[index + i]['playcount']) < 1:
next_episode = all_episodes[index + i]
break
i += 1
except IndexError:
# no unplayed episodes left
next_episode = None
# just get the first unwatched episode (e.g. when we simply do not yet have any fully played episodes)
if not next_episode:
next_episode = self.metadatautils.kodidb.episodes(
sort=kodi_constants.SORT_EPISODE, filters=filters + [kodi_constants.FILTER_UNWATCHED],
limits=(0, 1), tvshowid=show_id, fields=fields)
next_episode = next_episode[0] if next_episode else None
# return full details for our episode
return self.metadatautils.kodidb.episode(next_episode["episodeid"]) if next_episode else None
After that, just saved edited files and restarted Kodi. Now you can choose "In progress media and next Episodes" from Skin Helper Widgets as a widget content and it will show all In progress media and next episodes in one widget.
Best regards,
Davor