The branch, eden-pre has been updated
via 416270f3e6f4037fb9d118edb449394046b96497 (commit)
from f906006cfce4a6d3cc10d338533303a04169b6ae (commit)
- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=416270f3e6f4037fb9d118edb449394046b96497
commit 416270f3e6f4037fb9d118edb449394046b96497
Author: ronie <[email protected]>
Date: Fri Dec 16 14:55:14 2011 +0100
[script.watchlist] -v0.1.7
daemonize script and update properties after playback ended/stopped
notification
diff --git a/script.watchlist/README.txt b/script.watchlist/README.txt
index 643574d..dce345c 100644
--- a/script.watchlist/README.txt
+++ b/script.watchlist/README.txt
@@ -24,6 +24,7 @@ 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:
@@ -71,3 +72,7 @@ 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>
+
+
+WatchList_Running - used by the script internally to
check if it's already running
+
diff --git a/script.watchlist/addon.xml b/script.watchlist/addon.xml
index 3d992b5..3bb5e0c 100644
--- a/script.watchlist/addon.xml
+++ b/script.watchlist/addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="script.watchlist" name="Watchlist" version="0.1.2"
provider-name="ronie">
+<addon id="script.watchlist" name="Watchlist" version="0.1.7"
provider-name="ronie">
<requires>
<import addon="xbmc.python" version="2.0"/>
<import addon="script.module.simplejson" version="2.0.10"/>
diff --git a/script.watchlist/changelog.txt b/script.watchlist/changelog.txt
index 042f43b..79d547f 100644
--- a/script.watchlist/changelog.txt
+++ b/script.watchlist/changelog.txt
@@ -1,3 +1,19 @@
+v0.1.7
+- ignore possible unicode errors
+- stop previous script instance if a new one is created
+
+v0.1.6
+- daemonize script and update properties after playback ended/stopped
notification
+
+v0.1.5
+- fix previous fix
+
+v0.1.4
+- fixed: script didn't add episode if xbmc didn't return a playdate for the
previous episode
+
+v0.1.3
+- fix crash when user has no music database
+
v0.1.2
- added path property for albums
diff --git a/script.watchlist/default.py b/script.watchlist/default.py
index 1876097..18fa184 100644
--- a/script.watchlist/default.py
+++ b/script.watchlist/default.py
@@ -22,23 +22,13 @@ class Main:
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()
+ # clear our property, if another instance is already running it
should stop now
+ self.WINDOW.clearProperty('WatchList_Running')
+ self._fetch_info()
+ # give a possible other instance some time to notice the empty
property
+ xbmc.sleep(2000)
+ self.WINDOW.setProperty('WatchList_Running', 'True')
+ self._daemon()
def _parse_argv( self ):
try:
@@ -53,10 +43,31 @@ class Main:
def _init_vars( self ):
self.WINDOW = xbmcgui.Window( 10000 )
+ self.Player = MyPlayer( action = self._update )
+
+ def _fetch_info( self ):
+ 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 _fetch_movies( self ):
self.movies = []
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"VideoLibrary.GetMovies", "params": {"properties": ["resume", "genre",
"studio", "tagline", "runtime", "fanart", "thumbnail", "file", "plot",
"plotoutline", "year", "lastplayed", "rating"]}, "id": 1}')
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('movies'):
for item in json_response['result']['movies']:
@@ -75,12 +86,14 @@ class Main:
path = item['file']
rating = str(round(float(item['rating']),1))
if item.has_key('resume'):
- # catch exceptions where the lastplayed isn't returned
+ # catch exceptions where the lastplayed isn't returned
by json-rpc (bug?)
lastplayed = item['lastplayed']
else:
lastplayed = ''
- if not lastplayed == "":
+ if lastplayed == '':
# catch exceptions where the item has been partially
played, but playdate wasn't stored in the db
+ lastplayed = '0'
+ else:
datetime = strptime(lastplayed, "%Y-%m-%d %H:%M:%S")
lastplayed = str(mktime(datetime))
self.movies.append((lastplayed, label, year, genre,
studio, plot, plotoutline, tagline, runtime, fanart, thumbnail, path, rating))
@@ -90,6 +103,7 @@ class Main:
def _fetch_tvshows( self ):
self.tvshows = []
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"VideoLibrary.GetTVShows", "params": {"properties": ["studio", "thumbnail"]},
"id": 1}')
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('tvshows'):
for item in json_response['result']['tvshows']:
@@ -101,6 +115,7 @@ class Main:
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)
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('seasons'):
for item in json_response['result']['seasons']:
@@ -114,20 +129,23 @@ class Main:
for tvshow in self.tvshows:
lastplayed = ""
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"VideoLibrary.GetEpisodes", "params": {"properties": ["playcount", "plot",
"season", "episode", "showtitle", "thumbnail", "fanart", "file", "lastplayed",
"rating"], "sort": {"method": "episode"}, "tvshowid":%s}, "id": 1}' % tvshow[0])
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('episodes'):
for item in json_response['result']['episodes']:
playcount = item['playcount']
if playcount != 0:
- # this item has been watched, record play date (we
need it for sorting the final list) and continue to next item
+ # this episode has been watched, record play date (we
need it for sorting the final list) and continue to next episode
lastplayed = item['lastplayed']
- if not lastplayed == "":
- # catch exceptions where the item has been played,
but playdate wasn't stored in the db
+ if lastplayed == '':
+ # catch exceptions where the episode has been
played, but playdate wasn't stored in the db
+ lastplayed = '0'
+ else:
datetime = strptime(lastplayed, "%Y-%m-%d
%H:%M:%S")
lastplayed = str(mktime(datetime))
continue
else:
- # this is the first unwatched item, check if it's
partially watched
+ # this is the first unwatched episode, check if the
episode is partially watched
playdate = item['lastplayed']
if (lastplayed == "") and (playdate == ""):
# it's a tv show with 0 watched episodes, continue
to the next tv show
@@ -144,7 +162,7 @@ class Main:
showtitle = item['showtitle']
rating = str(round(float(item['rating']),1))
episodeno = "s%se%s" % ( season, episode, )
- if not playdate == "":
+ if not playdate == '':
# if the episode is partially watched, use
it's playdate for sorting
datetime = strptime(playdate, "%Y-%m-%d
%H:%M:%S")
lastplayed = str(mktime(datetime))
@@ -164,8 +182,9 @@ class Main:
self.albumsids = {}
previousid = ''
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method":
"AudioLibrary.GetSongs", "params": {"properties": ["playcount", "albumid"],
"sort": { "method": "album" } }, "id": 1}')
+ json_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
- if json_response['result'].has_key('songs'):
+ if (json_response['result'] != None) and
(json_response['result'].has_key('songs')):
for item in json_response['result']['songs']:
albumid = item['albumid']
if albumid != '':
@@ -192,6 +211,7 @@ class Main:
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_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
if json_response['result'].has_key('albumdetails'):
item = json_response['result']['albumdetails']
@@ -214,6 +234,7 @@ class Main:
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_query = unicode(json_query, 'utf-8', errors='ignore')
json_response = simplejson.loads(json_query)
# create a playlist
playlist = xbmc.PlayList(0)
@@ -232,6 +253,15 @@ class Main:
# play the playlist
xbmc.Player().play( playlist )
+ def _daemon( self ):
+ # keep running until xbmc exits or another instance is started
+ while (not xbmc.abortRequested) and
self.WINDOW.getProperty('WatchList_Running') == 'True':
+ xbmc.sleep(1000)
+ if xbmc.abortRequested:
+ log('script stopped: xbmc quit')
+ else:
+ log('script stopped: new script instance started')
+
def _clear_movie_properties( self ):
for count in range( int(self.LIMIT) ):
count += 1
@@ -304,7 +334,23 @@ class Main:
# stop here if our list contains more items
break
+ def _update( self ):
+ log('playback stopped')
+ xbmc.sleep(500)
+ self._fetch_info()
+
+
+class MyPlayer(xbmc.Player):
+ def __init__( self, *args, **kwargs ):
+ xbmc.Player.__init__( self )
+ self.action = kwargs[ "action" ]
+
+ def onPlayBackEnded( self ):
+ self.action()
+
+ def onPlayBackStopped( self ):
+ self.action()
+
if ( __name__ == "__main__" ):
log('script version %s started' % __addonversion__)
Main()
-log('script stopped')
-----------------------------------------------------------------------
Summary of changes:
script.watchlist/README.txt | 5 ++
script.watchlist/addon.xml | 2 +-
script.watchlist/changelog.txt | 16 +++++++
script.watchlist/default.py | 98 +++++++++++++++++++++++++++++-----------
4 files changed, 94 insertions(+), 27 deletions(-)
hooks/post-receive
--
Scripts
------------------------------------------------------------------------------
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons