The branch, eden-pre has been updated
via c54222347ac58fc5fb8cef4fbf878de94a83a163 (commit)
from d2cf567e4d89e18c0e5940b6e73cd0fc9ff3a078 (commit)
- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=c54222347ac58fc5fb8cef4fbf878de94a83a163
commit c54222347ac58fc5fb8cef4fbf878de94a83a163
Author: amet <[email protected]>
Date: Wed Jul 20 14:33:20 2011 +0200
[script.randomitems] - v 3.0.2:
- fixed fetching random albums
v 3.0.1:
- fixed error when trying to fetch info for installed addons only available
in the dharma repo
v 3.0.0:
- rewrote script to use json-rpc
diff --git a/script.randomitems/README.txt b/script.randomitems/README.txt
index f3060bc..39b5f56 100644
--- a/script.randomitems/README.txt
+++ b/script.randomitems/README.txt
@@ -1,19 +1,19 @@
-Parameters (separated by [B]&[/B]) -
+Parameters (separated by & ):
limit=# ; # to limit returned results (default=5)
-albums=True ; True to return albums instead of songs (default=False)
-unplayed=True ; True to return only items that have not been played
(default=False)
-trailer=True ; True to play the trailer (if available) (default=False)
+unplayed=True ; True to return only items (not supported for albums) that
have not been played (default=False)
+trailer=True ; True to play the trailer (if available) (default=False)
alarm=# ; # number of minutes before running again (default=Off)
-For example -
+
+For example:
-XBMC.RunScript(script.randomitems,limit=10&albums=False&unplayed=True&alarm=30)
+XBMC.RunScript(script.randomitems,limit=10&unplayed=True&alarm=30)
-will return 10 random, unplayed movies, episodes, songs and addons every 30
minutes.
+will return 10 random, unplayed movies, episodes, albums, songs and addons
every 30 minutes.
-Labels -
+Labels:
"RandomMovie.%d.Title"
"RandomMovie.%d.Rating"
@@ -23,6 +23,7 @@ Labels -
"RandomMovie.%d.Trailer"
"RandomMovie.%d.Fanart"
"RandomMovie.%d.Thumb"
+"RandomMovie.Count"
"RandomEpisode.%d.ShowTitle"
"RandomEpisode.%d.EpisodeTitle"
@@ -33,15 +34,26 @@ Labels -
"RandomEpisode.%d.Path"
"RandomEpisode.%d.Fanart"
"RandomEpisode.%d.Thumb"
+"RandomEpisode.Count"
+
+"RandomAlbum.%d.Title"
+"RandomAlbum.%d.Year"
+"RandomAlbum.%d.Artist"
+"RandomAlbum.%d.Path"
+"RandomAlbum.%d.Fanart"
+"RandomAlbum.%d.Thumb"
+"RandomAlbum.%d.Rating"
+"RandomAlbum.Count"
-"RandomSong.%d.Title" <!-- Returns the Song name when albums=False or Returns
the Album name when albums=True -->
+"RandomSong.%d.Title"
"RandomSong.%d.Year"
"RandomSong.%d.Artist"
-"RandomSong.%d.Album" <!-- Not used when albums=True so can be used as a
visible condition for knowing what mode the script is in -->
+"RandomSong.%d.Album"
"RandomSong.%d.Path"
"RandomSong.%d.Fanart"
"RandomSong.%d.Thumb"
"RandomSong.%d.Rating"
+"RandomSong.Count"
"RandomAddon.%d.Name"
"RandomAddon.%d.Author"
@@ -50,9 +62,9 @@ Labels -
"RandomAddon.%d.Path"
"RandomAddon.%d.Fanart"
"RandomAddon.%d.Thumb"
-"Addons.Count"
+"RandomAddon.Count"
-For more inforamtion and help please check -
+For more inforamtion and help please check:
http://forum.xbmc.org/showthread.php?t=55907
diff --git a/script.randomitems/RandomItems.py
b/script.randomitems/RandomItems.py
index 5aa1bdc..2bcd74f 100644
--- a/script.randomitems/RandomItems.py
+++ b/script.randomitems/RandomItems.py
@@ -1,21 +1,3 @@
-# * This Program is free software; you can redistribute it and/or modify
-# * it under the terms of the GNU General Public License as published by
-# * the Free Software Foundation; either version 2, or (at your option)
-# * any later version.
-# *
-# * This Program is distributed in the hope that it will be useful,
-# * but WITHOUT ANY WARRANTY; without even the implied warranty of
-# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# * GNU General Public License for more details.
-# *
-# * You should have received a copy of the GNU General Public License
-# * along with XBMC; see the file COPYING. If not, write to
-# * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-# * http://www.gnu.org/copyleft/gpl.html
-# *
-# * For more information on it's use please check -
-# * http://forum.xbmc.org/showthread.php?t=79378
-# *
# * Thanks to:
# *
# * Nuka for the original RecentlyAdded.py on which this is based
@@ -25,10 +7,8 @@
import xbmc, xbmcgui, xbmcaddon
import re, sys, os, random
import xml.dom.minidom
-from urllib import quote_plus, unquote_plus
-
-__cwd__ = xbmcaddon.Addon().getAddonInfo('path')
+__scriptID__ = "script.randomitems"
class Main:
# grab the home window
@@ -36,28 +16,18 @@ class Main:
def _clear_properties( self ):
# reset totals property for visible condition
- self.WINDOW.clearProperty( "Addons.Count" )
- # we enumerate thru and clear individual properties in case other
scripts set window properties
+ self.WINDOW.clearProperty( "RandomMovie.Count" )
+ self.WINDOW.clearProperty( "RandomEpisode.Count" )
+ self.WINDOW.clearProperty( "RandomSong.Count" )
+ self.WINDOW.clearProperty( "RandomAlbum.Count" )
+ self.WINDOW.clearProperty( "RandomAddon.Count" )
+ # we clear title for visible condition
for count in range( self.LIMIT ):
- # we clear title for visible condition
- self.WINDOW.clearProperty( "RandomMovie.%d.Title" % ( count + 1, )
)
- self.WINDOW.clearProperty( "RandomEpisode.%d.ShowTitle" % ( count
+ 1, ) )
- self.WINDOW.clearProperty( "RandomSong.%d.Title" % ( count + 1, ) )
- self.WINDOW.clearProperty( "RandomSong.%d.Album" % ( count + 1, ) )
- self.WINDOW.clearProperty( "RandomAddon.%d.Name" % ( count + 1, ) )
-
- def _get_media( self, path, file ):
- # set default values
- play_path = fanart_path = thumb_path = path + file
- # we handle stack:// media special
- if ( file.startswith( "stack://" ) ):
- play_path = fanart_path = file
- thumb_path = file[ 8 : ].split( " , " )[ 0 ]
- # we handle rar:// and zip:// media special
- if ( file.startswith( "rar://" ) or file.startswith( "zip://" ) ):
- play_path = fanart_path = thumb_path = file
- # return media info
- return xbmc.getCacheThumbName( thumb_path ), xbmc.getCacheThumbName(
fanart_path ), play_path
+ self.WINDOW.clearProperty( "RandomMovie.%d.Title" % ( count ) )
+ self.WINDOW.clearProperty( "RandomEpisode.%d.Title" % ( count ) )
+ self.WINDOW.clearProperty( "RandomSong.%d.Title" % ( count ) )
+ self.WINDOW.clearProperty( "RandomAlbum.%d.Title" % ( count ) )
+ self.WINDOW.clearProperty( "RandomAddon.%d.Name" % ( count ) )
def _parse_argv( self ):
try:
@@ -68,29 +38,22 @@ class Main:
params = {}
# set our preferences
self.LIMIT = int( params.get( "limit", "5" ) )
- self.ALBUMS = params.get( "albums", "" ) == "True"
- self.UNPLAYED = params.get( "unplayed", "" ) == "True"
- self.PLAY_TRAILER = params.get( "trailer", "" ) == "True"
+ self.UNPLAYED = params.get( "unplayed", "False" )
+ self.PLAY_TRAILER = params.get( "trailer", "False" )
self.ALARM = int( params.get( "alarm", "0" ) )
- self.RANDOM_ORDER = "True"
self.ALBUMID = params.get( "albumid", "" )
def _set_alarm( self ):
# only run if user/skinner preference
if ( not self.ALARM ): return
# set the alarms command
- command =
"XBMC.RunScript(%s,limit=%d&albums=%s&unplayed=%s&trailer=%s&alarm=%d)" % (
os.path.join( xbmc.translatePath(__cwd__), __file__ ), self.LIMIT, str(
self.ALBUMS ), str( self.UNPLAYED ), str( self.PLAY_TRAILER ), self.ALARM, )
+ command =
"XBMC.RunScript(%s,limit=%d&unplayed=%s&trailer=%s&alarm=%d)" % ( __scriptID__,
self.LIMIT, str( self.UNPLAYED ), str( self.PLAY_TRAILER ), self.ALARM, )
xbmc.executebuiltin( "AlarmClock(RandomItems,%s,%d,true)" % ( command,
self.ALARM, ) )
def __init__( self ):
# parse argv for any preferences
self._parse_argv()
- # format our records start and end
- xbmc.executehttpapi( "SetResponseFormat()" )
- xbmc.executehttpapi( "SetResponseFormat(OpenRecord,%s)" % (
"<record>", ) )
- xbmc.executehttpapi( "SetResponseFormat(CloseRecord,%s)" % (
"</record>", ) )
# check if we were executed internally
- print self.ALBUMID
if self.ALBUMID:
self._Play_Album( self.ALBUMID )
else:
@@ -100,143 +63,335 @@ class Main:
self._set_alarm()
# fetch media info
self._fetch_movie_info()
- self._fetch_tvshow_info()
- self._fetch_music_info()
+ self._fetch_episode_info()
+ self._fetch_album_info()
+ self._fetch_song_info()
self._fetch_addon_info()
def _fetch_movie_info( self ):
- # set our unplayed query
- unplayed = ( "", "where playCount is null ", )[ self.UNPLAYED ]
- # sql statement
- if ( self.RANDOM_ORDER ):
- # random order
- sql_movies = "select * from movieview %sorder by RANDOM() limit
%d" % ( unplayed, self.LIMIT, )
- else:
- # movies not finished
- sql_movies = "select movieview.*, bookmark.timeInSeconds from
movieview join bookmark on (movieview.idFile = bookmark.idFile) %sorder by
movieview.c00 limit %d" % ( unplayed, self.LIMIT, )
# query the database
- movies_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" %
quote_plus( sql_movies ), )
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"VideoLibrary.GetMovies", "params": {"fields": ["playcount", "year", "plot",
"runtime", "fanart", "thumbnail", "file", "trailer", "rating"] }, "id": 1}')
# separate the records
- movies = re.findall( "<record>(.+?)</record>", movies_xml, re.DOTALL )
- # enumerate thru our records and set our properties
- for count, movie in enumerate( movies ):
- # separate individual fields
- fields = re.findall( "<field>(.*?)</field>", movie, re.DOTALL )
- # set properties
+ json_response = re.compile( "{(.*?)}", re.DOTALL ).findall(json_query)
+ json_response.pop(0)
+ # get total value
+ total = str( len( json_response ) )
+ # enumerate thru our records
+ count = 0
+ while count < self.LIMIT:
+ count += 1
+ # check if we don't run out of items before LIMIT is reached
+ if len( json_response ) == 0:
+ return
+ # select a random item
+ item = random.choice( json_response )
+ # remove the item from our list
+ json_response.remove( item )
+ # find values
+ if self.UNPLAYED == "True":
+ findplaycount = re.search( '"playcount":(.*?),"', item )
+ if findplaycount:
+ playcount = findplaycount.group(1)
+ if int( playcount ) > 0:
+ count = count - 1
+ continue
+ findtitle = re.search( '"label":"(.*?)","', item )
+ if findtitle:
+ title = findtitle.group(1)
+ else:
+ title = ''
+ findrating = re.search( '"rating":(.*?),"', item )
+ if findrating:
+ rating = '%.1f' % float( findrating.group(1) )
+ else:
+ rating = ''
+ findyear = re.search( '"year":(.*)', item )
+ if findyear:
+ year = findyear.group(1)
+ else:
+ year = ''
+ findplot = re.search( '"plot":"(.*?)","', item )
+ if findplot:
+ plot = findplot.group(1)
+ else:
+ plot = ''
+ findrunningtime = re.search( '"runtime":"(.*?)","', item )
+ if findrunningtime:
+ runningtime = findrunningtime.group(1)
+ else:
+ runningtime = ''
+ findpath = re.search( '"file":"(.*?)","', item )
+ if findpath:
+ path = findpath.group(1)
+ else:
+ path = ''
+ findtrailer = re.search( '"trailer":"(.*?)","', item )
+ if findtrailer:
+ trailer = findtrailer.group(1)
+ if self.PLAY_TRAILER == "True":
+ path = trailer
+ else:
+ trailer = ''
+ findfanart = re.search( '"fanart":"(.*?)","', item )
+ if findfanart:
+ fanart = findfanart.group(1)
+ else:
+ fanart = ''
+ findthumb = re.search( '"thumbnail":"(.*?)","', item )
+ if findthumb:
+ thumb = findthumb.group(1)
+ else:
+ thumb = ''
+ # set our properties
+ self.WINDOW.setProperty( "RandomMovie.%d.Title" % ( count ), title
)
+ self.WINDOW.setProperty( "RandomMovie.%d.Rating" % ( count ),
rating )
+ self.WINDOW.setProperty( "RandomMovie.%d.Year" % ( count ), year)
+ self.WINDOW.setProperty( "RandomMovie.%d.Plot" % ( count ), plot )
+ self.WINDOW.setProperty( "RandomMovie.%d.RunningTime" % ( count ),
runningtime )
+ self.WINDOW.setProperty( "RandomMovie.%d.Path" % ( count ), path )
+ self.WINDOW.setProperty( "RandomMovie.%d.Trailer" % ( count ),
trailer )
+ self.WINDOW.setProperty( "RandomMovie.%d.Fanart" % ( count ),
fanart )
+ self.WINDOW.setProperty( "RandomMovie.%d.Thumb" % ( count ), thumb
)
+ self.WINDOW.setProperty( "RandomMovie.Count", total )
- self.WINDOW.setProperty( "RandomMovie.%d.Title" % ( count + 1, ),
fields[ 2 ] )
- self.WINDOW.setProperty( "RandomMovie.%d.Rating" % ( count + 1, ),
"%.1f" % float(fields[ 7 ]) )
- self.WINDOW.setProperty( "RandomMovie.%d.Year" % ( count + 1, ),
fields[ 9 ] )
- self.WINDOW.setProperty( "RandomMovie.%d.Plot" % ( count + 1, ),
fields[ 3 ] )
- self.WINDOW.setProperty( "RandomMovie.%d.RunningTime" % ( count +
1, ), fields[ 13 ] )
- # get cache names of path to use for thumbnail/fanart and play path
- thumb_cache, fanart_cache, play_path = self._get_media( fields[ 27
], fields[ 26 ] )
- if os.path.isfile("%s.dds" % (xbmc.translatePath(
"special://profile/Thumbnails/Video/%s/%s" % ( "Fanart",
os.path.splitext(fanart_cache)[0],) ) )):
- fanart_cache = "%s.dds" % (os.path.splitext(fanart_cache)[0],)
- self.WINDOW.setProperty( "RandomMovie.%d.Path" % ( count + 1, ), (
play_path, fields[ 21 ], )[ fields[ 21 ] != "" and self.PLAY_TRAILER ] )
- self.WINDOW.setProperty( "RandomMovie.%d.Trailer" % ( count + 1,
), fields[ 21 ] )
- self.WINDOW.setProperty( "RandomMovie.%d.Fanart" % ( count + 1, ),
"special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) )
- # initial thumb path
- thumb = "special://profile/Thumbnails/Video/%s/%s" % (
thumb_cache[ 0 ], thumb_cache, )
- # if thumb does not exist use an auto generated thumb path
- if ( not os.path.isfile( xbmc.translatePath( thumb ) ) ):
- thumb = "special://profile/Thumbnails/Video/%s/auto-%s" % (
thumb_cache[ 0 ], thumb_cache, )
- self.WINDOW.setProperty( "RandomMovie.%d.Thumb" % ( count + 1, ),
thumb )
+ def _fetch_episode_info( self ):
+ # query the database
+ tvshowid = 2
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"VideoLibrary.GetEpisodes", "params": { "fields": ["playcount", "season",
"episode", "showtitle", "plot", "fanart", "thumbnail", "file", "rating"] },
"id": 1}')
+ # separate the records
+ json_response = re.compile( "{(.*?)}", re.DOTALL ).findall(json_query)
+ json_response.pop(0)
+ # get total value
+ total = str( len( json_response ) )
+ # enumerate thru our records
+ count = 0
+ while count < self.LIMIT:
+ count += 1
+ # check if we don't run out of items before LIMIT is reached
+ if len( json_response ) == 0:
+ return
+ # select a random item
+ item = random.choice( json_response )
+ # remove the item from our list
+ json_response.remove( item )
+ # find values
+ if self.UNPLAYED == "True":
+ findplaycount = re.search( '"playcount":(.*?),"', item )
+ if findplaycount:
+ playcount = findplaycount.group(1)
+ if int( playcount ) > 0:
+ count = count - 1
+ continue
+ findtitle = re.search( '"label":"(.*?)","', item )
+ if findtitle:
+ title = findtitle.group(1)
+ else:
+ title = ''
+ findshowtitle = re.search( '"showtitle":"(.*?)","', item )
+ if findshowtitle:
+ showtitle = findshowtitle.group(1)
+ else:
+ showtitle = ''
+ findseason = re.search( '"season":(.*?),"', item )
+ if findseason:
+ season = findseason.group(1)
+ else:
+ season = ''
+ findepisode = re.search( '"episode":(.*?),"', item )
+ if findepisode:
+ episode = findepisode.group(1)
+ else:
+ episode = ''
+ findrating = re.search( '"rating":(.*?),"', item )
+ if findrating:
+ rating = "%.1f" % float( findrating.group(1) )
+ else:
+ rating = ''
+ findplot = re.search( '"plot":"(.*?)","', item )
+ if findplot:
+ plot = findplot.group(1)
+ else:
+ plot = ''
+ findpath = re.search( '"file":"(.*?)","', item )
+ if findpath:
+ path = findpath.group(1)
+ else:
+ path = ''
+ findfanart = re.search( '"fanart":"(.*?)","', item )
+ if findfanart:
+ fanart = findfanart.group(1)
+ else:
+ fanart = ''
+ findthumb = re.search( '"thumbnail":"(.*?)"', item )
+ if findthumb:
+ thumb = findthumb.group(1)
+ else:
+ thumb = ''
+ episodeno = "s%se%s" % ( season, episode, )
+ # set our properties
+ self.WINDOW.setProperty( "RandomEpisode.%d.ShowTitle" % ( count ),
showtitle )
+ self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeTitle" % ( count
), title )
+ self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeNo" % ( count ),
episodeno )
+ self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeSeason" % (
count ), season )
+ self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeNumber" % (
count ), episode )
+ self.WINDOW.setProperty( "RandomEpisode.%d.Rating" % ( count ),
rating )
+ self.WINDOW.setProperty( "RandomEpisode.%d.Plot" % ( count ), plot
)
+ self.WINDOW.setProperty( "RandomEpisode.%d.Path" % ( count ), path
)
+ self.WINDOW.setProperty( "RandomEpisode.%d.Fanart" % ( count ),
fanart )
+ self.WINDOW.setProperty( "RandomEpisode.%d.Thumb" % ( count ),
thumb )
+ self.WINDOW.setProperty( "RandomEpisode.Count", total )
- def _fetch_tvshow_info( self ):
- # set our unplayed query
- unplayed = ( "", "where playCount is null ", )[ self.UNPLAYED ]
- # sql statement
- if ( self.RANDOM_ORDER ):
- # random order
- sql_episodes = "select * from episodeview %sorder by RANDOM()
limit %d" % ( unplayed, self.LIMIT, )
- else:
- # tv shows not finished
- sql_episodes = "select episodeview.*, bookmark.timeInSeconds from
episodeview join bookmark on (episodeview.idFile = bookmark.idFile) %sorder by
episodeview.strTitle limit %d" % ( unplayed, self.LIMIT, )
+ def _fetch_album_info( self ):
# query the database
- episodes_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" %
quote_plus( sql_episodes ), )
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"AudioLibrary.GetAlbums", "params": {"fields": ["artist", "year", "thumbnail",
"fanart", "rating"] }, "id": 1}')
# separate the records
- episodes = re.findall( "<record>(.+?)</record>", episodes_xml,
re.DOTALL )
- # enumerate thru our records and set our properties
- for count, episode in enumerate( episodes ):
- # separate individual fields
- fields = re.findall( "<field>(.*?)</field>", episode, re.DOTALL )
- # set properties
- self.WINDOW.setProperty( "RandomEpisode.%d.ShowTitle" % ( count +
1, ), fields[ 30 ] )
- self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeTitle" % ( count
+ 1, ), fields[ 2 ] )
- self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeNo" % ( count +
1, ), "s%02de%02d" % ( int( fields[ 14 ] ), int( fields[ 15 ] ), ) )
- self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeSeason" % (
count + 1, ), fields[ 14 ] )
- self.WINDOW.setProperty( "RandomEpisode.%d.EpisodeNumber" % (
count + 1, ), fields[ 15 ] )
- self.WINDOW.setProperty( "RandomEpisode.%d.Rating" % ( count + 1,
), "%.1f" % float(fields[ 5 ]) )
- self.WINDOW.setProperty( "RandomEpisode.%d.Plot" % ( count + 1, ),
fields[ 3 ] )
- # get cache names of path to use for thumbnail/fanart and play path
- thumb_cache, fanart_cache, play_path = self._get_media( fields[ 27
], fields[ 26 ] )
- if ( not os.path.isfile( xbmc.translatePath(
"special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) ) ) ):
- fanart_cache =
xbmc.getCacheThumbName(os.path.join(os.path.split(os.path.split(fields[ 27
])[0])[0], ""))
- if os.path.isfile("%s.dds" % (xbmc.translatePath(
"special://profile/Thumbnails/Video/%s/%s" % ( "Fanart",
os.path.splitext(fanart_cache)[0],) ) )):
- fanart_cache = "%s.dds" % (os.path.splitext(fanart_cache)[0],)
- self.WINDOW.setProperty( "RandomEpisode.%d.Path" % ( count + 1, ),
play_path )
- self.WINDOW.setProperty( "RandomEpisode.%d.Fanart" % ( count + 1,
), "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) )
- # initial thumb path
- thumb = "special://profile/Thumbnails/Video/%s/%s" % (
thumb_cache[ 0 ], thumb_cache, )
- # if thumb does not exist use an auto generated thumb path
- if ( not os.path.isfile( xbmc.translatePath( thumb ) ) ):
- thumb = "special://profile/Thumbnails/Video/%s/auto-%s" % (
thumb_cache[ 0 ], thumb_cache, )
- self.WINDOW.setProperty( "RandomEpisode.%d.Thumb" % ( count + 1,
), thumb )
+ json_response = re.compile( "{(.*?)}", re.DOTALL ).findall(json_query)
+ json_response.pop(0)
+ # get total value
+ total = str( len( json_response ) )
+ # enumerate thru our records
+ count = 0
+ while count < self.LIMIT:
+ count += 1
+ # check if we don't run out of items before LIMIT is reached
+ if len( json_response ) == 0:
+ return
+ # select a random item
+ item = random.choice( json_response )
+ # remove the item from our list
+ json_response.remove( item )
+ # find values
+# if self.UNPLAYED == "True":
+# findplaycount = re.search( '"playcount":(.*?),"', item )
+# if findplaycount:
+# playcount = findplaycount.group(1)
+# if int( playcount ) > 0:
+# count = count - 1
+# continue
+ findtitle = re.search( '"label":"(.*?)","', item )
+ if findtitle:
+ title = findtitle.group(1)
+ else:
+ title = ''
+ findrating = re.search( '"rating":(.*?),"', item )
+ if findrating:
+ rating = findrating.group(1)
+ if rating == '48':
+ rating = ''
+ else:
+ rating = ''
+ findyear = re.search( '"year":(.*)', item )
+ if findyear:
+ year = findyear.group(1)
+ else:
+ year = ''
+ findartist = re.search( '"artist":"(.*?)","', item )
+ if findartist:
+ artist = findartist.group(1)
+ else:
+ artist = ''
+ findpath = re.search( '"albumid":(.*?),"', item )
+ if findpath:
+ path = 'XBMC.RunScript(' + __scriptID__ + ',albumid=' +
findpath.group(1) + ')'
+ else:
+ path = ''
+ findfanart = re.search( '"fanart":"(.*?)","', item )
+ if findfanart:
+ fanart = findfanart.group(1)
+ else:
+ fanart = ''
+ findthumb = re.search( '"thumbnail":"(.*?)","', item )
+ if findthumb:
+ thumb = findthumb.group(1)
+ else:
+ thumb = ''
+ # set our properties
+ self.WINDOW.setProperty( "RandomAlbum.%d.Title" % ( count ), title
)
+ self.WINDOW.setProperty( "RandomAlbum.%d.Rating" % ( count ),
rating )
+ self.WINDOW.setProperty( "RandomAlbum.%d.Year" % ( count ), year )
+ self.WINDOW.setProperty( "RandomAlbum.%d.Artist" % ( count ),
artist )
+ self.WINDOW.setProperty( "RandomAlbum.%d.Path" % ( count ), path )
+ self.WINDOW.setProperty( "RandomAlbum.%d.Fanart" % ( count ),
fanart )
+ self.WINDOW.setProperty( "RandomAlbum.%d.Thumb" % ( count ), thumb
)
+ self.WINDOW.setProperty( "RandomAlbum.Count", total )
- def _fetch_music_info( self ):
- # Current Working Directory
- # sql statement
- if ( self.ALBUMS ):
- sql_music = "select * from albumview order by RANDOM() limit
%d" % ( self.LIMIT, )
- # query the database for recently added albums
- music_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" %
quote_plus( sql_music ), )
- # separate the records
- items = re.findall( "<record>(.+?)</record>", music_xml,
re.DOTALL )
- # enumerate thru our records and set our properties
- for count, item in enumerate( items ):
- # separate individual fields
- fields = re.findall( "<field>(.*?)</field>", item,
re.DOTALL )
- # set properties
- self.WINDOW.setProperty( "RandomSong.%d.Title" % ( count +
1, ), fields[ 1 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Year" % ( count +
1, ), fields[ 8 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Artist" % ( count
+ 1, ), fields[ 6 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Rating" % ( count
+ 1, ), fields[ 18 ] )
- # Album Path (ID)
- path = 'XBMC.RunScript(script.randomitems,albumid=' +
fields[ 0 ] + ')'
- self.WINDOW.setProperty( "RandomSong.%d.Path" % ( count +
1, ), path )
- # get cache name of path to use for fanart
- cache_name = xbmc.getCacheThumbName( fields[ 6 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Fanart" % ( count
+ 1, ), "special://profile/Thumbnails/Music/%s/%s" % ( "Fanart", cache_name, ) )
- self.WINDOW.setProperty( "RandomSong.%d.Thumb" % ( count +
1, ), fields[ 9 ] )
- else:
- # set our unplayed query
- unplayed = ( "", "where lastplayed is null ", )[ self.UNPLAYED
]
- # sql statement
- sql_music = "select * from songview %sorder by RANDOM() limit
%d" % ( unplayed, self.LIMIT, )
- # query the database
- music_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" %
quote_plus( sql_music ), )
- # separate the records
- items = re.findall( "<record>(.+?)</record>", music_xml,
re.DOTALL )
- # enumerate thru our records and set our properties
- for count, item in enumerate( items ):
- # separate individual fields
- fields = re.findall( "<field>(.*?)</field>", item,
re.DOTALL )
- # set properties
- self.WINDOW.setProperty( "RandomSong.%d.Title" % ( count +
1, ), fields[ 3 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Year" % ( count +
1, ), fields[ 6 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Artist" % ( count
+ 1, ), fields[ 24 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Album" % ( count +
1, ), fields[ 21 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Rating" % ( count
+ 1, ), fields[ 18 ] )
- path = fields[ 22 ]
- # don't add song for albums list TODO: figure out how
toplay albums
- ##if ( not self.ALBUMS ):
- path += fields[ 8 ]
- self.WINDOW.setProperty( "RandomSong.%d.Path" % ( count +
1, ), path )
- # get cache name of path to use for fanart
- cache_name = xbmc.getCacheThumbName( fields[ 24 ] )
- self.WINDOW.setProperty( "RandomSong.%d.Fanart" % ( count
+ 1, ), "special://profile/Thumbnails/Music/%s/%s" % ( "Fanart", cache_name, ) )
- self.WINDOW.setProperty( "RandomSong.%d.Thumb" % ( count +
1, ), fields[ 27 ] )
+ def _fetch_song_info( self ):
+ # query the database
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"AudioLibrary.GetSongs", "params": {"fields": ["playcount", "artist", "album",
"year", "file", "thumbnail", "fanart", "rating"] }, "id": 1}')
+ # separate the records
+ json_response = re.compile( "{(.*?)}", re.DOTALL ).findall(json_query)
+ json_response.pop(0)
+ # get total value
+ total = str( len( json_response ) )
+ # enumerate thru our records
+ count = 0
+ while count < self.LIMIT:
+ count += 1
+ # check if we don't run out of items before LIMIT is reached
+ if len( json_response ) == 0:
+ return
+ # select a random item
+ item = random.choice( json_response )
+ # remove the item from our list
+ json_response.remove( item )
+ # find values
+ if self.UNPLAYED == "True":
+ findplaycount = re.search( '"playcount":(.*?),"', item )
+ if findplaycount:
+ playcount = findplaycount.group(1)
+ if int( playcount ) > 0:
+ count = count - 1
+ continue
+ findtitle = re.search( '"label":"(.*?)","', item )
+ if findtitle:
+ title = findtitle.group(1)
+ else:
+ title = ''
+ findrating = re.search( '"rating":(.*?),"', item )
+ if findrating:
+ rating = str( int( findrating.group(1) ) - 48)
+ else:
+ rating = ''
+ findyear = re.search( '"year":(.*)', item )
+ if findyear:
+ year = findyear.group(1)
+ else:
+ year = ''
+ findartist = re.search( '"artist":"(.*?)","', item )
+ if findartist:
+ artist = findartist.group(1)
+ else:
+ artist = ''
+ findalbum = re.search( '"album":"(.*?)","', item )
+ if findalbum:
+ album = findalbum.group(1)
+ else:
+ album = ''
+ findpath = re.search( '"file":"(.*?)","', item )
+ if findpath:
+ path = findpath.group(1)
+ else:
+ path = ''
+ findfanart = re.search( '"fanart":"(.*?)","', item )
+ if findfanart:
+ fanart = findfanart.group(1)
+ else:
+ fanart = ''
+ findthumb = re.search( '"thumbnail":"(.*?)","', item )
+ if findthumb:
+ thumb = findthumb.group(1)
+ else:
+ thumb = ''
+ # set our properties
+ self.WINDOW.setProperty( "RandomSong.%d.Title" % ( count ), title )
+ self.WINDOW.setProperty( "RandomSong.%d.Rating" % ( count ),
rating )
+ self.WINDOW.setProperty( "RandomSong.%d.Year" % ( count ), year )
+ self.WINDOW.setProperty( "RandomSong.%d.Artist" % ( count ),
artist )
+ self.WINDOW.setProperty( "RandomSong.%d.Album" % ( count ), album )
+ self.WINDOW.setProperty( "RandomSong.%d.Path" % ( count ), path )
+ self.WINDOW.setProperty( "RandomSong.%d.Fanart" % ( count ),
fanart )
+ self.WINDOW.setProperty( "RandomSong.%d.Thumb" % ( count ), thumb )
+ self.WINDOW.setProperty( "RandomSong.Count", total )
def _fetch_addon_info( self ):
# initialize our list
@@ -255,57 +410,67 @@ class Main:
for addonentry in
addonfilecontents.getElementsByTagName("addon"):
addonid = addonentry.getAttribute("id")
# find plugins and scripts
- addontype =
xbmcaddon.Addon(id=addonid).getAddonInfo('type')
- if (addontype == 'xbmc.python.script') or (addontype ==
'xbmc.python.pluginsource'):
- addonlist.append(addonid)
+ try:
+ addontype =
xbmcaddon.Addon(id=addonid).getAddonInfo('type')
+ if (addontype == 'xbmc.python.script') or (addontype
== 'xbmc.python.pluginsource'):
+ addonlist.append(addonid)
+ except:
+ pass
addonfilecontents.unlink()
- # set total property
- self.WINDOW.setProperty( "Addons.Count", str( len(addonlist) ) )
+ # get total value
+ total = str( len( addonlist ) )
# count thru our addons
- for count in range( self.LIMIT ):
+ count = 0
+ while count < self.LIMIT:
+ count += 1
# check if we don't run out of items before LIMIT is reached
- if len(addonlist) > 0:
- # select a random item
- addonid = random.choice(addonlist)
- # remove the item from our list
- addonlist.remove(addonid)
- # set properties
- self.WINDOW.setProperty( "RandomAddon.%d.Name" % ( count + 1,
), xbmcaddon.Addon(id=addonid).getAddonInfo('name') )
- self.WINDOW.setProperty( "RandomAddon.%d.Author" % ( count +
1, ), xbmcaddon.Addon(id=addonid).getAddonInfo('author') )
- self.WINDOW.setProperty( "RandomAddon.%d.Summary" % ( count +
1, ), xbmcaddon.Addon(id=addonid).getAddonInfo('summary') )
- self.WINDOW.setProperty( "RandomAddon.%d.Version" % ( count +
1, ), xbmcaddon.Addon(id=addonid).getAddonInfo('version') )
- self.WINDOW.setProperty( "RandomAddon.%d.Path" % ( count + 1,
), xbmcaddon.Addon(id=addonid).getAddonInfo('id') )
- self.WINDOW.setProperty( "RandomAddon.%d.Fanart" % ( count +
1, ), xbmcaddon.Addon(id=addonid).getAddonInfo('fanart') )
- self.WINDOW.setProperty( "RandomAddon.%d.Thumb" % ( count + 1,
), xbmcaddon.Addon(id=addonid).getAddonInfo('icon') )
- else:
- # set empty properties if we ran out of items before LIMIT was
reached
- self.WINDOW.setProperty( "RandomAddon.%d.Name" % ( count + 1,
), '' )
- self.WINDOW.setProperty( "RandomAddon.%d.Author" % ( count +
1, ), '' )
- self.WINDOW.setProperty( "RandomAddon.%d.Summary" % ( count +
1, ), '' )
- self.WINDOW.setProperty( "RandomAddon.%d.Version" % ( count +
1, ), '' )
- self.WINDOW.setProperty( "RandomAddon.%d.Path" % ( count + 1,
), '' )
- self.WINDOW.setProperty( "RandomAddon.%d.Fanart" % ( count +
1, ), '' )
- self.WINDOW.setProperty( "RandomAddon.%d.Thumb" % ( count + 1,
), '' )
+ if len(addonlist) == 0:
+ return
+ # select a random item
+ addonid = random.choice(addonlist)
+ # remove the item from our list
+ addonlist.remove(addonid)
+ # set properties
+ self.WINDOW.setProperty( "RandomAddon.%d.Name" % ( count ),
xbmcaddon.Addon(id=addonid).getAddonInfo('name') )
+ self.WINDOW.setProperty( "RandomAddon.%d.Author" % ( count ),
xbmcaddon.Addon(id=addonid).getAddonInfo('author') )
+ self.WINDOW.setProperty( "RandomAddon.%d.Summary" % ( count ),
xbmcaddon.Addon(id=addonid).getAddonInfo('summary') )
+ self.WINDOW.setProperty( "RandomAddon.%d.Version" % ( count ),
xbmcaddon.Addon(id=addonid).getAddonInfo('version') )
+ self.WINDOW.setProperty( "RandomAddon.%d.Path" % ( count ),
xbmcaddon.Addon(id=addonid).getAddonInfo('id') )
+ self.WINDOW.setProperty( "RandomAddon.%d.Fanart" % ( count ),
xbmcaddon.Addon(id=addonid).getAddonInfo('fanart') )
+ self.WINDOW.setProperty( "RandomAddon.%d.Thumb" % ( count ),
xbmcaddon.Addon(id=addonid).getAddonInfo('icon') )
+ self.WINDOW.setProperty( "RandomAddon.Count", total )
def _Play_Album( self, ID ):
- print "play album"
- playlist=xbmc.PlayList(0)
- playlist.clear()
- # sql statements
- sql_song = "select * from songview where idAlbum='%s' order by
iTrack " % ( ID )
- # query the databases
- songs_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" %
quote_plus( sql_song ), )
- # separate the records
- songs = re.findall( "<record>(.+?)</record>", songs_xml, re.DOTALL
)
- # enumerate thru our records and set our properties
- for count, movie in enumerate( songs ):
- # separate individual fields
- fields = re.findall( "<field>(.*?)</field>", movie, re.DOTALL )
- # set album name
- path = fields[ 22 ] + fields[ 8 ]
- listitem = xbmcgui.ListItem( fields[ 7 ] )
- xbmc.PlayList(0).add (path, listitem )
- xbmc.Player().play(playlist)
+ # query the database
+ json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"AudioLibrary.GetSongs", "params": {"fields": ["file", "fanart"], "albumid":%s
}, "id": 1}' % ID)
+ # separate the records
+ json_response = re.compile( "{(.*?)}", re.DOTALL ).findall(json_query)
+ json_response.pop(0)
+ # create a playlist
+ playlist = xbmc.PlayList(0)
+ # clear the playlist
+ playlist.clear()
+ # enumerate thru our records
+ for item in json_response:
+ # find values
+ findsongpath = re.search( '"file":"(.*?)","label"', item )
+ if findsongpath:
+ song = findsongpath.group(1)
+ else:
+ song = ''
+ findfanart = re.search( '"fanart":"(.*?)","file"', item )
+ if findfanart:
+ fanart = findfanart.group(1)
+ else:
+ fanart = ''
+ # create playlist item
+ listitem = xbmcgui.ListItem()
+ # add fanart image to the playlist item
+ listitem.setProperty( "fanart_image", fanart )
+ # add item to the playlist
+ playlist.add( url=song, listitem=listitem )
+ # play the playlist
+ xbmc.Player().play( playlist )
if ( __name__ == "__main__" ):
Main()
diff --git a/script.randomitems/addon.xml b/script.randomitems/addon.xml
index faf1225..b642c61 100644
--- a/script.randomitems/addon.xml
+++ b/script.randomitems/addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="script.randomitems" name="Random Items script" version="2.0.0"
provider-name="Hitcher, ronie">
+<addon id="script.randomitems" name="Random Items script" version="3.0.2"
provider-name="Hitcher, ronie">
<requires>
<import addon="xbmc.python" version="2.0"/>
</requires>
diff --git a/script.randomitems/changelog.txt b/script.randomitems/changelog.txt
index 21696a6..8ae9456 100644
--- a/script.randomitems/changelog.txt
+++ b/script.randomitems/changelog.txt
@@ -1,3 +1,12 @@
+v 3.0.2:
+- fixed fetching random albums
+
+v 3.0.1:
+- fixed error when trying to fetch info for installed addons only available in
the dharma repo
+
+v 3.0.0:
+- rewrote script to use json-rpc
+
v 2.0.0:
- version bump for eden repo
-----------------------------------------------------------------------
Summary of changes:
script.randomitems/README.txt | 36 ++-
script.randomitems/RandomItems.py | 615 +++++++++++++++++++++++--------------
script.randomitems/addon.xml | 2 +-
script.randomitems/changelog.txt | 9 +
4 files changed, 424 insertions(+), 238 deletions(-)
hooks/post-receive
--
Scripts
------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons