The branch, eden-pre has been updated
       via  e01218d26f10bb332fc708195892979c6ce0df73 (commit)
      from  93c9b4fbc8a0506bb5dade2937aa4a2f1e46a677 (commit)

- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=e01218d26f10bb332fc708195892979c6ce0df73

commit e01218d26f10bb332fc708195892979c6ce0df73
Author: ronie <[email protected]>
Date:   Mon Nov 21 23:02:02 2011 +0100

    [script.watchlist] -v0.1.2
    
    remove way too verbose logging and add support for albums

diff --git a/script.watchlist/README.txt b/script.watchlist/README.txt
index 83430fa..643574d 100644
--- a/script.watchlist/README.txt
+++ b/script.watchlist/README.txt
@@ -14,6 +14,7 @@ CONTENTS:
 This script will return:
 - a list containing the first unwatched episode of TV Shows you are watching.
 - a list of movies that are partially watched.
+- a list of most played albums
 
 The episode list is sorted by watch date of the previous episode:
 if you've watched 'South Park' yesterday and 'House' the day before,
@@ -21,11 +22,12 @@ if you've watched 'South Park' yesterday and 'House' the 
day before,
 
 The movie list is also sorted by watch date.
 
+The album list is sorted by playcount.
 
 2. Running the addon:
 ---------------------
 run the script with the options you need:
-RunScript(script.watchlist,movies=true&amp;episodes=true&amp;limit=25)
+RunScript(script.watchlist,movies=true&amp;episodes=true&amp;albums=true&amp;limit=25)
 
 
 3. Available infolabels:
@@ -57,4 +59,15 @@ WatchList_Episode.%d.Thumb           - episode thumbnail
 WatchList_Episode.%d.SeasonThumb       - season thumbnail
 WatchList_Episode.%d.TvshowThumb       - tv show thumbnail
 WatchList_Episode.%d.Fanart            - tv show fanart
-WatchList_Episode.%d.IsResumable       - indicates if it's a partially watched 
episode (True/False)  
+WatchList_Episode.%d.IsResumable       - indicates if it's a partially watched 
episode (True/False)
+
+WatchList_Album.%d.Label               - name of the album
+WatchList_Album.%d.Artist              - album artist
+WatchList_Album.%d.Genre               - album genre
+WatchList_Album.%d.Year                        - year of release
+WatchList_Album.%d.Album_Label         - recordlabel
+WatchList_Album.%d.Album_Description   - album review
+WatchList_Album.%d.Rating              - rating of the album
+WatchList_Album.%d.Thumb               - album thumbnail
+WatchList_Album.%d.Fanart              - artist fanart
+WatchList_Album.%d.Path                        - can be used to play the 
album: <onclick>$INFO[Window(Home).Property(WatchList_Album.%d.Path)]</onclick>
diff --git a/script.watchlist/addon.xml b/script.watchlist/addon.xml
index 9b0950b..3d992b5 100644
--- a/script.watchlist/addon.xml
+++ b/script.watchlist/addon.xml
@@ -1,13 +1,13 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="script.watchlist" name="Watchlist" version="0.1.0" 
provider-name="ronie">
+<addon id="script.watchlist" name="Watchlist" version="0.1.2" 
provider-name="ronie">
        <requires>
                <import addon="xbmc.python" version="2.0"/>
                <import addon="script.module.simplejson" version="2.0.10"/>
        </requires>
        <extension point="xbmc.python.library" library="default.py"/>
        <extension point="xbmc.addon.metadata">
-               <summary lang="en">Find the next episode to watch.</summary>
-               <description lang="en">This addon will create a list containing 
the first unwatched episode of tv shows you're watching.</description>
+               <summary lang="en">Addon to display recommended items from your 
library.</summary>
+               <description lang="en">This addon will create a list of 
partially watched movies, a list containing the first unwatched episode of tv 
shows you're watching and a list of most played albums.</description>
                <platform>all</platform>
        </extension>
 </addon>
diff --git a/script.watchlist/changelog.txt b/script.watchlist/changelog.txt
index 3030579..042f43b 100644
--- a/script.watchlist/changelog.txt
+++ b/script.watchlist/changelog.txt
@@ -1,3 +1,9 @@
+v0.1.2
+- added path property for albums
+
+v0.1.1
+- added most played albums
+
 v0.1.0
 - initial release
 
diff --git a/script.watchlist/default.py b/script.watchlist/default.py
index bc9df1b..1876097 100644
--- a/script.watchlist/default.py
+++ b/script.watchlist/default.py
@@ -1,4 +1,5 @@
 from time import strptime, mktime
