Kodi Community Forum

Full Version: [RELEASE] Random and last items smartplaylist script for Skins
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
You have to name your playlist !!

<name>Genre</name> or <name>Action</name>
(2014-02-03, 12:16)mikebzh44 Wrote: [ -> ]You have to name your playlist !!

<name>Genre</name> or <name>Action</name>

Oh God i knew it was something simple..
I thought playlist file name = playlist name
thanks alot Mike Smile
Hi, I'm having issues getting this addon to function. It returns an error on all my playlists running in Aeon MQ5 on the main menu screen.
Here is the error I'm getting and a playlist example

XBMC 12.3
latest version of your addon.

EDIT: After researching further it appears to be an issue with storing your playlists on an external area. Is there any way to resolve this as I'd like properly synced playlists between all my devices. If not, I understand. Thank you for your time.
New question, so I'm making a separate post.

Are these lists cached? Some of my playlists take a lonnnng time before the recently added shows up (10+ minutes on the larger tv ones containing 6000 episodes).
It doesn't appear to be, as when I restart xbmc the lists are blank as they load again. If it isn't cached is there any way to make the load times on these faster? My movies section, which has about 600 movies, takes roughly a minute to load the recently added.

Another thing I noticed is that my twitch plug in and pseudotv plugin become SUPER sluggish/refuse to open while I have this addon enabled. If I remove this addon those other 2 addons perform normally and do not have problems opening. Is this related to my super slow loading of recent items etc? Here is a full log with the addon enabled and with it disabled. It might be effecting other addons but I did not check. my cpu usage isn't high or anything while the addon is enabled so I'm unsure why it's causing slowdowns


With Random and last on - http://pastebin.com/kyPLzaJB
WIth Random and last off - 1 of 2: http://pastebin.com/P9k0UxxL
2 of 2: http://pastebin.com/G2PmP7TP

some of my 90s tv playlist "random items" listing shows a blank image as below
Image

and then inside the log I see the following. Is this related to your addon or a problem of xbmc?
Code:
12:58:15 T:1276 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fHey%20Arnold%2fHey%20Arnold%20-%20Season%205%2fhey%20arnold!%20-%205x08%20-%20suspended%20%7e%20ernie%20in%20love-thumb.jpg/
12:58:17 T:1276 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fSpider-Man%20The%20Animated%20Series%2fSpider-Man%20TAS%20-%20Season%202%20-%20The%20Neogenic%20Nightmare%2fSpider-Man%20TAS%20-%20S2E07%20-%20Neogenic%20Nightmare%20Chapter%207%20-%20Enter%20The%20Punisher-thumb.jpg/
12:58:18 T:2688 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fHey%20Arnold%2fHey%20Arnold%20-%20Season%205%2fhey%20arnold!%20-%205x08%20-%20suspended%20%7e%20ernie%20in%20love-thumb.jpg/
12:58:19 T:1276 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fSpider-Man%20The%20Animated%20Series%2fSpider-Man%20TAS%20-%20Season%202%20-%20The%20Neogenic%20Nightmare%2fSpider-Man%20TAS%20-%20S2E07%20-%20Neogenic%20Nightmare%20Chapter%207%20-%20Enter%20The%20Punisher-thumb.jpg/
12:58:20 T:2688 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fBill%20Nye%20the%20Science%20Guy%2fBill%20Nye%20The%20Science%20Guy%20S03E05%20Energy-thumb.jpg/
12:58:20 T:2688 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fFreaks%20%26%20Geeks%2fFreaks%20%26%20Geeks%20-%20S01E16%20(Smooching%20%26%20Mooching)-thumb.jpg/
12:58:20 T:2688 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fFreakazoid%2fFreakazoid%20-%202x08%20-%20Island%20of%20Dr.%20Mystico-thumb.jpg/
12:58:21 T:2688 WARNING: XFILE::CDirectoryFactory::Create - Unsupported protocol(image) in image://smb%3a%2f%2fFileserver-pc%2fh%2f90%27s%2fJohnny%20Bravo%2fSeason%202%2fJohnny%20Bravo%20-%202x26%20-%20Alien%20Confidential-thumb.jpg/
(2014-02-09, 23:04)Quiksmage Wrote: [ -> ]New question, so I'm making a separate post.

