Kodi Community Forum

Full Version: Smart(ish) Widgets - widgets with a built-in recommendation engine
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5

removed151214

To be absolutely clear, these widgets are very much to be considered a WIP, and a relatively early one at that. I'm hopeful that those skinners currently working on updates to their skin might consent to helping test their integration, and provide them as an optional extra to users that may be able to test them further, but they are currently a long way from being production-ready.

Currently, the widgets that Kodi provides are dumb. They provide random items, or simple recommendations based on the next available episode. But they don't actually take into account users habits, or similar media in the users library that they may be interested in playing instead. Smart(ish) widgets are an attempt to bring widgets more up to date: the idea is to try to recommend what media the user is most likely to want to play at any given time.

https://github.com/unfledged/service.smartish.widgets

They include a simple content-based recommendation system, with results being based on time. So, for example, if your Kodi box is used to play children tv shows after school, that is the content that is shown in the episodes widget at that time. If you watch action movies to relax on a weekend, the content of the movies widgets reflects this at that time.

The script contains four widgets - Movies, Episodes, Albums, PVR. They currently all use the Gotham list-filling method (though the nature of the widgets mean I am able, and intent to, add window properties - ala skin widgets - in the future). Usage is simple:

First of all, you need to set a skin boolean to indicate that your skin uses these widgets. Without this, the widgets won't update (though they will continue to save details of habits). For example, in home.xml:

Code:
<onload>Skin.SetBool(enable.smartish.widgets)</onload>

Then set the content of the list you want the widgets to appear in:

Code:
<content>plugin://service.smartish.widgets?type=movies&amp;reload=$INFO[Window.Property(smartish.movies)]</content>
<content>plugin://service.smartish.widgets?type=episodes&amp;reload=$INFO[Window.Property(smartish.episodes)]</content>
<content>plugin://service.smartish.widgets?type=albums&amp;reload=$INFO[Window.Property(smartish.albums)]</content>
<content>plugin://service.smartish.widgets?type=pvr&amp;reload=$INFO[Window.Property(smartish.pvr)]</content>

The list properties returned are identical to that of service.library.data.provider, with the exception of the PVR widget. This can return 2 types of items within the one widget - channels and recorded content. Channels have the additional list item properties StartTime, EndTime, NextStartTime, NextEndTime, NextTitle, NextGenre, NextPlot. Recorded has ChannelName, StartTime, EndTime. The 'type' property is set to 'livechannel' or 'recorded' as appropriate.

Feedback is particularly welcomed on skin integration. If you decide to make these available to any beta-testing users, their feedback is welcomed on any major inaccuracies the widget returns (though these are 'learning' widgets, and take time to learn properly, so a week or twos usage is suggested before complaining Wink)

They can also optionally get additional information on your movies and tv shows from the Movie DB to improve recommendations (has to be enabled in the scripts settings, and will majorly delay the next update of the relevant widgets whilst this information - 'keywords' and 'similar' - is retrieved.) I'm required to include the following text for using their api Wink:

"This product uses the TMDb API but is not endorsed or certified by TMDb."

Thanks in advance for any and all feedback on this idea Smile

Known Issues

* On startup, pretty much your entire video collection has to be scanned to find relevant results, so widgets will take some time to initially load. Updates of the widgets require a much smaller amount of your library to be scanned (and in future, will require even less)
* Generating the widgets takes processing power. Though I have been using these widgets on a Raspberry Pi for some time, some may not find the impact on performance of low-powered devices such as this acceptable
* The widgets use sockets to speed up the listing of widgets. There are situations where the script may fail to bind to the relevant socket. Restarting Kodi will normally fix this issue. A script error (a possibility at this stage of development!) will close the socket, stopping the widgets updating.

FAQ

A number of people have tried this script in various even-earlier incarnations - and my huge thanks to those who have tested, or even just given their early opinions on this idea - and a few questions have come up repeatedly:

