Kodi Community Forum
"Continue Watching" of TV Shows with JSON-RPC API - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93)
+---- Forum: JSON-RPC (https://forum.kodi.tv/forumdisplay.php?fid=174)
+---- Thread: "Continue Watching" of TV Shows with JSON-RPC API (/showthread.php?tid=378998)



"Continue Watching" of TV Shows with JSON-RPC API - benzhe - 2024-09-30

In Kodi app, there is a pretty nice feature about continue watching a specific tv show. It remember the episode i've watched, and next time when I choose "Continue Watching", it will start playback on next episode.

My question is how can i implement or achieve a feature like this through JSON-RPC API. I've tried some API but with no luck.


RE: "Continue Watching" of TV Shows with JSON-RPC API - Buschel - 2024-10-04

For a given TV Show you could read the playcount for each season. For the first non-played one you read playcount for each episode and continue with the first non-played one.


RE: "Continue Watching" of TV Shows with JSON-RPC API - roidy - 2024-10-05

The json-rpc api already gives you an inprogress end point.

https://kodi.wiki/view/JSON-RPC_API/v13#VideoLibrary.GetInProgressTVShows


RE: "Continue Watching" of TV Shows with JSON-RPC API - Buschel - 2024-10-09

(2024-10-05, 13:34)roidy Wrote: The json-rpc api already gives you an inprogress end point.

https://kodi.wiki/view/JSON-RPC_API/v13#VideoLibrary.GetInProgressTVShows

Maybe I am missing something, but looks like this only returns back the TV Shows which are in progress, how many seasons and episodes are available and how many episodes have been watched. From this you could show the progress, but how do you figure out which is the next episode to continue with?


RE: "Continue Watching" of TV Shows with JSON-RPC API - roidy - 2024-10-09

(2024-10-09, 08:31)Buschel Wrote: Maybe I am missing something, but looks like this only returns back the TV Shows which are in progress, how many seasons and episodes are available and how many episodes have been watched. From this you could show the progress, but how do you figure out which is the next episode to continue with?

Yes it returns a list of TV Shows which are in progress and then as the OP stated in his first post, you simply choose "Continue Watching" from the context menu. Kodi will then play the correct episode.

If you need to know the exact episode that will play then you need to do some extra work, as you said you will need to search through the episodes in the last played TV Show find the episode with the most recent last played date and then play the next one.


RE: "Continue Watching" of TV Shows with JSON-RPC API - Buschel - 2024-10-09

Thanks, I was hoping the method would somehow return back the next episode to play and/or the time position in the current played one.


RE: "Continue Watching" of TV Shows with JSON-RPC API - roidy - 2024-10-09

Once have the list of TV Shows from the "GetInprogressTVShows " endpoint. Just iterate over all of the Shows and using the tvshowid run a json-rpc query using the "GetEpisodes" endpoint and the following params:-

VideoLibrary.GetEpisodes
tvshowid = the id from the show return from "GetInprogressTVShows"
sort = {'order': 'ascending', 'method': 'playcount'}
filter = {'field': 'inprogress', 'operator': 'true', 'value': ''}
limit = 1

This will return one single episode from the show that is either currently inprogress or the next episode to watch, then just assemble all the episodes into a list.


RE: "Continue Watching" of TV Shows with JSON-RPC API - Buschel - 2024-10-09

That‘s clear, thanks👍


RE: "Continue Watching" of TV Shows with JSON-RPC API - MoojMidge - 2024-10-10

(2024-10-09, 17:50)roidy Wrote: This will return one single episode from the show that is either currently inprogress or the next episode to watch, then just assemble all the episodes into a list.

It has been a while since I have looked into it so what follows may no longer be completely accurate, but I don't think this will achieve the intended result.

inprogress for a tvshow is different to inprogress for an episode and you can't really use VideoLibrary.GetInprogressTVShows to replicate what is more commonly done by streaming services/software at an episode level

inprogress for a tvshow is equivalent to watchedcount > 1 AND totalcount != watchedcount. This means that a show where you have partially watched only one episode won't be considered inprogress.

Similarly if the last episode that was watched in a show was fully completed, then using VideoLibrary.GetEpisodes with the tvshowid from VideoLibrary.GetInprogressTVShows and filtering for inprogress won't return any results.

Using VideoLibrary.GetInprogressTVShows then VideoLibrary.GetEpisodes would only really work if you have completely watched at least one episode, and also partially watched another.

The fastest way I have found to get the next or currently in-progress episode is to just stick to VideoLibrary.GetEpisodes - once for inprogress episodes plus a second for watched episodes, then merge the two results sorting by lastplayed and filtering by unique tvshowid and dbid.

If the lastplayed episode for a particular tvshowid does not have a resume point, or has a resume point is too close to the end, then use VideoLibrary.GetEpisodes again to get the next episode.

An example implementation: https://github.com/MoojMidge/service.upnext/blob/5a9a1b4bd544e3a95ed8119f8efbf2dc037c6adb/resources/lib/api.py#L1060


RE: "Continue Watching" of TV Shows with JSON-RPC API - roidy - 2024-10-11

deleted


RE: "Continue Watching" of TV Shows with JSON-RPC API - roidy - 2024-10-11

@MoojMidge Here a complete plugin:-

https://github.com/roidy/script.tinyupnext

This will return next and inprogress episodes using a single json-rpc call to get the list of inprogress tv shows, and then one call on each show to get the correct episode.


RE: "Continue Watching" of TV Shows with JSON-RPC API - MoojMidge - 2024-10-13

There are many ways to do this, and there is no specification to say what is correct or not, so if you are satisfied with the results then that is what matters.

Just pointing out some stuff that I came across previously when looking at the same thing. Personally this current discussion has led to some improvements in how I ended up doing it, with the following comments being an extension of that.

By not filtering for inprogress in the VideoLibrary.GetEpisodes, you will get pretty close to the generally expected result, but as originally described with filtering on inprogress, it would not have worked.

The implementation of videodb://inprogresstvshows/ gets the job done quickly, but it has limitation that make it not useful in a few scenarios, and any implementation that utilises VideoLibrary.GetInprogressTVShows will have the same limitations. There is also another issue that may not be immediately obvious - using VideoLibrary.GetInprogressTVShows and then VideoLibrary.GetEpisodes sorted by playcount implicitly relies on the order that the video database returns results for the episodes from a show, rather than the actual episode order or the watch order.

This means that the results of the VideoLibrary.GetEpisodes calls may or may not actually provide the correct next episode depending on a number of factors, including whether the order in which episodes were added to the video library matches the same order in which you are watching the episodes.

This is on top of the underlying issues with VideoLibrary.GetInprogressTVShows, which combined, can prove problematic if you are skipping episodes or seasons, or watching seasons or episodes out of order, or re-watching a show, or have special episodes in season 0, or have re-added/refreshed/replaced episodes, or simply just originally added episodes out of order in the video library.

You are using X + 1 calls, with X being the number of tvshows returned by VideoLibrary.GetInprogressTVShows. In order to get the next episode without assuming that the order of records from the underlying database query will match your watching order, you need to know the last episode that was played, so rather than X + 1 JSON-RPC calls, you will end up needing 2*X + 1 calls. In order to check tvshows that have previously been watched will require an additional 2*Y + 1 JSON-RPC calls, where Y is the number of watched tvshows returned by VideoLibrary.GetTVShows.

All of this ends up being slower than just using VideoLibrary.GetEpisodes but I guess whether or not these limitation are important to someone will vary depending on how they manage their video library, and also how they actually watch the shows contained in their library.