Auto play next kodi episode to watch

I want to share here my project in development for automating play for next episode to play on kodi.

I’m new to yaml automation and script so bear with me…

So here my start:

First I’ve search for a long time how to do it and almost no pages on web explain all deep ways to communicate with kodi.

My goal:

  • Retreive all kodi shows
    – in order lastWatched
  • Loop For each shows retreive All episodes
    – For each episode ask if it as been seen
  • If all episodes availables as been seen continue on next lastShow watched
  • and so on…
  • If next episode as not been seen, send it to player
    – And pause it

1.Make a Script: retreive all lastWatchedShow

alias: Get Last played TvShows
variables:
  last_played_ids: null
sequence:
  - service: kodi.call_method
    data:
      method: VideoLibrary.GetTVShows
      properties:
        - lastplayed
      sort:
        order: descending
        method: lastplayed
    target:
      entity_id: media_player.qlexmediarpi4
...

2.Then make an Automation to be triggered by this script event and manipulate it data result:

alias: Auto set next show episode
description: >-
  Va permettre de pouvoir automatiquement écouter la prochaine épisode du
  dernier TV show a écouter
trigger:
  - platform: event
    event_type: kodi_call_method_result
    event_data:
      result_ok: true
      input:
        method: VideoLibrary.GetTVShows
condition:
  - condition: template
    value_template: "{{ lastPlayedShowsIDs | length > 0 }}"
action:
  - delay:
      milliseconds: 200
...
  1. Next is to loop throught the showid list received.
    3.1 Request its episodes
    3.1.1 Ordered by episode
    3.1.2 Filtered by playcount = 0
    3.1.3 Limit to 1 result

In openhab I was able with this call:

{"jsonrpc":"2.0",
 "method":"VideoLibrary.GetEpisodes",
 "params":{
   "sort" : {"order" : "ascending", "method" : "episode"},
   "tvshowid": " lastTvShowPlayedId ",
   "filter":{"field":"playcount","operator":"is","value":"0"
   }
 },
 "id":1}

Now I need to transfert kodi_call_method_result in automation event_data back to script variable list and iterate throught it in a loop…
Well I mean getting shows id list and request is kodi show/episodes one after one…

1 Like

I just saw your post.

And I have a script with a similar goal, but different take on it. Mine depends on the fact you’re already playing (or have just finished an episode).
Here’s my, much more basic, script:

alias: "Kodi Next Episode"
sequence:
  - if:
      - condition: state
        entity_id: media_player.kodi
        state: playing
        alias: If Kodi is playing, "Back"
    then:
      - service: kodi.call_method
        data:
          method: Input.Back
        target:
          entity_id: media_player.kodi
        alias: back
  - service: kodi.call_method
    data:
      method: Input.Down
    target:
      entity_id: media_player.kodi
    alias: "\"Down\""
  - service: kodi.call_method
    data:
      method: Input.Select
    target:
      entity_id: media_player.kodi
    alias: "\"Select\""
mode: single
icon: mdi:skip-next

I think it is interesting!
Would be great to be able to fetch recent TV shows, (filter and sort as you’ve done)… to be able to show in HA, or run after you start the media centre…