* Can this script recommend media not in my library that I may enjoy: No, this script is designed to only display results from within your library.
* Can this script get additional recommendations from external sites like TMDb/Trakt/etc: The sorts of lists these sites provide (a list of titles) don't fit well with the type of recommendation system the script uses. Related from TMDb can be (optionally) got, but are weighted very low for this reason, and I won't be adding recommendations from other sites.
* Will this script be integrated with existing widgets (service.library.data.provider/service.skin.widgets): Possible, with the consent of BigNoid and Martijn, and only when the widgets are ready for public release + repo push. Due to the nature of the widgets (which are written from quite a different development perspective from the existing widget scripts), it will likely involve the relevant widget script being integrated with Smart(Ish) Widgets + this script being renamed, not these widgets being directly integrated into an existing script. And, as the script is designed to (eventually) return both Gotham-Style list-filling (ala library data provider) and window properties (ala skin widgets), would likely deprecate the script it was not integrated with
* When will these widgets be finished: Potentially never, it's quite possible that they can't return results relevant for a large enough percentage of users - in which case, they'll never be pushed to the repo. In most likelyhood, when I'm convinced that they are working well enough for a large enough percentage of users to be a useful script to be on the repo. (And all development issues are solved)
* What personal information is recorded/shared: Only information ABOUT the media you have watched (genre, actors, etc) is saved, not the specific item that you have watched. This information is only ever stored locally, and is never shared (though I may ask for a copy of the database when you complain about the results Tongue)
Just added it for users to try out because the pre-alpha character of this add-on perfectly suits my skin Wink
Thx, it´s a nice option to have as a widget.
Small question: Why no GitHub? Smile

removed151214

(OP updated with github link)

Thanks for trying it out, I look forward to the feedback Smile

