Permalink
Browse files

protection for player.play

  • Loading branch information...
killdash9
killdash9 committed Aug 17, 2012
1 parent 9b9c231 commit bdab93649eaedba6707a803c16679c8c5d244fb5
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<addon id="script.video.parentalcontrols" name="Parental Controls" version="1.4.10" provider-name="killdash9">
+<addon id="script.video.parentalcontrols" name="Parental Controls" version="1.4.11" provider-name="killdash9">
<requires>
<import addon="xbmc.python" version="2.0"/>
</requires>
@@ -1 +1 @@
-
+1.4.11 - Support for a wider range of video addons
@@ -41,6 +41,7 @@ def onAction(self, action):
def showComboDialog(title):
ui= ComboWinXML("DialogCode.xml", __addonpath__, "default", title)
+ common.closeProgressDialogIfOpen()
ui.doModal()
if (ui.ok):
code = ui.code
@@ -1,5 +1,6 @@
import xbmcaddon
import xbmc
+import xbmcgui
from os import path
__addon__ = xbmcaddon.Addon('script.video.parentalcontrols')
@@ -68,6 +69,8 @@ def removeProtectedPlugin(plugin):
tvRatings = ['All TV','TV-MA','TV-14','TV-PG','TV-G','TV-Y7-FV','TV-Y7','TV-Y']
def allowed(rating):
+ if not rating:
+ return False
rating = rating.upper()
try:
r = movieRatings.index(rating)
@@ -90,9 +93,21 @@ def allowed(rating):
return False
except:
#it's neither a TV rating nor a move rating. Let's log this
- print "Unrecognized rating: " + rating
return False
+def closeProgressDialogIfOpen():
+ progressDialog= None
+ progressDialogWindowId=10101
+ try:
+ progressDialog = xbmcgui.Window(progressDialogWindowId)
+ except:
+ #window not found
+ pass
+ if progressDialog:
+ #close progress dialog so it doesn't interfere
+ xbmc.executebuiltin( "Dialog.Close(%s,true)" % progressDialogWindowId )
+
+
def msg(s):
print s
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s, %s)' % ( "Parental Controls", s, 2000, __icon__) )
@@ -2,6 +2,7 @@
import common
import hook
import traceback
+import xbmcgui
def checkProtection():
plugins = common.getProtectedPlugins()
@@ -10,17 +11,35 @@ def checkProtection():
if (not state['hooked']) or not (state['uptodate']):
p=hook.hookPlugin(plugin)
common.msg("Re-protecting plugin " + p['name'])
-
+
+def closeProgressDialogIfInterfering():
+ pythonWindow = None
+ pythonWindowId=13000
+ try:
+ pythonWindow=xbmcgui.Window(pythonWindowId)
+ except:
+ pass
+ #window not found
+ if pythonWindow:
+ xmlfile = pythonWindow.getProperty('xmlfile')
+ codeDialogIsUp = xmlfile and xmlfile.find('DialogCode.xml')>=0
+ if codeDialogIsUp:
+ #close any other open dialogs so they don't interfere
+ common.closeProgressDialogIfOpen()
common.msg("Started")
lastMessage = time.time()
+counter=0
while (not xbmc.abortRequested):
try:
- checkProtection()
- time.sleep(10)
+ counter = counter+1
+ if counter % 10 == 0:
+ checkProtection()
+ closeProgressDialogIfInterfering()
+
except:
traceback.print_exc()
if (time.time() - lastMessage > 5*60): #we don't want to be too annoying with errors
common.msg("Error checking plugin protection status")
lastMessage = time.time()
- time.sleep(10)
+ time.sleep(1)
@@ -78,24 +78,27 @@ def allowed(wrappeditem, isFolder):
and wrappeditem.type.lower() == 'video'
and hasattr(wrappeditem, "infoLabels")
):
- #print wrappeditem.infoLabels
- for k in wrappeditem.infoLabels:
- if (k.lower() == "mpaa"):
- mpaa = wrappeditem.infoLabels[k]
- #print "Current settings: " + common.getMovieRating() + " " + common.getTVRating()
- if (not common.allowed(mpaa)):
- #print "Blocking rating " + mpaa
- addBlockedRating(mpaa)
- return False
- else:
- #print "Allowing rating " + mpaa
- return True
- #print "Couldn't find rating, returning isFolder: %s" % isFolder
+ rating=getMpaaRating(wrappeditem.infoLabels)
+ if rating:
+ if common.allowed(rating):
+ return True
+ else:
+ addBlockedRating(rating)
+ return False
if not isFolder:
addBlockedRating("Unknown Rating")
- return isFolder #allow folders
+ return False
+ return True #it's a folder, let it through
+ print "shouldn't get here"
return True #shouldn't happen
+# returns None if no rating
+def getMpaaRating(infoLabels):
+ for k in infoLabels:
+ if k.lower() == "mpaa":
+ return infoLabels[k]
+ return None
+
def unwrapTuple(t):
if (len(t) == 2):
return (t[0],t[1]._obj)
@@ -161,10 +164,21 @@ def wrapper_Player(*args,**kwargs):
cls=type("PlayerProxy",(Proxy,),{"play":wrapper_Player_play})
return cls(rv)
-def wrapper_Player_play(item = None, listitem = None, windowed = False):
+def wrapper_Player_play(self, item = None, listitem = None, windowed = False):
+
if (listitem and hasattr(listitem,"_obj")):
+ wrappeditem = listitem
+ rating=getMpaaRating(wrappeditem.infoLabels)
+ if not common.allowed(rating):
+ blockedRating = rating or "Unknown Rating"
+ if not codeui.unlockUI("Blocked (%s)" % blockedRating):
+ return None
+ setUnlockedTime(int(time.time()))
+ common.msg("Unlocked for 5 minutes")
+ #unwrap before delegating
listitem=listitem._obj
if (item and hasattr(item,"_obj")):
+ #unwrap before delegating
item = item._obj
return self._obj.play(item, listitem, windowed)

0 comments on commit bdab936

Please sign in to comment.