Plex - Continue watching a show, resuming where it was last left off

I’m currently using the standard Plex integration and am able to successfully play shows:

service: media_player.play_media
target:
  entity_id: media_player.plex_plex_for_apple_tv_tv_bedroom
data:
  media_content_id: '{ "library_name": "tv shows", "show_name": "game of thrones" }'
  media_content_type: episode

Whenever I launch the service above, it starts the show from the beginning (season 1 ep 1), as opposed to resuming from where I left off (in this example: season 8, episode 2).

How can I resume the show from where I left off last time, instead of starting from the beginning?

Not possible at the moment, but should be doable. I believe the API command will accept a specific offset, and can’t just be told to “resume”. Would take some thought on how to handle this.

Thanks for confirming.

I wrote the utility function needed to continue Plex shows in HA (with quite a bit of flexibility and fallback mechanisms), things seem to work very well. I just need to clear it with work to ensure I’m allowed to share code.

Notes:

  • Only available with TV shows
  • Below continuation modes can only work in either Show or Season contexts
  • If user specified show, season and Episode, then continuation logic doesn’t trigger

This is the current media_id “API” (“Futurama” example):

media_id: { "library_name": "tv shows", "show_name": "futurama" }

Proposed alterations includes new keyword: "_continue" (the leading underscore is added to emphasize that it’s not a Plex media_api field; can be removed if undesirable).

For example (cont. “Futurama” example)::

media_id: { "library_name": "tv shows", "show_name": "futurama", "_continue": "deck|unfinished_last|unwatched_first" }

This will attempt to continue Futurama from deck; if it’s not on deck, it will look for the last part-way watched episode; if no such episodes are found, it will attempt to continue the first unwatched episode; if it’s not found it will play from the beginning.

Following is a more detailed description:

The following continuation modes are supported:

1. Deck: resumes media off the library deck
   - Requires:
     - library or section object
     - show name
   - Optional: season number
   - Parameters: first/last
2. Unfinished (episodes that were watched partway through)
   - Requires: show or season object
   - Parameters: first/last
3. Unwatched
   - Requires: show or season object
   - Parameters: first/last
4. Watched
   - Requires: show or season object
   - Parameters: first/last

Each mechanism above can function as a fallback in case the prior mechanism
fails to find a suitable episode. Fallbacks are delimited by a "|".

If all mechanisms fail, the show will start from the beginning.

Mechanisms may also be parameterized to get the 'first' or 'last' element
among the results (e.g. first unwatched, last unfinished). Parameters are
delimited by an "_". Default is 'first'.

Example:

    Let's assume the following complex continuation mechanism is desired:

      Resume show from deck, and if it's missing then
      resume last unfinished episode, and if it's missing then
      resume first unwatched episode, and if it's missing then
      start show from the beginning

    Resultant continuation query:
      ... "_continue": "deck|unfinished_last|unwatched_first" ...

While I was there, I also added support for Plex parameter "continuous": 1 in order to have the show continue playing on from the selected episode.

I’ll update this thread once the code is ready for review. It’s only ~40 lines of code but I don’t know HA style guidelines (using vim, no visual code) and surely there will be nitpicks. Plus I just slapped this sloppy piece together.

Do you review HA code submissions, @jjlawren?

Yep, and thanks for looking into it! Please open a PR and I’d be happy to review.

1 Like

Thanks @jjlawren, I submitted a PR for review. It’s my first one, please be as brutal as necessary :slight_smile:

1 Like

Hi all, I know it’s been a while but does anyone know if this has been integrated? I can’t seem to get it to work :frowning:

1 Like

Hey, did this ever get integrated?