As someone who contributed more than he probably realises (and I'll call out those who have contributed in whatever fashion as and when they post to this thread because - and I apologise - I genuinely can't remember everyone (and don't want to accidentally miss someone out), and at least one asked not to be called out individually), let me personally thank you:

Thanks for your early input into the skin integration - the PVR integration is directly based on your feedback.
Thanks for your own related items code in - I want to say - your extended info script, which gave me confidence that I was on the right track whilst programming this.
Thanks for your code to get additional info from tMDB, which I basically copied when writing the code to get the additional properties.
I always planned something like this but never got around to it (viewing based behaviour)
So thanks. This should make a lot of people happy Smile

little note: make the .py files you call from addon.xml as small as possible. Kodi will recompile them each time when starting. All others should stay compiled as they were. So make tiny default.py and service.py and load power platforms would be much happier. From those files you can call the other .py files which don't need to be recompiled if not changed (this was mentioned by some one a while ago)
perhaps also integrate trakt.tv into it as some store their watching behaviour there and not on TMDb.

removed151214

(2014-12-07, 15:43)Martijn Wrote: [ -> ]I always planned something like this but never got around to it (viewing based behaviour)
So thanks. This should make a lot of people happy Smile

little note: make the .py files you call from addon.xml as small as possible. Kodi will recompile them each time when starting. All others should stay compiled as they were. So make tiny default.py and service.py and load power platforms would be much happier. From those files you can call the other .py files which don't need to be recompiled if not changed (this was mentioned by some one a while ago)

Good tip. The widget script is already very light as it just passes the request to the service, but the service script can definitely benefit from this.

(2014-12-07, 17:27)Martijn Wrote: [ -> ]perhaps also integrate trakt.tv into it as some store their watching behaviour there and not on TMDb.

TMDb is just used to get additional information about the media in your library that the widgets can then use to weight items, not for actually getting details of the users habits, but trakt could potentially be used to generate history when first using the script rather than starting from no information. I'll look into the API and see what can be done.
TMDb also has "watched" status for users. So also potential for watching habbits. It's part of their API
Perhaps additional idea is that the service watches for a flag set by the skin before it performs background tasks. This prevents it from being run constantly when user switches away from the skin that uses it. If flag not set just keep service running on idle
Wish i had that added to Skin widgets back then.

removed151214

Thanks, I'll look into that part of TMDb API too.

Yes, some way of disabling the background updating is definitely needed. A simple skin flag is a good idea - my thinking was to actually try and keep track in the service of whether the widgets are being requested, but I hadn't yet got my head around how to prevent too many false-positives.

Edit - now added this. Skins need the boolean "enable.smartish.widgets" set in order for the widgets to update.

It's also worth noting that the amount of background loading the script does WILL reduce considerably (along with its memory usage) - at the moment the script doesn't take into account whether the widgets need to be updated (the data being returned from the scripts database has changed, the library has been updated, etc). I'm very aware there are lots of optimisations I still need to work on Wink
Hi, This looks like an awesome addon, great work Smile

I am however getting the following error on the RC1 OpenElec version of Kodi:

23:36:06 T:139694574171904 ERROR: Traceback (most recent call last):
23:36:06 T:139694574171904 ERROR: File "/storage/.kodi/addons/service.smartish.widgets/service.py", line 579, in <module>
23:36:06 T:139694574171904 ERROR: Main()
23:36:06 T:139694574171904 ERROR: File "/storage/.kodi/addons/service.smartish.widgets/service.py", line 77, in __init__
23:36:06 T:139694574171904 ERROR: self._daemon()
23:36:06 T:139694574171904 ERROR: File "/storage/.kodi/addons/service.smartish.widgets/service.py", line 202, in _daemon
23:36:06 T:139694574171904 ERROR: weighted, items = library.getMedia( nextWidget, habits, freshness )
23:36:06 T:139694574171904 ERROR: File "/storage/.kodi/addons/service.smartish.widgets/resources/lib/library.py", line 102, in getMedia
23:36:06 T:139694574171904 ERROR: processMovie( habits, items, weighted, item, freshness )
23:36:06 T:139694574171904 ERROR: File "/storage/.kodi/addons/service.smartish.widgets/resources/lib/library.py", line 437, in processMovie
23:36:06 T:139694574171904 ERROR: dateadded = datetime.now() - datetime.strptime( item[ "dateadded" ], "%Y-%m-%d %H:%M:%S" )
23:36:06 T:139694574171904 ERROR: ImportError: Failed to import _strptime because the import lockis held by another thread.

Hopefully you have an idea what's going on as it's a confusing one, thanks.

removed151214

It is a confusing one - having read up on this error on t'internet the suggestion is its a Python problem/bug with multiple-threaded scripts (this script uses three threads). I implemented the suggested workaround I found out there (which is to use strptime before launching any additional threads) and whilst it has improved matters - you should have seen how often I got this error in the early days of development! - it still comes up occasionally.

I have a couple of ideas for fixing it permanently, though because its not an error that is easily reproducible it will take a little time not just to implement them, but to check that they work. However, my experience is that, more often than not, the issue won't occur next time you restart Kodi. (Though if you are getting this error every time, please do say, and I'll prioritise getting a permanent fix in!)
Unfortunately I am getting it every time on startup and this is with two different test machines. Could it be related to the fact I only have 1 movie in my Kodi Library? (I use MediaBrowser) my goal here is to use the PVR widgets.

Edit

After doing some googling I managed to get it to work consistently for me by adding the following import to service.py

import _strptime

Hopefully you can include it in this version if it causes no problems for you. Cheers.

removed151214

I'll test it locally, and push it this evening if it works as well here. Thanks for the tip Smile

Edit: Now on git. And cheers, ronie - I've bookmarked that page for future reference.
in case you need even more suggestions, there are a few workarounds mentioned in this thread:
http://forum.kodi.tv/showthread.php?tid=112916
Hi Unfledged,
Thanks again for your amazing work. Like discussed before I really see potential in this addon.
I'll integrate the support in my skin so maybe we can get a few more users to test this.
Is there any integration done with skinshortcuts script ?
What I'm thinking about is that a user can select these widgets in the widget selector if they have this addon available...

EDIT: I tried using conditional checks for the addon in the widget selector, but that doesnt seem to work:

PHP Code:
<widget label="smart widget movies" condition="System.HasAddon(service.smartish.widgets)">smart-movies</widget>
<
widget label="smart widget episodes" condition="System.HasAddon(service.smartish.widgets)">smart-episodes</widget>
<
widget label="smart widget albums" condition="System.HasAddon(service.smartish.widgets)">smart-albums</widget>
<
widget label="smart widget pvr" condition="System.HasAddon(service.smartish.widgets)">smart-pvr</widget
Pages: 1 2 3 4 5