PM4K / PlexMod for Kodi (18, 19, 20, 21, 22+)

OK guys, it’s time.

0.7.9-beta13 (probably -prerelease1 soon): script.plexmod.zip (2.8 MB)

Introduction

Even though this is just another beta, here’s some context, as this one is bigger than any beta before.

As some of you might know, PM4K is basically a huge set of XML based windows that are interpreted by Kodi and the resulting UI controlled in Python.
Sadly, as opposed to Skins in Kodi, Plugins/Addons using the Kodi skinning engine, can’t make use of any real logic features such as includes, unified variable definitions, reusable code etc.

When it was obvious that Plex would once again change the watched marker, I had the option to either bloat the existing XML even further, to support the classic, modern 2023 and modern 2024 (un)watched states, or abandon the 2023 version, or go a completely different route.

I took the last option. Somehow I never really thought about it, but I had a slight brainwave a couple of weeks ago when thinking about the solution to this problem: Why not use a templating engine to gain code reusability? I’ve worked with jinja2 in the past, why wouldn’t that work with PM4K?

So I went and made a little test, ripping all the XML files that are referenced in PM4K’s code out of the addon folder to see whether my plugin entrypoint could simply generate a referenced XML for script-plex-home.xml before starting up its windows.

Guess what, it worked.

So I looked for a fitting templating language that I could use and landed on Ibis.

Ibis is a jinja2-like mostly pythonic templating engine, that is orders of magnitude smaller than jinja, is extensible and doesn’t have any binary dependencies. It was Python3.4+ only, though, and PM4K still supports Kodi 18 (Python 2.7), so I forked and extended it, adding a good couple of functions, such as variable handling in arithmetic operations, variables as filter/function args, and so on.

With this beta, there isn’t a single XML file supplied. Whenever you change your theme, or the theme version updates, or you change any theme related setting, the templates recompile and you’re good to go.

That doesn’t mean that the templates are now completely dynamic and without code duplication - I “only” managed the first step, but we have template inheritance and reuse, as well as fully dynamic playback-related buttons and watched indicators. Ah, and all theme files are now implicitly overridable and inheritable, so custom themes here we go.

I’ll post a little reference on the Github Wiki soon.

And, of course, we now have the new watched indicators besides the old options, together with a good couple of other fixes:

Temporary Changelog (filtered already):

  • Core: Add customized templating engine
  • Core: Add our own ibis-3.3.0 fork as a library
  • Core: Make ibis Python2/3 cross-compatible
  • Core: Fix time format issue introduced with last FireTV fix
  • Core: Fix certain network related issues
  • Core: Detect whether we’re using skin.plextuary
  • Player/Music: Fix broken shuffle handling (hopefully)
  • Fix seek issue with CoreELEC devices (thanks @bowlingbeeg)
  • Audio: Support direct play of high-res audio (<= 384 kHz)
  • Audio: Fix transcoding not working
  • Audio/Playqueues: Fix issue were track would skip back to the previous one
  • Audio/Playqueues: Generic fixes
  • Audio/CurrentPlayList: Allow round-robining
  • Audio/CurrentPlaylist: Close current playlist view when pressing back/previous menu with current playlist view open instead of closing the music player
  • Videoplayer/External: When using external player handle Ended events as always stopped manually
  • Photos: Correctly focus play button on OSD open
  • Home: Disable updates when screensaver activated
  • Home/Settings: Set home dirty when changing the option to show/hide path mapping indicators
  • Home: Wait 1 second before continuing (block input) after wake event (default); 5 seconds for CoreELEC (default)
  • Home: Don’t refresh stale sections while we’re not the active window; might improve UI performance after watching something
  • Home: update On Deck hubs after revisiting home, not before
  • Home: Avoid mis-selecting a hub item after watching something and returning to the hub, after updating the hub and a different selection has been made in the meantime
  • Home/Settings/Theming: When setting a theme-relevant setting, restart home
  • SeekDialog: Reduce skip-button “jumping” just before auto skipping a marker
  • Seekdialog: Only react to DOWN with OSD shown if we should behave like official Plex clients and we want/have (virtual) chapters
  • SeekDialog/VideoSettingsDialog: Don’t fade background when OSDBackgroundPause isn’t activated in plextuary; never fade background when SliderDialog is active (audio/subtitle offset adjustments), regardless of the skin used
  • VideoPlaylists: Fix returning to playlist after manually stopping a video
  • VideoPlaylists: Properly select first unwatched item if possible; correctly set current item after returning from watching more than one
  • SeekDialog/CurrentPlaylist: Honor no TV spoilers setting as well
  • Episodes: Fix no related shows shown; broken for half a year
  • Episodes: Fix episodes not playable after returning from playback
  • Episodes/Movies: Fix play button not working after cancelling the resume dialog; fix play button not working after returning to view after direct playing from home
  • SeasonsMixin: Select the first unwatched season by default
  • Episodes: Correctly update unwatched counter in seasons list after marking an episode watched
  • TV Shows: Fix play button not working after returning from playback on TV Shows/Seasons screen
  • Core/Theming: When rendering templates, show kodi progress dialog
  • Core/Theming: Allow overriding theme definition/defaults by supplying theme_overrides.json in userdata/addon_data/script.plexmod; see /lib/templating/context.py for the data structure
  • Core/Settings: Implement theme-relevant settings flag; reapply theme if necessary after exiting settings and revisiting home
  • Settings: Focus setting categories when pressing back while inside a category instead of immediately backing out
  • Settings/TV/Spoilers: Make allowed TV spoilers for specific genres configurable
  • Settings/Video: Streamline playback features and video codecs to reduce the amount of settings available
  • Settings/MultiOptionsSetting: Keep original options order when displaying currently selected options
  • Settings: Add MultiUAOptionsSetting (a user aware variant of MultiOptionsSetting)
  • Settings/Player: Make “Show buttons” setting user aware
  • Settings/Player: Add “Skip intro” and “Skip credits” to button options, allowing per-user control of whether marker action buttons should be shown or not (default: On)
  • Settings: Move “Player Theme” setting to Main section and rename it to “Theme”
  • Settings: Remove visually “annoying” last main section item bottom border
  • Settings: Add setting “Action on Wake event” (none, restart pm4k, wait Xs)
  • Settings: Add setting to enable or disable factor based scaling of modern watched indicators based on poster size (default: on)
  • Settings: Rename “Hide black backdrop in inverted watched states” to “Hide background in modern indicators”
  • Settings: Move Theme selection above Indicators
  • Settings: Implement new watched/unwatched status setting (default: Modern (2024))
  • Theming: Apply button themes to all views
  • Theming: Cache templates by default, making subsequent theme-related changes blazing fast (cache clears after restarting PM4K and is filled again when recompiling templates)
  • Theming: Implement new 2024 watch status
  • Theming: Make watch status indicator handling fully dynamic (templated)
  • Templating/Watched_indicators: Implement factor based scaling of modern watched indicators based on poster size
  • Theming/Playlists: Use different watched indicator location
  • AddonSettings: Add setting to Cache Templates (default: on); Add setting to always recompile templates on start (default: off)

PS: For you to be able to test all template/theme-related settings and effects (I’m sure I’ve missed areas), the template engine caches the templates after compiling them, which is why the recompiling after changing a theme-related setting is so blazing fast. This is at the expense of a little bit of RAM. Please check whether this results in any issues that you haven’t had before, and if so, I might disable the template caching for the final version (as you probably rarely change your theme settings).

I need a break.

Edit: Known issues:

  • weird visual bug when transitioning from audio album view to audioplayer->current playlist (probably missed something when creating the template); non-breaking
14 Likes