Thursday, March 31, 2016

Another Tweak to the Trakt.tv Add-On for Kodi

My additions to the Trakt.tv add-on for Kodi have been working fairly well, but every once in while it'll still have issues. I decided to tackle one of those issues - the problem of common episode titles.
To quickly recap, the idea here is to watch TV shows that are recorded on my MythTV DVR via Kodi on my Fire TV, and to have Trakt.tv automatically update what I've watched. All the pieces already exist to make this happen, but they don't quite fit together. Specifically, the information that the Trakt.tv add-on requires (show ID, season number, episode number) isn't available from Kodi when I'm watching a MythTV DVR recording. All that Kodi knows is the show name and episode title.

I got around this problem by using the Trakt.tv web API to search for the episode title. It often returns more than one result, so I verify it by matching the result's show name (to the show name that Kodi provides). If they match, I tell Trakt.tv that we've got the right episode. But what if I get back a bunch of results from that search, but none of them match the show name? That's the problem of common episode titles - lots of shows use the same episode titles, and so a simple search for that title won't always get the right result.

An alternative approach to find the right episode is to search first for the show, then go through all the episodes of that show until I find the right one. The Trakt.tv web API is capable of this, but there's no efficient way to do it. You've got to make a whole lot of API calls: use the show name to get the show ID; look up the first episode; if that doesn't match, get the next episode; repeat until you find the right one. Horribly inefficient and slow, which is why I didn't use this method in the first place. But it does work even if the episode title is a very common one, used by dozens of TV shows.

So now the modified Trakt.tv add-on code has both options. It tries the episode title search first. If that works, we're done...no need for anything further. But if it doesn't work, then it tries to look up the show by name. If that's found, then it loops through every episode of that show until finding the right one. This way, the least efficient option is used only if the more efficient choice doesn't work.

Ideally, a future version of Kodi or Trakt.tv will make this whole thing unnecessary. If Kodi and/or the MythTV add-on can provide the season and episode number, then there will be no need to use the episode title at all. Or if the Trakt.tv web API had a method that can search on both show name and episode title, instead of just one or the other, then common episode titles won't be an issue. Until one or the other changes, I'm stuck with the inefficient method...but it does work.

No comments:

Post a Comment