Are these lists cached? Some of my playlists take a lonnnng time before the recently added shows up (10+ minutes on the larger tv ones containing 6000 episodes).
It doesn't appear to be, as when I restart xbmc the lists are blank as they load again. If it isn't cached is there any way to make the load times on these faster? My movies section, which has about 600 movies, takes roughly a minute to load the recently added.

Same thing happened to me, i have like 10000 movies, it's rather slow to load, like almost 5 minutes...
And now i have around 30 genre based playlists, so i hope it could be faster..
it'd be great if it's cached Mike Smile
Sorry but as the script return statistics about playlists (total number of items, number of item viewed and unviewed), I have to go through the entire playlist to calculate them.

So with huge library like yours, it take a loooooong time Sad
(2014-02-11, 12:18)mikebzh44 Wrote: [ -> ]Sorry but as the script return statistics about playlists (total number of items, number of item viewed and unviewed), I have to go through the entire playlist to calculate them.

So with huge library like yours, it take a loooooong time Sad

CMIIW. So one of the factors that slows down the script is the viewed / unviewed scan?
I dont think its needed for my case..
Is there anyway to disable it? Which part of the code is related to this?
Anything else can be done to optimize it?
I only need it to display random and latest movies based on path, genres, and ratings
Ok, i'm gonna try mod this script to speed it up,
I'm gonna try removing the Watched and unwatched codes

Got a question, what does this code do?

Code:
def _timeTook( t ):
    t = ( time.time() - t )
    if t >= 60: return "%.3fm" % ( t / 60.0 )
    return "%.3fs" % ( t )

Ok, this speeds up the script considerably,
because i don't use watched property




I tried to remove watched/unwatched codes for episodes but it didn't work
It seems to force it as a requirement for episodes
Function _timeTook is for calculating script running time. So nothing to do with watched / unwatched.

For example, look at _getMovies function. line 105, we use Files.GetDirectories function with playlist (xsp file) as argument to retrieve movies from the playlist.
And you can compare this function to _fetch_movies from service.skin.widget.

In service.skin.widget, line 165, JSON query can be reduce because you only need to get LIMIT latest movies ("limits": {"end": %d}), as statistics for standard library (Total number of movies, Number of movies watched, unwatched) are given by XBMC.

But for my script, I cannot use "limits": {"end": %d} because even if you just want the last 10 movies from your playlist, I have to submit query on the entire smart playlist in order to calculate how many movies you get, how many movies are watched / unwatched. By puting "limits": {"end": %d} in JSON query, your statistics will be wrong as the total number of movies will be equal to 10 (depend on skin parameter).

So, if you want to speed up the script you have to look at service.skin.widget function and add limits to JSON queries.

@Martijn : Does this script can be replace by this new feature from Gotham :

http://forum.xbmc.org/showthread.php?tid...pid1612262

http://forum.xbmc.org/showthread.php?tid=176864

Sorry but I don't understand very well BigNoid answer and I don't know if this script won't be required any more for populating widgets in Gotham.

Thanks.
(2014-02-11, 16:50)mikebzh44 Wrote: [ -> ]Function _timeTook is for calculating script running time. So nothing to do with watched / unwatched.

For example, look at _getMovies function. line 105, we use Files.GetDirectories function with playlist (xsp file) as argument to retrieve movies from the playlist.
And you can compare this function to _fetch_movies from service.skin.widget.

In service.skin.widget, line 165, JSON query can be reduce because you only need to get LIMIT latest movies ("limits": {"end": %d}), as statistics for standard library (Total number of movies, Number of movies watched, unwatched) are given by XBMC.

But for my script, I cannot use "limits": {"end": %d} because even if you just want the last 10 movies from your playlist, I have to submit query on the entire smart playlist in order to calculate how many movies you get, how many movies are watched / unwatched. By puting "limits": {"end": %d} in JSON query, your statistics will be wrong as the total number of movies will be equal to 10 (depend on skin parameter).

So, if you want to speed up the script you have to look at service.skin.widget function and add limits to JSON queries.

@Martijn : Does this script can be replace by this new feature from Gotham :

http://forum.xbmc.org/showthread.php?tid...pid1612262

