home *** CD-ROM | disk | FTP | other *** search
/ Clickx 96 / Clickx 96.iso / software / tools / tool / xbmc-10.1.exe / addons / script.recentlyadded / RecentlyAdded.py < prev   
Encoding:
Python Source  |  2011-03-08  |  21.9 KB  |  357 lines

  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.             self.WINDOW.clearProperty( "LatestSong.%d.Album" % ( count + 1, ) )
  49.  
  50.     def _get_media( self, path, file ):
  51.         # set default values
  52.         play_path = fanart_path = thumb_path = path + file
  53.         # we handle stack:// media special
  54.         if ( file.startswith( "stack://" ) ):
  55.             play_path = fanart_path = file
  56.             thumb_path = file[ 8 : ].split( " , " )[ 0 ]
  57.         # we handle rar:// and zip:// media special
  58.         if ( file.startswith( "rar://" ) or file.startswith( "zip://" ) ):
  59.             play_path = fanart_path = thumb_path = file
  60.         # return media info
  61.         return xbmc.getCacheThumbName( thumb_path ), xbmc.getCacheThumbName( fanart_path ), play_path
  62.  
  63.     def _parse_argv( self ):
  64.         try:
  65.             # parse sys.argv for params
  66.             params = dict( arg.split( "=" ) for arg in sys.argv[ 1 ].split( "&" ) )
  67.         except:
  68.             # no params passed
  69.             params = {}
  70.            
  71.  
  72.             # set our preferences
  73.         print params
  74.         self.LIMIT = int( params.get( "limit", "5" ) )
  75.         self.RECENT = not params.get( "partial", "" ) == "True"
  76.         self.ALBUMS = params.get( "albums", "" ) == "True"
  77.         self.UNPLAYED = params.get( "unplayed", "" ) == "True"
  78.         self.TOTALS = params.get( "totals", "" ) == "True"
  79.         self.PLAY_TRAILER = params.get( "trailer", "" ) == "True"
  80.         self.ALARM = int( params.get( "alarm", "0" ) )
  81.         self.RANDOM_ORDER = params.get( "random", "" ) == "True"
  82.         self.ALBUMID = params.get( "albumid", "" )
  83.     
  84.     def _set_alarm( self ):
  85.         # only run if user/skinner preference
  86.         if ( not self.ALARM ): return
  87.         # set the alarms command
  88.         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, )
  89.         xbmc.executebuiltin( "AlarmClock(LatestAdded,%s,%d,true)" % ( command, self.ALARM, ) )
  90.  
  91.     def __init__( self ):
  92.         # parse argv for any preferences
  93.         self._parse_argv()
  94.         # clear properties
  95.         self._clear_properties()
  96.         # set any alarm
  97.         self._set_alarm()
  98.         # format our records start and end
  99.         xbmc.executehttpapi( "SetResponseFormat()" )
  100.         xbmc.executehttpapi( "SetResponseFormat(OpenRecord,%s)" % ( "<record>", ) )
  101.         xbmc.executehttpapi( "SetResponseFormat(CloseRecord,%s)" % ( "</record>", ) )
  102.         # fetch media info
  103.         print self.ALBUMID
  104.         if self.ALBUMID: self._Play_Album( self.ALBUMID )
  105.         else:
  106.             self._fetch_totals()
  107.             self._fetch_movie_info()
  108.             self._fetch_tvshow_info()
  109.             self._fetch_music_info()
  110.  
  111.     def _fetch_totals( self ):
  112.         # only run if user/skinner preference
  113.         if ( not self.TOTALS ): return
  114.         import datetime
  115.         # get our regions format
  116.         date_format = xbmc.getRegion( "dateshort" ).replace( "MM", "%m" ).replace( "DD", "%d" ).replace( "YYYYY", "%Y" ).replace( "YYYY", "%Y" ).strip()
  117.         # only need to make Totals not empty
  118.         self.WINDOW.setProperty( "Database.Totals", "true" )
  119.         # sql statement for movie totals
  120.         sql_totals = "select count(1), count(playCount), movieview.* from movieview group by lastPlayed"
  121.         totals_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_totals ), )
  122.         records = re.findall( "<record>(.+?)</record>", totals_xml, re.DOTALL )
  123.         # initialize our list
  124.         movies_totals = [ 0 ] * 7
  125.         # enumerate thru and total our numbers
  126.         for record in records:
  127.             fields = re.findall( "<field>(.*?)</field>", record, re.DOTALL )
  128.             movies_totals[ 0 ] += int( fields[ 0 ] )
  129.             movies_totals[ 1 ] += int( fields[ 1 ] )
  130.             if ( fields[ 29 ] ):
  131.                 movies_totals[ 2 ] = fields[ 4 ] # title
  132.                 movies_totals[ 3 ] = fields[ 11 ] # year
  133.                 movies_totals[ 4 ] = fields[ 15 ] # runningtime
  134.                 movies_totals[ 5 ] = fields[ 18 ] # genre
  135.                 movies_totals[ 6 ] = "" # last watched
  136.                 date = fields[ 29 ].split( " " )[ 0 ].split( "-" )
  137.                 movies_totals[ 6 ] = datetime.date( int( date[ 0 ] ), int( date[ 1 ] ), int( date[ 2 ] ) ).strftime( date_format ) # last played
  138.         # sql statement for music videos totals
  139.         sql_totals = "select count(1), count(playCount) from musicvideoview"
  140.         totals_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_totals ), )
  141.         mvideos_totals = re.findall( "<field>(.+?)</field>", totals_xml, re.DOTALL )
  142.         # sql statement for tv shows/episodes totals
  143.         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"
  144.         totals_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_totals ), )
  145.         # initialize our list
  146.         tvshows_totals = [ 0 ] * 4
  147.         records = re.findall( "<record>(.+?)</record>", totals_xml, re.DOTALL )
  148.         # enumerate thru and total our numbers
  149.         for record in records:
  150.             fields = re.findall( "<field>(.*?)</field>", record, re.DOTALL )
  151.             if ( fields[ 25 ] ):
  152.                 tvshows_totals[ 0 ] += 1
  153.                 tvshows_totals[ 1 ] += int( fields[ 24 ] ) # number of episodes
  154.                 tvshows_totals[ 2 ] += int( fields[ 26 ] ) # watched?
  155.                 tvshows_totals[ 3 ] += int( fields[ 25 ] ) # number of episodes watched
  156.          # sql statement for tv albums/songs totals
  157.  
  158.         sql_totals = "select count(1), count(distinct strAlbum), count(distinct strArtist) from songview"
  159.         totals_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_totals ), )
  160.         music_totals = re.findall( "<field>(.+?)</field>", totals_xml, re.DOTALL )
  161.         
  162.         # set properties
  163.         self.WINDOW.setProperty( "Movies.Count" , str( movies_totals[ 0 ] ) or "" )
  164.         self.WINDOW.setProperty( "Movies.Watched" , str( movies_totals[ 1 ] ) or "" )
  165.         self.WINDOW.setProperty( "Movies.UnWatched" , str( movies_totals[ 0 ] - movies_totals[ 1 ] ) or "" )
  166.         self.WINDOW.setProperty( "Movies.LastWatchedTitle" , movies_totals[ 2 ] or "" )
  167.         self.WINDOW.setProperty( "Movies.LastWatchedYear" , movies_totals[ 3 ] or "" )
  168.         self.WINDOW.setProperty( "Movies.LastWatchedRuntime" , movies_totals[ 4 ] or "" )
  169.         self.WINDOW.setProperty( "Movies.LastWatchedGenre" , movies_totals[ 5 ] or "" )
  170.         self.WINDOW.setProperty( "Movies.LastWatchedDate" , movies_totals[ 6 ] or "" )
  171.         
  172.         self.WINDOW.setProperty( "MusicVideos.Count" , mvideos_totals[ 0 ] or "" )
  173.         self.WINDOW.setProperty( "MusicVideos.Watched" , mvideos_totals[ 1 ] or "" )
  174.         self.WINDOW.setProperty( "MusicVideos.UnWatched" , str( int( mvideos_totals[ 0 ] ) - int( mvideos_totals[ 1 ] ) ) or "" )
  175.         
  176.         self.WINDOW.setProperty( "TVShows.Count" , str( tvshows_totals[ 0 ] ) or "" )
  177.         self.WINDOW.setProperty( "TVShows.Watched" , str( tvshows_totals[ 2 ] ) or "" )
  178.         self.WINDOW.setProperty( "TVShows.UnWatched" , str( tvshows_totals[ 0 ] - tvshows_totals[ 2 ] ) or "" )
  179.         self.WINDOW.setProperty( "Episodes.Count" , str( tvshows_totals[ 1 ] ) or "" )
  180.         self.WINDOW.setProperty( "Episodes.Watched" , str( tvshows_totals[ 3 ] ) or "" )
  181.         self.WINDOW.setProperty( "Episodes.UnWatched" , str( tvshows_totals[ 1 ] - tvshows_totals[ 3 ] ) or "" )
  182.         
  183.         self.WINDOW.setProperty( "Music.SongsCount" , music_totals[ 0 ] or "" )
  184.         self.WINDOW.setProperty( "Music.AlbumsCount" , music_totals[ 1 ] or "" )
  185.         self.WINDOW.setProperty( "Music.ArtistsCount" , music_totals[ 2 ] or "" )
  186.  
  187.     def _fetch_movie_info( self ):
  188.         # set our unplayed query
  189.         unplayed = ( "", "where playCount is null ", )[ self.UNPLAYED ]
  190.         # sql statement
  191.         if ( self.RANDOM_ORDER ):
  192.             # random order
  193.             sql_movies = "select * from movieview %sorder by RANDOM() limit %d" % ( unplayed, self.LIMIT, )        
  194.         elif ( self.RECENT ):
  195.             # recently added
  196.             sql_movies = "select * from movieview %sorder by idMovie desc limit %d" % ( unplayed, self.LIMIT, )
  197.         else:
  198.             # movies not finished
  199.             sql_movies = "select movieview.*, bookmark.timeInSeconds from movieview join bookmark on (movieview.idFile = bookmark.idFile) %sorder by movieview.c00 limit %d" % ( unplayed, self.LIMIT, )
  200.         # query the database
  201.         movies_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_movies ), )
  202.         # separate the records
  203.         movies = re.findall( "<record>(.+?)</record>", movies_xml, re.DOTALL )
  204.         # enumerate thru our records and set our properties
  205.         for count, movie in enumerate( movies ):
  206.             # separate individual fields
  207.             fields = re.findall( "<field>(.*?)</field>", movie, re.DOTALL )
  208.             # set properties
  209.  
  210.             self.WINDOW.setProperty( "LatestMovie.%d.Title" % ( count + 1, ), fields[ 2 ] )
  211.             self.WINDOW.setProperty( "LatestMovie.%d.Rating" % ( count + 1, ), fields[ 7 ] )
  212.             self.WINDOW.setProperty( "LatestMovie.%d.Year" % ( count + 1, ), fields[ 9 ] )
  213.             self.WINDOW.setProperty( "LatestMovie.%d.Plot" % ( count + 1, ), fields[ 3 ] )
  214.             self.WINDOW.setProperty( "LatestMovie.%d.RunningTime" % ( count + 1, ), fields[ 13 ] )
  215.             # get cache names of path to use for thumbnail/fanart and play path
  216.             thumb_cache, fanart_cache, play_path = self._get_media( fields[ 25 ], fields[ 24 ] )
  217.             if os.path.isfile("%s.dds" % (xbmc.translatePath( "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", os.path.splitext(fanart_cache)[0],) ) )):
  218.                 fanart_cache = "%s.dds" % (os.path.splitext(fanart_cache)[0],)
  219.             self.WINDOW.setProperty( "LatestMovie.%d.Path" % ( count + 1, ), ( play_path, fields[ 21 ], )[ fields[ 21 ] != "" and self.PLAY_TRAILER ] )
  220.             self.WINDOW.setProperty( "LatestMovie.%d.Trailer" % ( count + 1, ), fields[ 21 ] )
  221.             self.WINDOW.setProperty( "LatestMovie.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) )
  222.             # initial thumb path
  223.             thumb = "special://profile/Thumbnails/Video/%s/%s" % ( thumb_cache[ 0 ], thumb_cache, )
  224.             # if thumb does not exist use an auto generated thumb path
  225.             if ( not os.path.isfile( xbmc.translatePath( thumb ) ) ):
  226.                 thumb = "special://profile/Thumbnails/Video/%s/auto-%s" % ( thumb_cache[ 0 ], thumb_cache, )
  227.             self.WINDOW.setProperty( "LatestMovie.%d.Thumb" % ( count + 1, ), thumb )
  228.  
  229.     def _fetch_tvshow_info( self ):
  230.         # set our unplayed query
  231.         unplayed = ( "", "where playCount is null ", )[ self.UNPLAYED ]
  232.         # sql statement
  233.         if ( self.RANDOM_ORDER ):
  234.             # random order
  235.             sql_episodes = "select * from episodeview %sorder by RANDOM() limit %d" % ( unplayed, self.LIMIT, )
  236.         elif ( self.RECENT ):
  237.             # recently added
  238.             sql_episodes = "select * from episodeview %sorder by idepisode desc limit %d" % ( unplayed, self.LIMIT, )
  239.         else:
  240.             # tv shows not finished
  241.             sql_episodes = "select episodeview.*, bookmark.timeInSeconds from episodeview join bookmark on (episodeview.idFile = bookmark.idFile) %sorder by episodeview.strTitle limit %d" % ( unplayed, self.LIMIT, )
  242.         # query the database
  243.         episodes_xml = xbmc.executehttpapi( "QueryVideoDatabase(%s)" % quote_plus( sql_episodes ), )
  244.         # separate the records
  245.         episodes = re.findall( "<record>(.+?)</record>", episodes_xml, re.DOTALL )
  246.         # enumerate thru our records and set our properties
  247.         for count, episode in enumerate( episodes ):
  248.             # separate individual fields
  249.             fields = re.findall( "<field>(.*?)</field>", episode, re.DOTALL )
  250.             # set properties        
  251.             self.WINDOW.setProperty( "LatestEpisode.%d.ShowTitle" % ( count + 1, ), fields[ 28 ] )
  252.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeTitle" % ( count + 1, ), fields[ 2 ] )
  253.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeNo" % ( count + 1, ), "s%02de%02d" % ( int( fields[ 14 ] ), int( fields[ 15 ] ), ) )
  254.             self.WINDOW.setProperty( "LatestEpisode.%d.Rating" % ( count + 1, ), fields[ 5 ] )
  255.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeSeason" % ( count + 1, ), fields[ 14 ] )
  256.             self.WINDOW.setProperty( "LatestEpisode.%d.EpisodeNumber" % ( count + 1, ), fields[ 15 ] )
  257.             self.WINDOW.setProperty( "LatestEpisode.%d.Plot" % ( count + 1, ), fields[ 3 ] )
  258.             # get cache names of path to use for thumbnail/fanart and play path
  259.             thumb_cache, fanart_cache, play_path = self._get_media( fields[ 25 ], fields[ 24 ] )
  260.             if ( not os.path.isfile( xbmc.translatePath( "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) ) ) ):
  261.                 fanart_cache = xbmc.getCacheThumbName(os.path.join(os.path.split(os.path.split(fields[ 25 ])[0])[0], ""))
  262.             if os.path.isfile("%s.dds" % (xbmc.translatePath( "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", os.path.splitext(fanart_cache)[0],) ) )):
  263.                 fanart_cache = "%s.dds" % (os.path.splitext(fanart_cache)[0],)
  264.             self.WINDOW.setProperty( "LatestEpisode.%d.Path" % ( count + 1, ), play_path )
  265.             self.WINDOW.setProperty( "LatestEpisode.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Video/%s/%s" % ( "Fanart", fanart_cache, ) )
  266.             # initial thumb path
  267.             thumb = "special://profile/Thumbnails/Video/%s/%s" % ( thumb_cache[ 0 ], thumb_cache, )
  268.             # if thumb does not exist use an auto generated thumb path
  269.             if ( not os.path.isfile( xbmc.translatePath( thumb ) ) ):
  270.                 thumb = "special://profile/Thumbnails/Video/%s/auto-%s" % ( thumb_cache[ 0 ], thumb_cache, )
  271.             self.WINDOW.setProperty( "LatestEpisode.%d.Thumb" % ( count + 1, ), thumb )
  272.  
  273.     def _fetch_music_info( self ):
  274.             # Current Working Directory
  275.             # sql statement
  276.             if ( self.ALBUMS ):
  277.                 if ( self.RANDOM_ORDER ):
  278.                     sql_music = "select * from albumview order by RANDOM() limit %d" % ( self.LIMIT, )
  279.                 else:
  280.                     sql_music = "select * from albumview order by idAlbum desc limit %d" % ( self.LIMIT, )
  281.                 # query the database for recently added albums
  282.                 music_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_music ), )
  283.                 # separate the records
  284.                 items = re.findall( "<record>(.+?)</record>", music_xml, re.DOTALL )
  285.                 # enumerate thru our records and set our properties
  286.                 for count, item in enumerate( items ):
  287.                     # separate individual fields
  288.                     fields = re.findall( "<field>(.*?)</field>", item, re.DOTALL )
  289.                     # set properties
  290.                     self.WINDOW.setProperty( "LatestSong.%d.Title" % ( count + 1, ), fields[ 1 ] )
  291.                     self.WINDOW.setProperty( "LatestSong.%d.Year" % ( count + 1, ), fields[ 8 ] )
  292.                     self.WINDOW.setProperty( "LatestSong.%d.Artist" % ( count + 1, ), fields[ 6 ] )
  293.                     self.WINDOW.setProperty( "LatestSong.%d.Rating" % ( count + 1, ), fields[ 18 ] )
  294.                     # Album Path  (ID)
  295.                     path = 'XBMC.RunScript(script.recentlyadded,albumid=' + fields[ 0 ] + ')'
  296.                     self.WINDOW.setProperty( "LatestSong.%d.Path" % ( count + 1, ), path )
  297.                     # get cache name of path to use for fanart
  298.                     cache_name = xbmc.getCacheThumbName( fields[ 6 ] )
  299.                     self.WINDOW.setProperty( "LatestSong.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Music/%s/%s" % ( "Fanart", cache_name, ) )
  300.                     self.WINDOW.setProperty( "LatestSong.%d.Thumb" % ( count + 1, ), fields[ 9 ] )
  301.                 
  302.             else:
  303.                 # set our unplayed query
  304.                 unplayed = ( "", "where lastplayed is null ", )[ self.UNPLAYED ]
  305.                 # sql statement
  306.                 #sql_music = "select * from songview %sorder by idSong desc limit %d" % ( unplayed, self.LIMIT, )
  307.                 if ( self.RANDOM_ORDER ):
  308.                     sql_music = "select * from songview order by RANDOM() limit %d" % ( self.LIMIT, )
  309.                 else:
  310.                     sql_music = "select * from songview %sorder by idSong desc limit %d" % ( unplayed, self.LIMIT, )
  311.                 # query the database
  312.                 music_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_music ), )
  313.                 # separate the records
  314.                 items = re.findall( "<record>(.+?)</record>", music_xml, re.DOTALL )
  315.                 # enumerate thru our records and set our properties
  316.                 for count, item in enumerate( items ):
  317.                     # separate individual fields
  318.                     fields = re.findall( "<field>(.*?)</field>", item, re.DOTALL )
  319.                     # set properties
  320.                     self.WINDOW.setProperty( "LatestSong.%d.Title" % ( count + 1, ), fields[ 3 ] )
  321.                     self.WINDOW.setProperty( "LatestSong.%d.Year" % ( count + 1, ), fields[ 6 ] )
  322.                     self.WINDOW.setProperty( "LatestSong.%d.Artist" % ( count + 1, ), fields[ 24 ] )
  323.                     self.WINDOW.setProperty( "LatestSong.%d.Album" % ( count + 1, ), fields[ 21 ] )
  324.                     self.WINDOW.setProperty( "LatestSong.%d.Rating" % ( count + 1, ), fields[ 18 ] )
  325.                     path = fields[ 22 ]
  326.                     # don't add song for albums list TODO: figure out how toplay albums
  327.                     ##if ( not self.ALBUMS ):
  328.                     path += fields[ 8 ]
  329.                     self.WINDOW.setProperty( "LatestSong.%d.Path" % ( count + 1, ), path )
  330.                     # get cache name of path to use for fanart
  331.                     cache_name = xbmc.getCacheThumbName( fields[ 24 ] )
  332.                     self.WINDOW.setProperty( "LatestSong.%d.Fanart" % ( count + 1, ), "special://profile/Thumbnails/Music/%s/%s" % ( "Fanart", cache_name, ) )
  333.                     self.WINDOW.setProperty( "LatestSong.%d.Thumb" % ( count + 1, ), fields[ 27 ] )
  334.    
  335.     def _Play_Album( self, ID ):
  336.             print "play album"
  337.             playlist=xbmc.PlayList(0)
  338.             playlist.clear()
  339.             # sql statements
  340.             sql_song = "select * from songview where idAlbum='%s' order by iTrack " % ( ID )
  341.             # query the databases
  342.             songs_xml = xbmc.executehttpapi( "QueryMusicDatabase(%s)" % quote_plus( sql_song ), )
  343.             # separate the records
  344.             songs = re.findall( "<record>(.+?)</record>", songs_xml, re.DOTALL )
  345.             # enumerate thru our records and set our properties
  346.             for count, movie in enumerate( songs ):
  347.                 # separate individual fields
  348.                 fields = re.findall( "<field>(.*?)</field>", movie, re.DOTALL )
  349.                 # set album name
  350.                 path = fields[ 22 ] + fields[ 8 ]
  351.                 listitem = xbmcgui.ListItem( fields[ 7 ] )
  352.                 xbmc.PlayList(0).add (path, listitem )
  353.             xbmc.Player().play(playlist)
  354.  
  355.  
  356. if ( __name__ == "__main__" ):
  357.     Main()