Posts: 3
Joined: Sep 2024
Reputation:
0
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.
Posts: 1,542
Joined: Mar 2018
Reputation:
34
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.
Posts: 1,542
Joined: Mar 2018
Reputation:
34
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.
Posts: 800
Joined: Aug 2009
Reputation:
187
roidy
Posting Freak
Posts: 800
2024-10-09, 17:50
(This post was last modified: 2024-10-09, 17:53 by roidy. Edited 1 time in total.)
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.
Posts: 109
Joined: Mar 2024
Reputation:
33
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.
Posts: 3
Joined: Sep 2024
Reputation:
0
Apologies for such a late reply, as well as many thanks for the discussion.
Shortly after the post, I found a workable solution on my own. It probably goes something like this:
---
STEP 1: wakeupTV();
STEP 2: kodi.send('Player.Stop', [1]);
STEP 3: kodi.send('GUI.ActivateWindow', ["busydialognocancel"]);
STEP 4: kodi.send('Playlist.Clear', [1]);
STEP 5: kodi.send('Playlist.Add', [1, {directory: tvshow.folder, media: 'video', recursive: true}]);
STEP 6: kodi.send('Playlist.GetItems', {playlistid: 1, "properties": ["title", "file","playcount"]});
STEP 7: findNextEpisodeIndex (currentItem.playcount < prevItem.playcount)
STEP 8: kodi.send('Input.ExecuteAction', ['close']); // maybe has a another better method to close the busydialog
STEP 9: kodi.send('Player.Open', {"item": {"position": nextEpisodeIndex, "playlistid": 1}});
---
The issue with this solution is that it takes a long time between STEP 5 and 9 due to the high number of episodes for some of the tvshows (folders), so I add a busy loader in step 3 and close it in STEP 8 after Kodi had finished processing the playlist.
I tried ways to solve this loading issue, but came up unsuccessful and had to keep the above solution.
> For now I just tell Kodi to play a directory of files as an tvshow series because the file structure on the hard drive is inconsistent for each show, and I haven't had enough time to try to build up all TVShows in Kodi. I will try it later with VideoLibrary.GetInProgressTVShows.
Posts: 3
Joined: Sep 2024
Reputation:
0
For more context: I'm setting up a NFC card to cartoon shows system for my child. Every time she selects an cartoon series card and tap it, the system will wake up the TV and play the cartoon show, which can start from the next episode that last ended up playing.