Kodi Community Forum
Solved 'Real' runtime of episode - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Solved 'Real' runtime of episode (/showthread.php?tid=292672)



'Real' runtime of episode - wkia - 2016-09-30

My addon uses JSON-RPC "VideoLibrary.GetEpisodes" method to get episodes for a TV show and then creates a playlist within the given maximum playing time limit. To track the playing time I use the "runtime" field returned by "VideoLibrary.GetEpisodes".

Recently I found that the 'runtime' field has the same value for all the TV show's seasons. OK, it works the same as thetvdb.com does. But the point is that some TV shows have 'Special' episodes, and its lenght is not the same as the standard episode lenght.

So the question is how can I retrieve the 'real' runtime of the episode in my addon?


RE: 'Real' runtime of episode - Roman_V_M - 2016-09-30

I think that there is no other way than to read duration from videofiles. It can be done with ffmpeg but, if I'm not mistaken, Kodi's buit-in ffmpeg is not accessible from Python. Fortunately, there is Hachoir library which is pure-Python (means platform-independent) that can work with a number of binary file formats, including some media formats. It works with great majority of avi/mp4/mkv files and does not work with ts/m2ts. You can see an example of its usage in my YATP plugin.

The only problem I see that scanning many files, especially with Python, will take quite a while. I'd recommend to use some form of caching for known files, for example with a pickled dictionary or a Python shelve that stores "path: duration" pairs.


RE: 'Real' runtime of episode - wkia - 2016-10-01

Thank you for the answer, I will try it))


RE: 'Real' runtime of episode - ronie - 2016-10-01

if i remember correctly, the 'runtime' field contains the scraped (from thetvdb.com etc..) length of a video.

you can also query the 'streamdetails' field, which will return (amongst others) the 'duration' value,
which is the actually length of the video.


'Real' runtime of episode - wkia - 2016-10-03

@ronie thank you, it works! Moreover I see that if I request 'streamdetails' field, the 'runtime' field is updated in accordance with 'streamdetails.duration'.