The branch, dharma has been updated
via e2c90e23285653e7b74f7c15de5921971d444095 (commit)
from 20a3b7e7bfbf88652209ff2e5ade42c4ad25cef3 (commit)
- Log -----------------------------------------------------------------
http://xbmc.git.sourceforge.net/git/gitweb.cgi?p=xbmc/scripts;a=commit;h=e2c90e23285653e7b74f7c15de5921971d444095
commit e2c90e23285653e7b74f7c15de5921971d444095
Author: amet <[email protected]>
Date: Tue Apr 5 22:37:08 2011 +0400
[script.mymediadb] -v0.1.4
- Added notifications, and now handles 404 exceptions. Fixed compabillity
issues with python 2.6
diff --git a/script.mymediadb/addon.xml b/script.mymediadb/addon.xml
index 186bfe0..caabbb8 100644
--- a/script.mymediadb/addon.xml
+++ b/script.mymediadb/addon.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon
id="script.mymediadb"
- version="0.1.3"
+ version="0.1.4"
name="MyMediaDB"
provider-name="mmdb"
>
@@ -16,7 +16,7 @@
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<summary>Sync your media collection with MyMediaDB.org</summary>
- <description>Sync your acquired and watched state of your videolibrary to
and from MyMediaDB.org Share your entertainment endavours with your friends and
family!</description>
+ <description>Sync your acquired and watched state of your videolibrary to
and from MyMediaDB.org Share your entertainment endavours with your friends and
family! Bugs can be reported at
http://mmbd-xbmc-addon.googlecode.com</description>
<disclaimer>An account at www.mymediadb.org is required!</disclaimer>
</extension>
</addon>
diff --git a/script.mymediadb/changelog.txt b/script.mymediadb/changelog.txt
index b8a3ff8..208c6df 100644
--- a/script.mymediadb/changelog.txt
+++ b/script.mymediadb/changelog.txt
@@ -1,8 +1,11 @@
+[B]0.1.4[/B]
+- Added notifications, and now handles 404 exceptions. Fixed compabillity
issues with python 2.6
+
[B]0.1.3[/B]
- Removed extra thread to prevent python from failing on exit. Added Testmode,
Testmode stops setting tags for media locally and remotly.
-[B]0.1.2[/B]
-- added basic cookie handling, enabling reuse of http session id's (JSESSIONID)
+[B]0.1.2[/B]
+- added basic cookie handling, enabling reuse of http session id's (JSESSIONID)
[B]0.1.1[/B]
- initial working version!
diff --git a/script.mymediadb/default.py b/script.mymediadb/default.py
index 27c4d5f..4ed055f 100644
--- a/script.mymediadb/default.py
+++ b/script.mymediadb/default.py
@@ -6,141 +6,25 @@ Licensed under GPL3
# Import statements
import sys
import os
-import time
import xbmc
-import xbmcaddon
import urllib2
-import base64
-import re
-import thread
-import simplejson as json
-try:
- from sqlite3 import dbapi2 as sqlite
- print "Loading sqlite3 as DB engine"
-except:
- from pysqlite2 import dbapi2 as sqlite
- print "Loading pysqlite2 as DB engine"
-
-# Functions
-def debug(txt):
- if(addon.getSetting('debug') == 'true'):
- try:
- print txt
- except:
- print "Unexpected error:", sys.exc_info()[0]
-
-def sleeper(millis):
- while (not xbmc.abortRequested and millis > 0):
- xbmc.sleep(1000)
- millis -= 1000
-
-def makeRequest(url):
- global session_cookie
- request = urllib2.Request(url)
- #debug('remote url='+url)
- if(session_cookie != None):
- request.add_header("Cookie", session_cookie)
-
- base64string = base64.encodestring('%s:%s' %
(addon.getSetting('username'), addon.getSetting('password'))).replace('\n', '')
- request.add_header("Authorization", "Basic %s" % base64string)
- request.add_header("Content-Type","text/json")
- return request
-
-def openRequest(request):
- global session_cookie
- opener = urllib2.build_opener()
- response = None
- try:
- response = opener.open(request)
- headers = response.info()
- if('set-cookie' in headers):
- session_cookie = headers['set-cookie']
- except urllib2.URLError, e:
- if(e.code == 401):
- xbmc.executebuiltin('Notification(%s,%s,%s,%s)' %
(addon.getAddonInfo('name'),e,3000,addon.getAddonInfo("icon")))
- return response
-
-
-def getRemoteMovieLibrary():
- request = makeRequest(apiurl+'/user')
- f = openRequest(request)
- if(f == None):
- return None
- library = json.load(f)['mediaLibrary']
- for i, media in enumerate(library):
-
#=======================================================================
- # debug("MEDIA")
- # debug(media)
-
#=======================================================================
- tags = getRemoteMovieTags(media['mediaId'])
-
#=======================================================================
- # debug("TAGS")
- # debug(tags)
-
#=======================================================================
- library[i].update(tags)
- return library
-
-def getRemoteMovieTags(mediaId):
- request =
makeRequest(apiurl+'/userMedia?mediaType=movie&idType=mmdb&id=%s' % mediaId)
- f = openRequest(request)
- if(f != None):
- return json.load(f)
- return None
-
-def setRemoteMovieTag(imdbId,postdata):
- if(addon.getSetting('testmode') == 'false'):
- request =
makeRequest(apiurl+'/userMedia?mediaType=movie&idType=imdb&id=%s' % imdbId)
- request.add_data(json.dumps(postdata))
- request.get_method = lambda: 'PUT'
- f = openRequest(request)
- if(f != None):
- json.load(f)
- else:
- debug('MMDB Testmode cancelled API request "setRemoteMovieTag"')
-
-
-def getLocalMovieLibrary():
- result = []
- connection = sqlite.connect(moviedb)
- cursor = connection.cursor()
- cursor.execute( "select movie.idMovie,movie.idFile,movie.c09 as
imdbId,movie.c00 as name, case when files.playCount > 0 then 1 else 0 end as
watched from movie left join files on (movie.idFile = files.idFile)")
- for row in cursor:
- result.append(createProperRowFromCursor(cursor,row))
- connection.close()
- return result
-
-def getLocalMovie(imdbId):
- result = None
- connection = sqlite.connect(moviedb)
- cursor = connection.cursor()
- cursor.execute( "select movie.idMovie,movie.idFile,movie.c09 as
imdbId,movie.c00 as name, case when files.playCount > 0 then 1 else 0 end as
watched from movie left join files on (movie.idFile = files.idFile) where
imdbId=?",(imdbId,))
- result = createProperRowFromCursor(cursor,cursor.fetchone())
- connection.close()
- return result
-
-def createProperRowFromCursor(cursor, row):
- if(row == None):
- return None
- d = {}
- for idx, col in enumerate(cursor.description):
- d[col[0]] = row[idx]
- return d
-
+from mymediadb.mmdb import MMDB
+from mymediadb.xbmcapp import XBMCApp
+from mymediadb.commonutils import debug,sleeper,addon
+
def remoteMovieExists(imdbId):
for remoteMedia in mmdb_library:
if(remoteMedia['imdbId'] == imdbId):
return True
return False
-def setLocalMovieAsWatched(idFile):
- if(addon.getSetting('testmode') == 'false'):
- connection = sqlite.connect(moviedb)
- cursor = connection.cursor()
- cursor.execute("update files SET playCount=1 where
idFile=?",(idFile,))
- connection.commit()
- connection.close()
- else:
- debug('MMDB Testmode cancelled API request "setLocalMovieAsWatched"')
+def movieUpdatedNotifications():
+ global updatedMovies
+ if(addon.getSetting('shownotifications') == 'true'):
+ moviesUpdatedCounter= updatedMovies.__len__()
+ del updatedMovies[:]
+ if(moviesUpdatedCounter > 0):
+ xbmc.executebuiltin('Notification(%s,%s,%s,%s)' %
(addon.getAddonInfo('name'),"%d movies updated on MMDB" %
(moviesUpdatedCounter),7000,addon.getAddonInfo("icon")))
#def periodicallyGetRemoteLibrary():
# while (not xbmc.abortRequested):
@@ -148,6 +32,23 @@ def setLocalMovieAsWatched(idFile):
# debug('perodically import of remote library initiated')
# mmdb_library = getRemoteMovieLibrary()
+def _setRemoteMovieTag(imdbId, postdata):
+ global recentlyFailedMovies
+ global updatedMovies
+
+ try:
+ if(imdbId not in recentlyFailedMovies):
+ mmdb.setRemoteMovieTag(imdbId,postdata)
+ updatedMovies += [imdbId] ## adding to updated list
+ return True
+ else:
+ debug('Movie was on failed list, and did not update')
+ except urllib2.URLError, e:
+ if(e.code == 404):
+ recentlyFailedMovies += [imdbId] #Adding movie to failed movies
list, these will not be updated next sync
+ debug('Adding movie to failed list.')
+ return False
+
def syncWithMMDB():
#define global access
global mmdb_library
@@ -155,23 +56,26 @@ def syncWithMMDB():
if(mmdb_library == None):
debug("mmdb_library = None, is api down/changed?")
return
+ anyRemoteChanges = False
+ anyLocalChanges = False
for remoteMedia in mmdb_library:
- anyRemoteChanges = False
- localMedia = getLocalMovie(remoteMedia['imdbId'])
+ localMedia = xbmcApp.getLocalMovie(remoteMedia['imdbId'])
if (localMedia != None):
debug('Media exists both locally and remotely -
('+remoteMedia['name']+')')
if not remoteMedia['acquired']:
debug('Setting remote media status to acquired')
- setRemoteMovieTag(remoteMedia['imdbId'],{'acquired':True})
+ _setRemoteMovieTag(remoteMedia['imdbId'],{'acquired':True})
+ anyRemoteChanges = True
if(remoteMedia['experienced'] != localMedia['watched']):
debug('watched status is not synchronized')
if(addon.getSetting('dontsyncwatched') == 'false'):
if(remoteMedia['experienced']):
debug('setting local media to watched')
- setLocalMovieAsWatched(localMedia['idFile'])
+ xbmcApp.setLocalMovieAsWatched(localMedia['idFile'])
+ anyLocalChanges = True
else:
debug ('setting remote media to watched')
-
setRemoteMovieTag(localMedia['imdbId'],{'experienced':localMedia['watched'] ==
1})
+
_setRemoteMovieTag(localMedia['imdbId'],{'experienced':localMedia['watched'] ==
1})
anyRemoteChanges = True
else:
debug('Cancelled synchronize of watched status due to
settings!')
@@ -180,33 +84,38 @@ def syncWithMMDB():
if(remoteMedia['acquired'] == True):
if(addon.getSetting('dontdeleteacquired') == 'false'):
debug('Acquired flag was removed from mmdb')
- setRemoteMovieTag(remoteMedia['imdbId'],{'acquired':False})
+
_setRemoteMovieTag(remoteMedia['imdbId'],{'acquired':False})
anyRemoteChanges = True
else:
debug('Acquired flag was not removed from mmdb due to
settings!')
#sync local media with remote db
- for localMedia in getLocalMovieLibrary():
+ for localMedia in xbmcApp.getLocalMovieLibrary():
if(remoteMovieExists(localMedia['imdbId'])):
continue
debug('Media exists only locally - ('+localMedia['name']+')')
- setRemoteMovieTag(localMedia['imdbId'],{'acquired': True,
'experienced':localMedia['watched'] == 1})
- anyRemoteChanges = True
+ if(_setRemoteMovieTag(localMedia['imdbId'],{'acquired': True,
'experienced':localMedia['watched'] == 1})):
+ anyRemoteChanges = True #if it _setRemoteMovieTag fails doesnt
set: anyRemoteChanges
+
+
+ movieUpdatedNotifications()
if(anyRemoteChanges):
- debug('--- SYNCED WITH MMDB ---')
- mmdb_library = getRemoteMovieLibrary() #sync local copy with changes
on remote
+ debug('--- MADE REMOTE UPDATE(S) ---')
+ mmdb_library = mmdb.getRemoteMovieLibrary() #sync local copy with
changes on remote
+ elif(anyLocalChanges):
+ debug('--- MADE LOCAL CHANGE(S) ---')
else:
debug('--- NO CHANGES DETECTED ---')
+
# Constants
-addon = xbmcaddon.Addon(id='script.mymediadb')
-apiurl = 'http://mymediadb.org/api/0.1'
-moviedb = xbmc.translatePath('special://database/%s' %
addon.getSetting('database'))
+mmdb = MMDB(addon.getSetting('username'),addon.getSetting('password'))
+xbmcApp = XBMCApp(xbmc.translatePath('special://database/%s' %
addon.getSetting('database')))
# Globals
mmdb_library = []
-session_cookie = None
-
+recentlyFailedMovies = []
+updatedMovies = []
# autoexecute addon on startup for older xbmc versions, remove this when
xbmc.service goes live
# Auto exec info
AUTOEXEC_PATH = xbmc.translatePath( 'special://home/userdata/autoexec.py' )
@@ -260,41 +169,34 @@ else:
autoexecfile.write (AUTOEXEC_SCRIPT.strip())
autoexecfile.close()
-# Print addon information
-print "[ADDON] '%s: version %s' initialized!" % (addon.getAddonInfo('name'),
addon.getAddonInfo('version'))
-xbmc.executebuiltin('Notification(%s,%s,%s,%s)' %
(addon.getAddonInfo('name'),'is running!',3000,addon.getAddonInfo("icon")))
-
-# Print debug info
-if(addon.getSetting('debug') == 'true'):
- print '---- '+addon.getAddonInfo('name')+'- DEBUG ----'
- print 'username=%s' % addon.getSetting('username')
- print 'moviedb=%s' % moviedb
- print '---- '+addon.getAddonInfo('name')+'- DEBUG ----'
-
-# Testmode
-if(addon.getSetting('testmode') == 'true'):
- debug('Testmode activated')
-
-# DontdeleteAqcuired
-if(addon.getSetting('dontdeleteacquired') == 'true'):
- debug('Dont delete aqcuired activated')
-
-# Dontsyncwatched
-if(addon.getSetting('dontsyncwatched') == 'true'):
- debug('Synching of wathched disabled')
-# Main logic
-debug('initial import of mmdb library')
-mmdb_library = getRemoteMovieLibrary() #initial fetch
-#thread.start_new_thread(periodicallyGetRemoteLibrary,()) Removed because
python error
-GRLCounter = 0
-while (not xbmc.abortRequested):
- syncWithMMDB()
- sleeper(300000) #5minutes
- GRLCounter += 1
- if(GRLCounter == 12): #60minutes
- mmdb_library = getRemoteMovieLibrary()
- debug('Scheduled import of mmdb library')
- GRLCounter = 0
+try:
+ # Print addon information
+ print "[ADDON] '%s: version %s' initialized!" %
(addon.getAddonInfo('name'), addon.getAddonInfo('version'))
+ if(addon.getSetting('shownotifications') == 'true'):
+ xbmc.executebuiltin('Notification(%s,%s,%s,%s)' %
(addon.getAddonInfo('name'),'is running!',3000,addon.getAddonInfo("icon")))
+
+ # Main logic
+ debug('initial import of mmdb library')
+ mmdb_library = mmdb.getRemoteMovieLibrary() #initial fetch
+
+ #thread.start_new_thread(periodicallyGetRemoteLibrary,()) Removed
because python error
+ syncWithMmdbRunsCounter= 0
-
\ No newline at end of file
+ while (not xbmc.abortRequested):
+ syncWithMMDB()
+ sleeper(300000) #5minutes
+ syncWithMmdbRunsCounter += 1
+ if(syncWithMmdbRunsCounter == 12): #60minutes
+ del recentlyFailedMovies[:] # Will clear the failedmovies list,
since we now got a newer remote medialibrary
+ mmdb_library = mmdb.getRemoteMovieLibrary()
+ debug('Scheduled import of mmdb library')
+ GRLCounter = 0
+
+except urllib2.URLError, e:
+ if(e.code == 401):
+ xbmc.executebuiltin('Notification(%s,%s,%s,%s)' %
(addon.getAddonInfo('name'),e,3000,addon.getAddonInfo("icon")))
+except Exception:
+ xbmc.executebuiltin('Notification(%s,%s,%s,%s)' %
(addon.getAddonInfo('name'),"An error occured.. check the logs!
exiting!",3000,addon.getAddonInfo("icon")))
+ sleeper(5000)
+ sys.exit(1)
\ No newline at end of file
diff --git a/script.mymediadb/resources/settings.xml
b/script.mymediadb/resources/settings.xml
index 0c0a30c..8405062 100644
--- a/script.mymediadb/resources/settings.xml
+++ b/script.mymediadb/resources/settings.xml
@@ -5,6 +5,7 @@
<setting id="username" type="text" label="Username" default="" />
<setting id="password" type="text" option="hidden" label="Password"
default="" />
<setting id="separator" type="lsep" label=""/>
+ <setting id="shownotifications" type="bool" label="Show all
notifications" default="true" />
<setting id="dontdeleteacquired" type="bool" label="Do not set
unacquired on mmdb when not existing locally" default="true" />
<setting id="dontsyncwatched" type="bool" label="Do not synchronise
watched status" default="false" />
</category>
-----------------------------------------------------------------------
Summary of changes:
script.mymediadb/addon.xml | 4 +-
script.mymediadb/changelog.txt | 7 +-
script.mymediadb/default.py | 260 ++++++--------------
.../mymediadb}/__init__.py | 0
script.mymediadb/mymediadb/commonutils.py | 37 +++
script.mymediadb/mymediadb/mmdb.py | 60 +++++
script.mymediadb/mymediadb/xbmcapp.py | 51 ++++
script.mymediadb/resources/settings.xml | 1 +
8 files changed, 237 insertions(+), 183 deletions(-)
copy {script.image.bigpictures/resources =>
script.mymediadb/mymediadb}/__init__.py (100%)
create mode 100644 script.mymediadb/mymediadb/commonutils.py
create mode 100644 script.mymediadb/mymediadb/mmdb.py
create mode 100644 script.mymediadb/mymediadb/xbmcapp.py
hooks/post-receive
--
Scripts
------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
Xbmc-addons mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xbmc-addons