http://forum.xbmc.org/showthread.php?tid=176864

Sorry but I don't understand very well BigNoid answer and I don't know if this script won't be required any more for populating widgets in Gotham.

Thanks.

Hmm.. So you're saying i should use skin widgets..
I read skin widgets wiki and kinda confused,
Can i use it the same way as your script?
With your script i can create Latest Action Movie, High Rated Sci-fi movies, etc

I use Ace skin, and i need to populate the main screen with those..
Ace's thread says it supports skin widgets, so does that mean it's already implemented?

Looks like Ace is still using your script

https://github.com/CutSickAss/skin.ace.v...p/Home.xml


So... if i want to change the method to skin widgets,
does that mean i'm gonna have to rewrite the majority of Ace's code? Confused
No, I'm not saying that you should use skin widgets. Skin widget is for default library, not for smart playlists.

I just say that if you want to speed up THIS script with YOUR HUGE library, you have to add limits in JSON query the way Martijn did in skin widget function but your statistics will be wrong because Ace use limit=12 parameter. So every custom menu based on smart playlist will display a total of 12 movies, even if your smart playlist contains hundreds of movies.
(2014-02-11, 17:32)mikebzh44 Wrote: [ -> ]No, I'm not saying that you should use skin widgets. Skin widget is for default library, not for smart playlists.

I just say that if you want to speed up THIS script with YOUR HUGE library, you have to add limits in JSON query the way Martijn did in skin widget function but your statistics will be wrong because Ace use limit=12 parameter. So every custom menu based on smart playlist will display a total of 12 movies, even if your smart playlist contains hundreds of movies.

I see, sorry i'm not familiar with python :p
So let me try to understand it here..

- Use this script, ok
- "add limits in JSON query" -- > Where exactly must this be done?

On skin level (e.g xml files) or your script?

You said line 165 on skin widgets..

you're reffering to this part right?

