Guest - Testers are needed for the reworked CDateTime core component. See... https://forum.kodi.tv/showthread.php?tid=378981 (September 29) x
"Continue Watching" of TV Shows with JSON-RPC API
#1
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.
Reply
#2
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.
Reply
#3
The json-rpc api already gives you an inprogress end point.

https://kodi.wiki/view/JSON-RPC_API/v13#...essTVShows
Reply
#4
(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#...essTVShows

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?
Reply
#5
(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.
Reply
#6
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.
Reply
#7
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.
Reply
#8
That‘s clear, thanks👍
Reply
#9
(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.upn...i.py#L1060
Reply
#10
deleted
Reply
#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.
Reply
#12
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.
Reply

Logout Mark Read Team Forum Stats Members Help
"Continue Watching" of TV Shows with JSON-RPC API0