+from operator import itemgetter
 import simplejson
 import xbmc, xbmcgui, xbmcaddon
 # http://mail.python.org/pipermail/python-list/2009-June/596197.html
@@ -6,6 +7,7 @@ import _strptime
 
 __addon__        = xbmcaddon.Addon()
 __addonversion__ = __addon__.getAddonInfo('version')
+__addonid__      = __addon__.getAddonInfo('id')
 __cwd__          = __addon__.getAddonInfo('path')
 
 def log(txt):
@@ -16,26 +18,38 @@ class Main:
     def __init__( self ):
         self._parse_argv()
         self._init_vars()
-        if self.MOVIES == 'true':
-            self._fetch_movies()
-        if self.EPISODES == 'true':
-            self._fetch_tvshows()
-            self._fetch_episodes()
-        if self.MOVIES == 'true':
-            self._clear_movie_properties()
-            self._set_movie_properties()
-        if self.EPISODES == 'true':
-            self._clear_episode_properties()
-            self._set_episode_properties()
+        # check how we were executed
+        if self.ALBUMID:
+            self._play_album( self.ALBUMID )
+        else:
+            if self.MOVIES == 'true':
+                self._fetch_movies()
+            if self.EPISODES == 'true':
+                self._fetch_tvshows()
+                self._fetch_episodes()
+            if self.ALBUMS == 'true':
+                self._fetch_songs()
+                self._fetch_albums()
+            if self.MOVIES == 'true':
+                self._clear_movie_properties()
+                self._set_movie_properties()
+            if self.EPISODES == 'true':
+                self._clear_episode_properties()
+                self._set_episode_properties()
+            if self.ALBUMS == 'true':
+                self._clear_album_properties()
+                self._set_album_properties()
 
     def _parse_argv( self ):
         try:
-            self.params = dict( arg.split( "=" ) for arg in sys.argv[ 1 
].split( "&" ) )
+            params = dict( arg.split( "=" ) for arg in sys.argv[ 1 ].split( 
"&" ) )
         except:
-            self.params = {}
-        self.MOVIES = self.params.get( "movies", "" )
-        self.EPISODES = self.params.get( "episodes", "" )
-        self.LIMIT = self.params.get( "limit", "25" )
+            params = {}
+        self.MOVIES = params.get( "movies", "" )
+        self.EPISODES = params.get( "episodes", "" )
+        self.ALBUMS = params.get( "albums", "" )
+        self.LIMIT = params.get( "limit", "25" )
+        self.ALBUMID = params.get( "albumid", "" )
 
     def _init_vars( self ):
         self.WINDOW = xbmcgui.Window( 10000 )
@@ -84,7 +98,6 @@ class Main:
                 studio = item['studio']
                 self.tvshows.append((tvshowid, thumbnail, studio))
         log("tv show list: %s items" % len(self.tvshows))
-        log("tv show list: %s" % self.tvshows)
 
     def _fetch_seasonthumb( self, tvshowid, seasonnumber ):
         json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": 
"VideoLibrary.GetSeasons", "params": {"properties": ["season", "thumbnail"], 
"tvshowid":%s }, "id": 1}' % tvshowid)
@@ -104,28 +117,22 @@ class Main:
             json_response = simplejson.loads(json_query)
             if json_response['result'].has_key('episodes'):
                 for item in json_response['result']['episodes']:
-                    log("### item: %s" % item)
                     playcount = item['playcount']
                     if playcount != 0:
-                        log("item has been played")
                         # this item has been watched, record play date (we 
need it for sorting the final list) and continue to next item
                         lastplayed = item['lastplayed']
                         if not lastplayed == "":