Code:
def _fetch_movies(self, request):
        if not xbmc.abortRequested:
            json_string = '{"jsonrpc": "2.0",  "id": 1, "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "originaltitle", "playcount", "year", "genre", "studio", "country", "tagline", "plot", "runtime", "file", "plotoutline", "lastplayed", "trailer", "rating", "resume", "art", "streamdetails", "mpaa", "director"], "limits": {"end": %d},' %self.LIMIT
            if request == 'RecommendedMovie':
                json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "lastplayed"}, "filter": {"field": "inprogress", "operator": "true", "value": ""}}}' %json_string)
            elif request == 'RecentMovie' and self.RECENTITEMS_UNPLAYED:
                json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}, "filter": {"field": "playcount", "operator": "is", "value": "0"}}}' %json_string)
            elif request == 'RecentMovie':
                json_query = xbmc.executeJSONRPC('%s "sort": {"order": "descending", "method": "dateadded"}}}' %json_string)
            elif request == "RandomMovie" and self.RANDOMITEMS_UNPLAYED:
                json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" }, "filter": {"field": "playcount", "operator": "lessthan", "value": "1"}}}' %json_string)
            else:
                json_query = xbmc.executeJSONRPC('%s "sort": {"method": "random" } }}' %json_string)
            json_query = unicode(json_query, 'utf-8', errors='ignore')
            json_query = simplejson.loads(json_query)
            if json_query.has_key('result') and json_query['result'].has_key('movies'):
                self._clear_properties(request)
                count = 0
                for item in json_query['result']['movies']:
                    count += 1
                    if (item['resume']['position'] and item['resume']['total'])> 0:
                        resume = "true"
                        played = '%s%%'%int((float(item['resume']['position']) / float(item['resume']['total'])) * 100)
                    else:
                        resume = "false"
                        played = '0%'
                    if item['playcount'] >= 1:
                        watched = "true"
                    else:
                        watched = "false"
                    if not self.PLOT_ENABLE and watched == "false":
                        plot = __localize__(32014)
                    else:
                        plot = item['plot']
                    art = item['art']
                    path = media_path(item['file'])
                    play = 'XBMC.RunScript(' + __addonid__ + ',movieid=' + str(item.get('movieid')) + ')'
                    streaminfo = media_streamdetails(item['file'].encode('utf-8').lower(),
                                               item['streamdetails'])
                    self.WINDOW.setProperty("%s.%d.DBID"           % (request, count), str(item.get('movieid')))
                    self.WINDOW.setProperty("%s.%d.Title"           % (request, count), item['title'])
                    self.WINDOW.setProperty("%s.%d.OriginalTitle"   % (request, count), item['originaltitle'])
                    self.WINDOW.setProperty("%s.%d.Year"            % (request, count), str(item['year']))
                    self.WINDOW.setProperty("%s.%d.Genre"           % (request, count), " / ".join(item['genre']))
                    self.WINDOW.setProperty("%s.%d.Studio"          % (request, count), item['studio'][0])
                    self.WINDOW.setProperty("%s.%d.Country"          % (request, count), item['country'][0])
                    self.WINDOW.setProperty("%s.%d.Plot"            % (request, count), plot)
                    self.WINDOW.setProperty("%s.%d.PlotOutline"     % (request, count), item['plotoutline'])
                    self.WINDOW.setProperty("%s.%d.Tagline"         % (request, count), item['tagline'])
                    self.WINDOW.setProperty("%s.%d.Runtime"         % (request, count), str(int((item['runtime'] / 60) + 0.5)))
                    self.WINDOW.setProperty("%s.%d.Rating"          % (request, count), str(round(float(item['rating']),1)))
                    self.WINDOW.setProperty("%s.%d.mpaa"            % (request, count), item['mpaa'])
                    self.WINDOW.setProperty("%s.%d.Director"        % (request, count), " / ".join(item['director']))
                    self.WINDOW.setProperty("%s.%d.Trailer"         % (request, count), item['trailer'])
                    self.WINDOW.setProperty("%s.%d.Art(poster)"     % (request, count), art.get('poster',''))
                    self.WINDOW.setProperty("%s.%d.Art(fanart)"     % (request, count), art.get('fanart',''))
                    self.WINDOW.setProperty("%s.%d.Art(clearlogo)"  % (request, count), art.get('clearlogo',''))
                    self.WINDOW.setProperty("%s.%d.Art(clearart)"   % (request, count), art.get('clearart',''))
                    self.WINDOW.setProperty("%s.%d.Art(landscape)"  % (request, count), art.get('landscape',''))
                    self.WINDOW.setProperty("%s.%d.Art(banner)"     % (request, count), art.get('banner',''))
                    self.WINDOW.setProperty("%s.%d.Art(discart)"    % (request, count), art.get('discart',''))                
                    self.WINDOW.setProperty("%s.%d.Resume"          % (request, count), resume)
                    self.WINDOW.setProperty("%s.%d.PercentPlayed"   % (request, count), played)
                    self.WINDOW.setProperty("%s.%d.Watched"         % (request, count), watched)
                    self.WINDOW.setProperty("%s.%d.File"            % (request, count), item['file'])
                    self.WINDOW.setProperty("%s.%d.Path"            % (request, count), path)
                    self.WINDOW.setProperty("%s.%d.Play"            % (request, count), play)
                    self.WINDOW.setProperty("%s.%d.VideoCodec"      % (request, count), streaminfo['videocodec'])
                    self.WINDOW.setProperty("%s.%d.VideoResolution" % (request, count), streaminfo['videoresolution'])
                    self.WINDOW.setProperty("%s.%d.VideoAspect"     % (request, count), streaminfo['videoaspect'])
                    self.WINDOW.setProperty("%s.%d.AudioCodec"      % (request, count), streaminfo['audiocodec'])
                    self.WINDOW.setProperty("%s.%d.AudioChannels"   % (request, count), str(streaminfo['audiochannels']))
            del json_query
json_string = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.GetMovies", "params": {"properties": ["title", "originaltitle", "playcount", "year", "genre", "studio", "country", "tagline", "plot", "runtime", "file", "plotoutline", "lastplayed", "trailer", "rating", "resume", "art", "streamdetails", "mpaa", "director"], "limits": {"end": %d},' %self.LIMIT
Like this? I got indentantion error though...
Sorry but I don't have time to explain all the modifications you have to make.

So, you have to learn about python, look the differences between this script and skin widgets, read JSON wiki or use this script "has is".

Sorry.