Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jan 9th, 2011  |  syntax: Python  |  size: 21.87 KB  |  hits: 85  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # *  This Program is free software; you can redistribute it and/or modify
  2. # *  it under the terms of the GNU General Public License as published by
  3. # *  the Free Software Foundation; either version 2, or (at your option)
  4. # *  any later version.
  5. # *
  6. # *  This Program is distributed in the hope that it will be useful,
  7. # *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # *  GNU General Public License for more details.
  10. # *
  11. # *  You should have received a copy of the GNU General Public License
  12. # *  along with XBMC; see the file COPYING.  If not, write to
  13. # *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  14. # *  http://www.gnu.org/copyleft/gpl.html
  15. # *
  16. # *  this file was taken from http://xbmc-addons.googlecode.com/svn/packages/scripts/RecentlyAdded.py
  17. # *  and modified to be a XBMC Add-on under gpl2 license on 20. November 2010.
  18. # *
  19. # *  Thanks to:
  20. # *
  21. # *  Nuka for the original RecentlyAdded.py
  22. # *
  23. # *  ronie and Hitcher for the improvements made while in official repo
  24. # *  
  25. # *  Team XBMC
  26.  
  27. import xbmc
  28. import xbmcgui
  29. from urllib import quote_plus, unquote_plus
  30. import re
  31. import sys
  32. import os
  33. import random
  34.    
  35. class Main:
  36.     # grab the home window
  37.     WINDOW = xbmcgui.Window( 10000 )
  38.  
  39.     def _clear_properties( self ):
  40.         # reset Totals property for visible condition
  41.         self.WINDOW.clearProperty( "Database.Totals" )
  42.         # we enumerate thru and clear individual properties in case other scripts set window properties
  43.         for count in range( self.LIMIT ):
  44.             # we clear title for visible condition
  45.             self.WINDOW.clearProperty( "LatestMovie.%d.Title" % ( count + 1, ) )
  46.             self.WINDOW.clearProperty( "LatestEpisode.%d.ShowTitle" % ( count + 1, ) )
  47.             self.WINDOW.clearProperty( "LatestSong.%d.Title" % ( count + 1, ) )
  48.  
  49.     def _get_media( self, path, file ):
  50.         # set default values
  51.         play_path = fanart_path = thumb_path = path + file
  52.         # we handle stack:// media special
  53.         if ( file.startswith( "stack://" ) ):
  54.             play_path = fanart_path = file
  55.             thumb_path = file[ 8 : ].split( " , " )[ 0 ]
  56.         # we handle rar:// and zip:// media special
  57.         if ( file.startswith( "rar://" ) or file.startswith( "zip://" ) ):
  58.             play_path = fanart_path = thumb_path = file
  59.         # return media info
  60.         return xbmc.getCacheThumbName( thumb_path ), xbmc.getCacheThumbName( fanart_path ), play_path
  61.  
  62.     def _parse_argv( self ):
  63.         try:
  64.             # parse sys.argv for params
  65.             params = dict( arg.split( "=" ) for arg in sys.argv[ 1 ].split( "&" ) )
  66.         except:
  67.             # no params passed
  68.             params = {}
  69.            
  70.  
  71.             # set our preferences
  72.         print params
  73.         self.LIMIT = int( params.get( "limit", "5" ) )
  74.         self.RECENT = not params.get( "partial", "" ) == "True"
  75.         self.ALBUMS = params.get( "albums", "" ) == "True"
  76.         self.UNPLAYED = params.get( "unplayed", "" ) == "True"
  77.         self.TOTALS = params.get( "totals", "" ) == "True"
  78.         self.PLAY_TRAILER = params.get( "trailer", "" ) == "True"
  79.         self.ALARM = int( params.get( "alarm", "0" ) )
  80.         self.RANDOM_ORDER = params.get( "random", "" ) == "True"
  81.         self.ALBUMID = params.get( "albumid", "" )
  82.    
  83.     def _set_alarm( self ):
  84.         # only run if user/skinner preference
  85.         if ( not self.ALARM ): return
  86.         # set the alarms command
  87.         command = "XBMC.RunScript(%s,limit=%d&partial=%s&albums=%s&unplayed=%s&totals=%s&trailer=%s&alarm=%d)" % ( os.path.join( os.getcwd(), __file__ ), self.LIMIT, str( not self.RECENT ), str( self.ALBUMS ), str( self.UNPLAYED ), str( self.TOTALS ), str( self.PLAY_TRAILER ), self.ALARM, )
  88.         xbmc.executebuiltin( "AlarmClock(LatestAdded,%s,%d,true)" % ( command, self.ALARM, ) )
  89.  
  90.     def __init__( self ):
  91.         # parse argv for any preferences
  92.         self._parse_argv()
  93.         # clear properties
  94.         self._clear_properties()
  95.         # set any alarm
  96.         self._set_alarm()
  97.         # format our records start and end
  98.         xbmc.executehttpapi( "SetResponseFormat()" )
  99.         xbmc.executehttpapi( "SetResponseFormat(OpenRecord,%s)" % ( "<record>", ) )
  100.         xbmc.executehttpapi( "SetResponseFormat(CloseRecord,%s)" % ( "</record>", ) )
  101.         # fetch media info
  102.         print self.ALBUMID
  103.         if self.ALBUMID: self._Play_Album( self.ALBUMID )
  104.         else:
  105.             self._fetch_totals()
  106.             self._fetch_movie_info()
  107.             self._fetch_tvshow_info()
  108.             self._fetch_music_info()
  109.  
  110.     def _fetch_totals( self ):
  111.         # only run if user/skinner preference
  112.         if ( not self.TOTALS ): return
  113.         import datetime
  114.         # get our regions format
  115.         date_format = xbmc.getRegion( "dateshort" ).replace( "MM", "%m" ).replace( "DD", "%d" ).replace( "YYYYY", "%Y" ).replace( "YYYY", "%Y" ).strip()
  116.         # only need to make Totals not empty
  117.         self.WINDOW.setProperty( "Database.Totals", "true" )
  118.         # sql statement for movie totals
  119.         sql_totals = "select count(1), count(playCount), movieview.* from movieview group by lastPlayed"
  120.         totals_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_totals ), )
  121.         records = re.findall( "<record>(.+?)</record>", totals_xml, re.DOTALL )
  122.         # initialize our list
  123.         movies_totals = [ 0 ] * 7
  124.         # enumerate thru and total our numbers
  125.         for record in records:
  126.             fields = re.findall( "<field>(.*?)</field>", record, re.DOTALL )
  127.             movies_totals[ 0 ] += int( fields[ 0 ] )
  128.             movies_totals[ 1 ] += int( fields[ 1 ] )
  129.             if ( fields[ 29 ] ):
  130.                 movies_totals[ 2 ] = fields[ 4 ] # title
  131.                 movies_totals[ 3 ] = fields[ 11 ] # year
  132.                 movies_totals[ 4 ] = fields[ 15 ] # runningtime
  133.                 movies_totals[ 5 ] = fields[ 18 ] # genre
  134.                 movies_totals[ 6 ] = "" # last watched
  135.                 date = fields[ 29 ].split( " " )[ 0 ].split( "-" )
  136.                 movies_totals[ 6 ] = datetime.date( int( date[ 0 ] ), int( date[ 1 ] ), int( date[ 2 ] ) ).strftime( date_format ) # last played
  137.         # sql statement for music videos totals
  138.         sql_totals = "select count(1), count(playCount) from musicvideoview"
  139.         totals_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_totals ), )
  140.         mvideos_totals = re.findall( "<field>(.+?)</field>", totals_xml, re.DOTALL )
  141.         # sql statement for tv shows/episodes totals
  142.         sql_totals = "SELECT tvshow.*, path.strPath AS strPath, counts.totalcount AS totalCount, counts.watchedcount AS watchedCount, counts.totalcount=counts.watchedcount AS watched FROM tvshow JOIN tvshowlinkpath ON tvshow.idShow=tvshowlinkpath.idShow JOIN path ON path.idpath=tvshowlinkpath.idPath LEFT OUTER join (SELECT tvshow.idShow AS idShow, count(1) AS totalCount, count(files.playCount) AS watchedCount FROM tvshow JOIN tvshowlinkepisode ON tvshow.idShow=tvshowlinkepisode.idShow JOIN episode ON episode.idEpisode=tvshowlinkepisode.idEpisode JOIN files ON files.idFile=episode.idFile GROUP BY tvshow.idShow) counts ON tvshow.idShow=counts.idShow"
  143.         totals_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_totals ), )
  144.         # initialize our list
  145.         tvshows_totals = [ 0 ] * 4
  146.         records = re.findall( "<record>(.+?)</record>", totals_xml, re.DOTALL )
  147.         # enumerate thru and total our numbers
  148.         for record in records:
  149.             fields = re.findall( "<field>(.*?)</field>", record, re.DOTALL )
  150.             if ( fields[ 25 ] ):
  151.                 tvshows_totals[ 0 ] += 1
  152.                 tvshows_totals[ 1 ] += int( fields[ 24 ] ) # number of episodes
  153.                 tvshows_totals[ 2 ] += int( fields[ 26 ] ) # watched?
  154.                 tvshows_totals[ 3 ] += int( fields[ 25 ] ) # number of episodes watched
  155.          # sql statement for tv albums/songs totals
  156.  
  157.         sql_totals = "select count(1), count(distinct strAlbum), count(distinct strArtist) from songview"
  158.         totals_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_totals ), )
  159.         music_totals = re.findall( "<field>(.+?)</field>", totals_xml, re.DOTALL )
  160.        
  161.         # set properties
  162.         self.WINDOW.setProperty( "Movies.Count" , str( movies_totals[ 0 ] ) or "" )
  163.         self.WINDOW.setProperty( "Movies.Watched" , str( movies_totals[ 1 ] ) or "" )
  164.         self.WINDOW.setProperty( "Movies.UnWatched" , str( movies_totals[ 0 ] - movies_totals[ 1 ] ) or "" )
  165.         self.WINDOW.setProperty( "Movies.LastWatchedTitle" , movies_totals[ 2 ] or "" )
  166.         self.WINDOW.setProperty( "Movies.LastWatchedYear" , movies_totals[ 3 ] or "" )
  167.         self.WINDOW.setProperty( "Movies.LastWatchedRuntime" , movies_totals[ 4 ] or "" )
  168.         self.WINDOW.setProperty( "Movies.LastWatchedGenre" , movies_totals[ 5 ] or "" )
  169.         self.WINDOW.setProperty( "Movies.LastWatchedDate" , movies_totals[ 6 ] or "" )
  170.        
  171.         self.WINDOW.setProperty( "MusicVideos.Count" , mvideos_totals[ 0 ] or "" )
  172.         self.WINDOW.setProperty( "MusicVideos.Watched" , mvideos_totals[ 1 ] or "" )
  173.         self.WINDOW.setProperty( "MusicVideos.UnWatched" , str( int( mvideos_totals[ 0 ] ) - int( mvideos_totals[ 1 ] ) ) or "" )
  174.        
  175.         self.WINDOW.setProperty( "TVShows.Count" , str( tvshows_totals[ 0 ] ) or "" )
  176.         self.WINDOW.setProperty( "TVShows.Watched" , str( tvshows_totals[ 2 ] ) or "" )
  177.         self.WINDOW.setProperty( "TVShows.UnWatched" , str( tvshows_totals[ 0 ] - tvshows_totals[ 2 ] ) or "" )
  178.         self.WINDOW.setProperty( "Episodes.Count" , str( tvshows_totals[ 1 ] ) or "" )
  179.         self.WINDOW.setProperty( "Episodes.Watched" , str( tvshows_totals[ 3 ] ) or "" )
  180.         self.WINDOW.setProperty( "Episodes.UnWatched" , str( tvshows_totals[ 1 ] - tvshows_totals[ 3 ] ) or "" )
  181.        
  182.         self.WINDOW.setProperty( "Music.SongsCount" , music_totals[ 0 ] or "" )
  183.         self.WINDOW.setProperty( "Music.AlbumsCount" , music_totals[ 1 ] or "" )
  184.         self.WINDOW.setProperty( "Music.ArtistsCount" , music_totals[ 2 ] or "" )
  185.  
  186.     def _fetch_movie_info( self ):
  187.         # set our unplayed query
  188.         unplayed = ( "", "where playCount is null ", )[ self.UNPLAYED ]
  189.         # sql statement
  190.         if ( self.RANDOM_ORDER ):
  191.             # random order
  192.             sql_movies = "select * from movieview %sorder by RANDOM() limit %d" % ( unplayed, self.LIMIT, )        
  193.         elif ( self.RECENT ):
  194.             # recently added
  195.             sql_movies = "select * from movieview %sorder by idMovie desc limit %d" % ( unplayed, self.LIMIT, )
  196.         else:
  197.             # movies not finished
  198.             sql_movies = "select movieview.*, bookmark.timeInSeconds from movieview join bookmark on (movieview.idFile = bookmark.idFile) %sorder by movieview.c00 limit %d" % ( unplayed, self.LIMIT, )
  199.         # query the database
  200.         movies_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_movies ), )
  201.         # separate the records
  202.         movies = re.findall( "<record>(.+?)</record>", movies_xml, re.DOTALL )
  203.         # enumerate thru our records and set our properties
  204.         for count, movie in enumerate( movies ):
  205.             # separate individual fields
  206.             fields = re.findall( "<field>(.*?)</field>", movie, re.DOTALL )
  207.             # set properties
  208.  
  209.             self.WINDOW.setProperty( "LatestMovie.%d.Title" % ( count + 1, ), fields[ 2 ] )
  210.             self.WINDOW.setProperty( "LatestMovie.%d.Rating" % ( count + 1, ), fields[ 7 ] )
  211.             self.WINDOW.setProperty( "LatestMovie.%d.Year" % ( count + 1, ), fields[ 9 ] )
  212.             self.WINDOW.setProperty( "LatestMovie.%d.Plot" % ( count + 1, ), fields[ 3 ] )
  213.             self.WINDOW.setProperty( "LatestMovie.%d.RunningTime" % ( count + 1, ), fields[ 13 ] )
  214.             # get cache names of path to use for thumbnail/fanart and play path
  215.             thumb_cache, fanart_cache, play_path = self._get_media( fields[ 25 ], fields[ 24 ] )
  216.             if os.path.isfile("%s.dds" % (xbmc.translatePath( "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", os.path.splitext(fanart_cache)[0],) ) )):
  217.                 fanart_cache = "%s.dds" % (os.path.splitext(fanart_cache)[0],)
  218.             self.WINDOW.setProperty( "LatestMovie.%d.Path" % ( count + 1, ), ( play_path, fields[ 21 ], )[ fields[ 21 ] != "" and self.PLAY_TRAILER ] )
  219.             self.WINDOW.setProperty( "LatestMovie.%d.Trailer" % ( count + 1, ), fields[ 21 ] )
  220.             self.WINDOW.setProperty( "LatestMovie.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) )
  221.             # initial thumb path
  222.             thumb = "special://profile/Thumbnails/Video/%s/%s" % ( thumb_cache[ 0 ], thumb_cache, )
  223.             # if thumb does not exist use an auto generated thumb path
  224.             if ( not os.path.isfile( xbmc.translatePath( thumb ) ) ):
  225.                 thumb = "special://profile/Thumbnails/Video/%s/auto-%s" % ( thumb_cache[ 0 ], thumb_cache, )
  226.             self.WINDOW.setProperty( "LatestMovie.%d.Thumb" % ( count + 1, ), thumb )
  227.  
  228.     def _fetch_tvshow_info( self ):
  229.         # set our unplayed query
  230.         unplayed = ( "", "where playCount is null ", )[ self.UNPLAYED ]
  231.         # sql statement
  232.         if ( self.RANDOM_ORDER ):
  233.             # random order
  234.             sql_episodes = "select * from episodeview %sorder by RANDOM() limit %d" % ( unplayed, self.LIMIT, )
  235.         elif ( self.RECENT ):
  236.             # recently added
  237.             sql_episodes = "select * from episodeview %sorder by idepisode desc limit %d" % ( unplayed, self.LIMIT, )
  238.         else:
  239.             # tv shows not finished
  240.             sql_episodes = "select episodeview.*, bookmark.timeInSeconds from episodeview join bookmark on (episodeview.idFile = bookmark.idFile) %sorder by episodeview.strTitle limit %d" % ( unplayed, self.LIMIT, )
  241.         # query the database
  242.         episodes_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_episodes ), )
  243.         # separate the records
  244.         episodes = re.findall( "<record>(.+?)</record>", episodes_xml, re.DOTALL )
  245.         # enumerate thru our records and set our properties
  246.         for count, episode in enumerate( episodes ):
  247.             # separate individual fields
  248.             fields = re.findall( "<field>(.*?)</field>", episode, re.DOTALL )
  249.             # set properties        
  250.             self.WINDOW.setProperty( "LatestEpisode.%d.ShowTitle" % ( count + 1, ), fields[ 28 ] )
  251.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeTitle" % ( count + 1, ), fields[ 2 ] )
  252.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeNo" % ( count + 1, ), "s%02de%02d" % ( int( fields[ 14 ] ), int( fields[ 15 ] ), ) )
  253.             self.WINDOW.setProperty( "LatestEpisode.%d.Rating" % ( count + 1, ), fields[ 5 ] )
  254.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeSeason" % ( count + 1, ), fields[ 14 ] )
  255.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeNumber" % ( count + 1, ), fields[ 15 ] )
  256.             self.WINDOW.setProperty( "LatestEpisode.%d.Plot" % ( count + 1, ), fields[ 3 ] )
  257.             # get cache names of path to use for thumbnail/fanart and play path
  258.             thumb_cache, fanart_cache, play_path = self._get_media( fields[ 25 ], fields[ 24 ] )
  259.             if ( not os.path.isfile( xbmc.translatePath( "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) ) ) ):
  260.                 fanart_cache = xbmc.getCacheThumbName(os.path.join(os.path.split(os.path.split(fields[ 25 ])[0])[0], ""))
  261.             if os.path.isfile("%s.dds" % (xbmc.translatePath( "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", os.path.splitext(fanart_cache)[0],) ) )):
  262.                 fanart_cache = "%s.dds" % (os.path.splitext(fanart_cache)[0],)
  263.             self.WINDOW.setProperty( "LatestEpisode.%d.Path" % ( count + 1, ), play_path )
  264.             self.WINDOW.setProperty( "LatestEpisode.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) )
  265.             # initial thumb path
  266.             thumb = "special://profile/Thumbnails/Video/%s/%s" % ( thumb_cache[ 0 ], thumb_cache, )
  267.             # if thumb does not exist use an auto generated thumb path
  268.             if ( not os.path.isfile( xbmc.translatePath( thumb ) ) ):
  269.                 thumb = "special://profile/Thumbnails/Video/%s/auto-%s" % ( thumb_cache[ 0 ], thumb_cache, )
  270.             self.WINDOW.setProperty( "LatestEpisode.%d.Thumb" % ( count + 1, ), thumb )
  271.  
  272.     def _fetch_music_info( self ):
  273.             # Current Working Directory
  274.             # sql statement
  275.             if ( self.ALBUMS ):
  276.                 if ( self.RANDOM_ORDER ):
  277.                     sql_music = "select * from albumview order by RANDOM() limit %d" % ( self.LIMIT, )
  278.                 else:
  279.                     sql_music = "select * from albumview order by idAlbum desc limit %d" % ( self.LIMIT, )
  280.                 # query the database for recently added albums
  281.                 music_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_music ), )
  282.                 # separate the records
  283.                 items = re.findall( "<record>(.+?)</record>", music_xml, re.DOTALL )
  284.                 # enumerate thru our records and set our properties
  285.                 for count, item in enumerate( items ):
  286.                     # separate individual fields
  287.                     fields = re.findall( "<field>(.*?)</field>", item, re.DOTALL )
  288.                     # set properties
  289.                     self.WINDOW.setProperty( "LatestSong.%d.Title" % ( count + 1, ), fields[ 1 ] )
  290.                     self.WINDOW.setProperty( "LatestSong.%d.Year" % ( count + 1, ), fields[ 8 ] )
  291.                     self.WINDOW.setProperty( "LatestSong.%d.Artist" % ( count + 1, ), fields[ 6 ] )
  292.                     self.WINDOW.setProperty( "LatestSong.%d.Rating" % ( count + 1, ), fields[ 18 ] )
  293.                     # Album Path  (ID)
  294.                     path = 'XBMC.RunScript(script.recentlyadded,albumid=' + fields[ 0 ] + ')'
  295.                     self.WINDOW.setProperty( "LatestSong.%d.Path" % ( count + 1, ), path )
  296.                     # get cache name of path to use for fanart
  297.                     cache_name = xbmc.getCacheThumbName( fields[ 6 ] )
  298.                     self.WINDOW.setProperty( "LatestSong.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Music/%s/%s" % ( "Fanart", cache_name, ) )
  299.                     self.WINDOW.setProperty( "LatestSong.%d.Thumb" % ( count + 1, ), fields[ 9 ] )
  300.                
  301.             else:
  302.                 # set our unplayed query
  303.                 unplayed = ( "", "where lastplayed is null ", )[ self.UNPLAYED ]
  304.                 # sql statement
  305.                 #sql_music = "select * from songview %sorder by idSong desc limit %d" % ( unplayed, self.LIMIT, )
  306.                 if ( self.RANDOM_ORDER ):
  307.                     sql_music = "select * from songview order by RANDOM() limit %d" % ( self.LIMIT, )
  308.                 else:
  309.                     sql_music = "select * from songview %sorder by idSong desc limit %d" % ( unplayed, self.LIMIT, )
  310.                 # query the database
  311.                 music_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_music ), )
  312.                 # separate the records
  313.                 items = re.findall( "<record>(.+?)</record>", music_xml, re.DOTALL )
  314.                 # enumerate thru our records and set our properties
  315.                 for count, item in enumerate( items ):
  316.                     # separate individual fields
  317.                     fields = re.findall( "<field>(.*?)</field>", item, re.DOTALL )
  318.                     # set properties
  319.                     self.WINDOW.setProperty( "LatestSong.%d.Title" % ( count + 1, ), fields[ 3 ] )
  320.                     self.WINDOW.setProperty( "LatestSong.%d.Year" % ( count + 1, ), fields[ 6 ] )
  321.                     self.WINDOW.setProperty( "LatestSong.%d.Artist" % ( count + 1, ), fields[ 24 ] )
  322.                     self.WINDOW.setProperty( "LatestSong.%d.Album" % ( count + 1, ), fields[ 21 ] )
  323.                     self.WINDOW.setProperty( "LatestSong.%d.Rating" % ( count + 1, ), fields[ 18 ] )
  324.                     path = fields[ 22 ]
  325.                     # don't add song for albums list TODO: figure out how toplay albums
  326.                     ##if ( not self.ALBUMS ):
  327.                     path += fields[ 8 ]
  328.                     self.WINDOW.setProperty( "LatestSong.%d.Path" % ( count + 1, ), path )
  329.                     # get cache name of path to use for fanart
  330.                     cache_name = xbmc.getCacheThumbName( fields[ 24 ] )
  331.                     self.WINDOW.setProperty( "LatestSong.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Music/%s/%s" % ( "Fanart", cache_name, ) )
  332.                     self.WINDOW.setProperty( "LatestSong.%d.Thumb" % ( count + 1, ), fields[ 27 ] )
  333.    
  334.     def _Play_Album( self, ID ):
  335.             print "play album"
  336.             playlist=xbmc.PlayList(0)
  337.             playlist.clear()
  338.             # sql statements
  339.             sql_song = "select * from songview where idAlbum='%s' order by iTrack " % ( ID )
  340.             # query the databases
  341.             songs_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_song ), )
  342.             # separate the records
  343.             songs = re.findall( "<record>(.+?)</record>", songs_xml, re.DOTALL )
  344.             # enumerate thru our records and set our properties
  345.             for count, movie in enumerate( songs ):
  346.                 # separate individual fields
  347.                 fields = re.findall( "<field>(.*?)</field>", movie, re.DOTALL )
  348.                 # set album name
  349.                 path = fields[ 22 ] + fields[ 8 ]
  350.                 listitem = xbmcgui.ListItem( fields[ 7 ] )
  351.                 xbmc.PlayList(0).add (path, listitem )
  352.             xbmc.Player().play(playlist)
  353.  
  354.  
  355. if ( __name__ == "__main__" ):
  356.     Main()