-                            log("item has been played, but no playdate was 
found")
                             # catch exceptions where the item has been played, 
but playdate wasn't stored in the db
                             datetime = strptime(lastplayed, "%Y-%m-%d 
%H:%M:%S")
                             lastplayed = str(mktime(datetime))
                         continue
                     else:
-                        log("item has not been played")
                         # this is the first unwatched item, check if it's 
partially watched
                         playdate = item['lastplayed']
                         if (lastplayed == "") and (playdate == ""):
-                            log("item has not been played and it's the first 
episode of a show")
                             # it's a tv show with 0 watched episodes, continue 
to the next tv show
                             break
                         else:
-                            log("item has not been played and we have a 
previous episode")
                             # this is the episode we need
                             label = item['label']
                             fanart = item['fanart']
@@ -153,6 +160,78 @@ class Main:
         self.episodes.sort(reverse=True)
         log("episode list: %s items" % len(self.episodes))
 
+    def _fetch_songs( self ):
+        self.albumsids = {}
+        previousid = ''
+        json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": 
"AudioLibrary.GetSongs", "params": {"properties": ["playcount", "albumid"], 
"sort": { "method": "album" } }, "id": 1}')
+        json_response = simplejson.loads(json_query)
+        if json_response['result'].has_key('songs'):
+            for item in json_response['result']['songs']:
+                albumid = item['albumid']
+                if albumid != '':
+                    # ignore single tracks that do not belong to an album
+                    if albumid != previousid:
+                        # new album
+                        albumplaycount = 0
+                        playcount = item['playcount']
+                        albumplaycount = albumplaycount + playcount
+                        previousid = albumid
+                    else:
+                        # song from the same album
+                        playcount = item['playcount']
+                        albumplaycount = albumplaycount + playcount
+                    if playcount != 0:
+                        # don't add unplayed items
+                        self.albumsids.update({albumid: albumplaycount})
+        self.albumsids = sorted(self.albumsids.items(), key=itemgetter(1))
+        self.albumsids.reverse()
+        log("album list: %s items" % len(self.albumsids))
+
+    def _fetch_albums( self ):
+        self.albums = []
+        for count, albumid in enumerate( self.albumsids ):
+            count += 1
+            json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": 
"AudioLibrary.GetAlbumDetails", "params": {"properties": ["description", 
"albumlabel", "artist", "genre", "year", "thumbnail", "fanart", "rating"], 
"albumid":%s }, "id": 1}' % albumid[0])
+            json_response = simplejson.loads(json_query)
+            if json_response['result'].has_key('albumdetails'):
+                item = json_response['result']['albumdetails']
+                description = item['description']
+                album = item['label']
+                albumlabel = item['albumlabel']
+                artist = item['artist']
+                genre = item['genre']
+                year = str(item['year'])
+                thumbnail = item['thumbnail']
+                fanart = item['fanart']
+                rating = str(item['rating'])
+                if rating == '48':
+                    rating = ''
+                path = 'XBMC.RunScript(' + __addonid__ + ',albumid=' + 
str(albumid[0]) + ')'
+                self.albums.append((album, artist, genre, year, albumlabel, 
description, rating, thumbnail, fanart, path))
+            if count == int(self.LIMIT):
+                # stop here if our list contains more items
+                break
+
+    def _play_album( self, ID ):
+        json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": 
"AudioLibrary.GetSongs", "params": {"properties": ["file", "fanart"], 
"albumid":%s }, "id": 1}' % ID)
+        json_response = simplejson.loads(json_query)
+        # create a playlist
+        playlist = xbmc.PlayList(0)
+        # clear the playlist
+        playlist.clear()
+        if json_response['result'].has_key('songs'):
+            for item in json_response['result']['songs']:
+                song = item['file']
+                fanart = item['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 )
+
     def _clear_movie_properties( self ):
         for count in range( int(self.LIMIT) ):
             count += 1
@@ -163,6 +242,11 @@ class Main:
             count += 1
             self.WINDOW.clearProperty( "WatchList_Episode.%d.Label" % ( count 
) )
 
+    def _clear_album_properties( self ):
+        for count in range( int(self.LIMIT) ):
+            count += 1
+            self.WINDOW.clearProperty( "WatchList_Album.%d.Label" % ( count ) )
+
     def _set_movie_properties( self ):
         for count, movie in enumerate( self.movies ):
             count += 1
@@ -203,6 +287,23 @@ class Main:
                 # stop here if our list contains more items
                 break
 
+    def _set_album_properties( self ):
+        for count, album in enumerate( self.albums ):
+            count += 1
+            self.WINDOW.setProperty( "WatchList_Album.%d.Label" % ( count ), 
album[0] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Artist" % ( count ), 
album[1] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Genre" % ( count ), 
album[2] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Year" % ( count ), 
album[3] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Album_Label" % ( 
count ), album[4] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Album_Description" % 
( count ), album[5] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Rating" % ( count ), 
album[6] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Thumb" % ( count ), 
album[7] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Fanart" % ( count ), 
album[8] )
+            self.WINDOW.setProperty( "WatchList_Album.%d.Path" % ( count ), 
album[9] )
+            if count == int(self.LIMIT):
+                # stop here if our list contains more items
+                break
+
 if ( __name__ == "__main__" ):
         log('script version %s started' % __addonversion__)
         Main()

-----------------------------------------------------------------------

Summary of changes:
 script.watchlist/README.txt    |   17 ++++-
 script.watchlist/addon.xml     |    6 +-
 script.watchlist/changelog.txt |    6 ++
 script.watchlist/default.py    |  147 +++++++++++++++++++++++++++++++++------
 4 files changed, 148 insertions(+), 28 deletions(-)


hooks/post-receive
-- 
Scripts

------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons

Reply via email to