syntax corrections and version bump

This commit is contained in:
desolat 2012-10-06 12:21:30 +02:00
parent dab2624c88
commit ad4637f4cf
15 changed files with 1960 additions and 1950 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*.pyo
*.pyc
.*

View file

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.makemkvbluray" name="BluRay Player with MakeMKV"
version="1.1.0" provider-name="Magnetism">
<addon
id="plugin.makemkvbluray"
name="BluRay Player with MakeMKV"
version="1.1.1"
provider-name="desolat">
<requires>
<import addon="xbmc.python" version="2.0" />
</requires>
@ -11,7 +14,7 @@
</extension>
<extension point="xbmc.addon.metadata">
<summary>Play BluRays from XBMC with MakeMKV</summary>
<description>Awesomeness </description>
<description>Uses MakeMKV streaming ability to play BlueRay Discs</description>
<platform>all</platform>
</extension>
</addon>

View file

@ -3,7 +3,7 @@ import xbmcplugin, xbmcaddon
__scriptname__ = "MakeMKV BluRay Watch Plugin"
__scriptID__ = "plugin.makemkvbluray"
__scriptID__ = "plugin.makemkvbluray"
__author__ = "Magnetism"
__url__ = "http://bultsblog.com/arne"
__credits__ = ""
@ -24,166 +24,166 @@ _log = brlog.BrLog()
_log.info('Starting the BluRay script')
class BluRayStarter:
def __init__(self):
_log.info('Staring')
self.settings = settings.BluRaySettings()
self.makemkv = makemkv.MakeMkvInteraction()
def killAndStart(self, mkvStart):
if self.settings.local:
_log.info('Running makemkvcon locally')
self.killMkv()
# Determine if we're doing the disc or if we're browsing..
_log.info(mkvStart)
return subprocess.Popen(mkvStart, shell=True)
else:
_log.info('connecting to remote stream, returning fake file browse class..')
return file.FakeFile()
def killMkv(self):
# Linux
try :
_log.info('attempting linux kill of makemkvcon')
subprocess.call('killall -9 makemkvcon', shell=True)
_log.info('Linux call successful')
except:
pass
#Windows.
try :
_log.info('attempting windows kill of makemkvcon')
subprocess.call('taskkill /F /IM makemkvcon.exe', shell=True)
_log.info('Windows call successful')
except:
pass
def browse(self, url) :
_log.info('starting browser handler')
h = mkvparser.BrowseHandler()
h.start(url)
for k,v in h.titleMap.iteritems() : #@UnusedVariable
self.addLink("%s %s, %s %s" %(_(50005), v['duration'], _(50006), v['chaptercount']),v['file'])
def getMainFeatureTitle(self, url):
h = mkvparser.BrowseHandler()
h.start(url)
# Play the longest feature on the disc:
largest = 0
largestTitle = ''
for k,v in h.titleMap.iteritems() : #@UnusedVariable
m = re.search('(\d+):(\d+):(\d+)', v['duration'])
length = int(m.group(1)) * 3600 + int(m.group(2)) * 60 + int(m.group(3))
if length > largest :
largest = length
largestTitle = v['file']
_log.info('largest: %d, %s' %(largest,largestTitle))
return largestTitle
def handleListing(self):
mode = self.settings.paramMode
_log.info( 'mode: ' + str(mode))
if mode ==None:
_log.info('Showing categories')
self.CATEGORIES()
_log.info('Showing categories done')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
if mode == 1 :
_log.info( 'Entering Disc mode')
self.process(self.makemkv.startStream(self.settings.disc))
elif mode == 3 :
_log.info( 'Entering Remote mode')
mystarter = BluRayStarter()
mystarter.process('')
elif mode == 2:
_log.info( 'Entering Browse mode')
d = xbmcgui.Dialog()
choice = d.browse(1, 'Select folder', 'video', 'index.bdmv|.iso|.isoRenamedMeansSkip!|.MDS|.CUE|.CDI|.CCD', False, False, '')
if choice <> '':
self.process(self.makemkv.startFileStream(choice))
if mode == 20:
self.settings.showSettings()
def process(self, ready):
try :
if ready:
_log.info( 'Stream ready. ')
# the Stream has started, start auto playback?
if self.settings.autoPlay:
_log.info( 'Autoplay selected')
title = self.getMainFeatureTitle(self.settings.rootURL)
_log.info( 'Main feature determined to be : ' + title)
opener = urllib.URLopener()
testfile = ''
try:
testfile = title
opener.open(testfile)
except IOError:
testfile = ''
del opener
if testfile<>'':
_log.info( 'Playing file ' + testfile)
li = xbmcgui.ListItem(path = testfile)
li.setProperty('IsPlayable', 'true')
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li)
else:
self.message(_(50071))
xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem())
def __init__(self):
_log.info('Staring')
self.settings = settings.BluRaySettings()
self.makemkv = makemkv.MakeMkvInteraction()
def killAndStart(self, mkvStart):
if self.settings.local:
_log.info('Running makemkvcon locally')
self.killMkv()
# Determine if we're doing the disc or if we're browsing..
_log.info(mkvStart)
return subprocess.Popen(mkvStart, shell=True)
else:
# Add the selections as selectable files.
self.browse(self.settings.rootURL)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
_log.info('connecting to remote stream, returning fake file browse class..')
return file.FakeFile()
def killMkv(self):
# Linux
try :
_log.info('attempting linux kill of makemkvcon')
subprocess.call('killall -9 makemkvcon', shell=True)
_log.info('Linux call successful')
except:
pass
#Windows.
try :
_log.info('attempting windows kill of makemkvcon')
subprocess.call('taskkill /F /IM makemkvcon.exe', shell=True)
_log.info('Windows call successful')
except:
pass
def browse(self, url) :
_log.info('starting browser handler')
h = mkvparser.BrowseHandler()
h.start(url)
for k,v in h.titleMap.iteritems() : #@UnusedVariable
self.addLink("%s %s, %s %s" %(_(50005), v['duration'], _(50006), v['chaptercount']),v['file'])
except :
self.message(_(50072))
self.pDialog.close()
xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem())
raise
def getMainFeatureTitle(self, url):
h = mkvparser.BrowseHandler()
h.start(url)
# Play the longest feature on the disc:
largest = 0
largestTitle = ''
for k,v in h.titleMap.iteritems() : #@UnusedVariable
m = re.search('(\d+):(\d+):(\d+)', v['duration'])
length = int(m.group(1)) * 3600 + int(m.group(2)) * 60 + int(m.group(3))
if length > largest :
largest = length
largestTitle = v['file']
_log.info('largest: %d, %s' %(largest,largestTitle))
return largestTitle
def CATEGORIES(self):
# Disc
if self.settings.enableDisc:
disclist = self.makemkv.discList()
for disc in disclist:
self.addDir(_(50061) %(disc[0], disc[1]),1, True, disc[0], disc[1])
for disc in disclist:
self.addDir(_(50062) %(disc[0], disc[1]),1, False, disc[0], disc[1])
# Filelocation
if self.settings.enableFile:
self.addDir(_(50063),2, True)
self.addDir(_(50064),2, False)
self.addDir(_(50060),20, True, '0', 'settings', False)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def handleListing(self):
mode = self.settings.paramMode
_log.info( 'mode: ' + str(mode))
if mode == None:
_log.info('Showing categories')
self.CATEGORIES()
_log.info('Showing categories done')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
if mode == 1 :
_log.info( 'Entering Disc mode')
self.process(self.makemkv.startStream(self.settings.disc))
elif mode == 3 :
_log.info( 'Entering Remote mode')
mystarter = BluRayStarter()
mystarter.process('')
elif mode == 2:
_log.info( 'Entering Browse mode')
d = xbmcgui.Dialog()
choice = d.browse(1, 'Select folder', 'video', 'index.bdmv|.iso|.isoRenamedMeansSkip!|.MDS|.CUE|.CDI|.CCD', False, False, '')
if choice <> '':
self.process(self.makemkv.startFileStream(choice))
if mode == 20:
self.settings.showSettings()
def process(self, ready):
try :
if ready:
_log.info( 'Stream ready. ')
# the Stream has started, start auto playback?
if self.settings.autoPlay:
_log.info( 'Autoplay selected')
title = self.getMainFeatureTitle(self.settings.rootURL)
_log.info( 'Main feature determined to be : ' + title)
opener = urllib.URLopener()
testfile = ''
try:
testfile = title
opener.open(testfile)
except IOError:
testfile = ''
del opener
if testfile<>'':
_log.info( 'Playing file ' + testfile)
li = xbmcgui.ListItem(path = testfile)
li.setProperty('IsPlayable', 'true')
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li)
else:
self.message(_(50071))
xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem())
else:
# Add the selections as selectable files.
self.browse(self.settings.rootURL)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def addDir(self, name,mode, autoplay, disc = '0', disc_title ='idontknow', isPlayable = True):
u=sys.argv[0]+"?mode="+str(mode)+"&autoplay="+urllib.quote_plus(str(autoplay)) + "&disc=" + disc
_log.info(u)
icon = "DefaultVideoPlaylists.png"
if autoplay:
icon= "DefaultVideo.png"
liz=xbmcgui.ListItem(name, iconImage=icon, thumbnailImage='')
if autoplay and isPlayable:
liz.setProperty("IsPlayable", "true")
liz.setInfo( type="Video", infoLabels={ "Title": name } )
_log.info(name)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz, isFolder= not autoplay)
except :
self.message(_(50072))
self.pDialog.close()
xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem())
raise
def CATEGORIES(self):
# Disc
if self.settings.enableDisc:
disclist = self.makemkv.discList()
for disc in disclist:
self.addDir(_(50061) %(disc[0], disc[1]),1, True, disc[0], disc[1])
for disc in disclist:
self.addDir(_(50062) %(disc[0], disc[1]),1, False, disc[0], disc[1])
# Filelocation
if self.settings.enableFile:
self.addDir(_(50063),2, True)
self.addDir(_(50064),2, False)
self.addDir(_(50060),20, True, '0', 'settings', False)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def addLink(self, name,url):
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage='')
liz.setInfo( type="Video", infoLabels={ "Title": name } )
liz.setProperty("IsPlayable" , "true")
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
def addDir(self, name,mode, autoplay, disc = '0', disc_title ='idontknow', isPlayable = True):
u=sys.argv[0]+"?mode="+str(mode)+"&autoplay="+urllib.quote_plus(str(autoplay)) + "&disc=" + disc
_log.info(u)
icon = "DefaultVideoPlaylists.png"
if autoplay:
icon= "DefaultVideo.png"
liz=xbmcgui.ListItem(name, iconImage=icon, thumbnailImage='')
if autoplay and isPlayable:
liz.setProperty("IsPlayable", "true")
liz.setInfo( type="Video", infoLabels={ "Title": name } )
_log.info(name)
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz, isFolder= not autoplay)
def message(self, messageText):
dialog = xbmcgui.Dialog()
dialog.ok("Info", messageText)
def addLink(self, name,url):
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage='')
liz.setInfo( type="Video", infoLabels={ "Title": name } )
liz.setProperty("IsPlayable" , "true")
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
def message(self, messageText):
dialog = xbmcgui.Dialog()
dialog.ok("Info", messageText)
_log.info("args")
for arg in sys.argv:

View file

@ -0,0 +1,5 @@
'''
Created on 06.10.2012
@author: desolat
'''

View file

@ -1,32 +1,32 @@
class BrLog:
__DEBUG = 0
__INFO = 1
__WARN = 2
__ERROR = 3
__DEBUG = 0
__INFO = 1
__WARN = 2
__ERROR = 3
def __init__(self, prefix = ''):
self.logLevel = self.__INFO
if prefix <> '':
prefix = '-' + prefix
self.prefix = prefix
def __init__(self, prefix = ''):
self.logLevel = self.__INFO
if prefix <> '':
prefix = '-' + prefix
self.prefix = prefix
def setLevel(self, level):
if level >= 0 and level <= 3:
self.logLevel = level
def setLevel(self, level):
if level >= 0 and level <= 3:
self.logLevel = level
def info(self, message):
self.log(message, self.__INFO)
def info(self, message):
self.log(message, self.__INFO)
def debug(self, message):
self.log(message, self.__DEBUG)
def debug(self, message):
self.log(message, self.__DEBUG)
def error(self, message):
self.log(message, self.__ERROR)
def error(self, message):
self.log(message, self.__ERROR)
def warn(self, message):
self.log(message, self.__WARN)
def warn(self, message):
self.log(message, self.__WARN)
def log(self, message, level):
if self.logLevel <= level:
print '[BR%s %d] %s' %(self.prefix, level, message)
def log(self, message, level):
if self.logLevel <= level:
print '[BR%s %d] %s' %(self.prefix, level, message)

View file

@ -1,6 +1,6 @@
class FakeFile:
def poll(self):
return False
def poll(self):
return False
def communicate(self):
return '', ''
def communicate(self):
return '', ''

View file

@ -67,37 +67,37 @@ class MakeMkvInteraction:
proc = subprocess.Popen(mkvStart, shell=True)
# Then wait for the stream to come up
while True:
try:
urllib.urlretrieve(self.settings.rootURL)
return proc.pid
except IOError:
pass
if proc.poll() :
if proc.proc != 0 :
self.message(_(50070))
return -1
xbmc.sleep(1000)
timeSlept = timeSlept + 1
if timeSlept > self.settings.waitTimeOut :
return -1
try:
urllib.urlretrieve(self.settings.rootURL)
return proc.pid
except IOError:
pass
if proc.poll() :
if proc.proc != 0 :
self.message(_(50070))
return -1
xbmc.sleep(1000)
timeSlept = timeSlept + 1
if timeSlept > self.settings.waitTimeOut :
return -1
def killMkv(self):
# Linux
try :
self.log.info('attempting linux kill of makemkvcon')
subprocess.call('killall -9 makemkvcon', shell=True)
self.log.info('Linux call successful')
except:
pass
# Linux
try :
self.log.info('attempting linux kill of makemkvcon')
subprocess.call('killall -9 makemkvcon', shell=True)
self.log.info('Linux call successful')
except:
pass
#Windows.
try :
self.log.info('attempting windows kill of makemkvcon')
subprocess.call('taskkill /F /IM makemkvcon.exe', shell=True)
self.log.info('Windows call successful')
except:
pass
#Windows.
try :
self.log.info('attempting windows kill of makemkvcon')
subprocess.call('taskkill /F /IM makemkvcon.exe', shell=True)
self.log.info('Windows call successful')
except:
pass
def makeMkvExists(self):
(fin, fout) = os.popen4('%s -r' %(self.settings.mkvLocation))
@ -107,7 +107,7 @@ class MakeMkvInteraction:
self.log.info("MakeMkvCon found!")
return True
else:
self.log.info('MakeMkvcon seems not to be configured properly : %s' %(self.settings.mkvLocation))
self.log.info('MakeMkvcon seems not to be configured properly : %s'
% (self.settings.mkvLocation))
return False

View file

@ -1,56 +1,56 @@
import urllib, re, elementtree.ElementTree as ET
class BrowseHandler:
def __init__(self) :
self.catchCharData = False
self.keyColumn = False
self.map = {}
self.lastKey = ''
self.lastVal = ''
self.titleMap = {}
def __init__(self) :
self.catchCharData = False
self.keyColumn = False
self.map = {}
self.lastKey = ''
self.lastVal = ''
self.titleMap = {}
def start(self, url, title = 'none'):
# Initialize all locals
self.catchCharData = False
self.keyColumn = False
self.map[url] = {}
self.currMap = self.map[url]
self.lastKey = ''
self.lastVal = ''
filename, headers = urllib.urlretrieve(url)
del headers
def start(self, url, title = 'none'):
# Initialize all locals
self.catchCharData = False
self.keyColumn = False
self.map[url] = {}
self.currMap = self.map[url]
self.lastKey = ''
self.lastVal = ''
filename, headers = urllib.urlretrieve(url)
del headers
XML = ET.parse(filename)
elems = XML.getiterator(tag='{http://www.w3.org/1999/xhtml}td')
for each in elems:
self.keyColumn = not self.keyColumn
if self.keyColumn:
self.lastKey = each.text
else:
txt = ''
# Check for href:
refs = each.getiterator(tag='{http://www.w3.org/1999/xhtml}a')
for ref in refs:
txt = ref.get('href')
XML = ET.parse(filename)
elems = XML.getiterator(tag='{http://www.w3.org/1999/xhtml}td')
for each in elems:
self.keyColumn = not self.keyColumn
if self.keyColumn:
self.lastKey = each.text
else:
txt = ''
# Check for href:
refs = each.getiterator(tag='{http://www.w3.org/1999/xhtml}a')
for ref in refs:
txt = ref.get('href')
if txt == '' :
txt = each.text
if txt == '' :
txt = each.text
self.currMap[self.lastKey] = txt
self.currMap[self.lastKey] = txt
# Now do some processing:
for k, v in self.map[url].iteritems() :
if k == 'titles':
# go straight ahead and parse some more:
self.start(v)
if re.search('title\d+', k) :
self.titleMap[k] = {}
self.start(v, k)
if title != 'none':
if k == 'duration':
self.titleMap[title]['duration'] = v
elif k == 'file0':
self.titleMap[title]['file'] = v
elif k == 'chaptercount':
self.titleMap[title]['chaptercount'] = v
# Now do some processing:
for k, v in self.map[url].iteritems() :
if k == 'titles':
# go straight ahead and parse some more:
self.start(v)
if re.search('title\d+', k) :
self.titleMap[k] = {}
self.start(v, k)
if title != 'none':
if k == 'duration':
self.titleMap[title]['duration'] = v
elif k == 'file0':
self.titleMap[title]['file'] = v
elif k == 'chaptercount':
self.titleMap[title]['chaptercount'] = v

View file

@ -3,79 +3,79 @@ import sys
import urllib
import brlog
__scriptID__ = sys.modules[ "__main__" ].__scriptID__
__scriptID__ = sys.modules[ "__main__" ].__scriptID__
class BluRaySettings:
def __init__(self):
addon = xbmcaddon.Addon(__scriptID__)
self.log = brlog.BrLog('settings')
self.log.info('reading settings')
def __init__(self):
addon = xbmcaddon.Addon(__scriptID__)
self.log = brlog.BrLog('settings')
self.log.info('reading settings')
params = self.getParams()
if len(sys.argv) >= 2:
self.handle = int(sys.argv[1])
self.paramUrl = self.getParam(params, 'url')
self.paramName = self.getParam(params, "name")
self.paramMode = self.getIntParam(params, "mode")
self.autoPlay = self.getBoolParam(params, "autoplay")
self.disc = self.getParam(params, "disc")
self.local = True
self.portNumber = addon.getSetting('port_number')
self.ipAddress = '127.0.0.1'
params = self.getParams()
if len(sys.argv) >= 2:
self.handle = int(sys.argv[1])
self.paramUrl = self.getParam(params, 'url')
self.paramName = self.getParam(params, "name")
self.paramMode = self.getIntParam(params, "mode")
self.autoPlay = self.getBoolParam(params, "autoplay")
self.disc = self.getParam(params, "disc")
self.local = True
self.portNumber = addon.getSetting('port_number')
self.ipAddress = '127.0.0.1'
self.mkvLocation = addon.getSetting('mkvlocation')
self.rootURL = 'http://%s:%s/' % (self.ipAddress, self.portNumber)
self.waitTimeOut = int(addon.getSetting('wait_timeout'))
self.mkvLocation = addon.getSetting('mkvlocation')
self.rootURL = 'http://%s:%s/' % (self.ipAddress, self.portNumber)
self.waitTimeOut = int(addon.getSetting('wait_timeout'))
# Sections:
self.enableDisc = addon.getSetting('support_disc') == "true"
self.enableFile = addon.getSetting('support_fileselect') == "true"
# Sections:
self.enableDisc = addon.getSetting('support_disc') == "true"
self.enableFile = addon.getSetting('support_fileselect') == "true"
def getParam(self, params, name):
try:
result = params[name]
result = urllib.unquote_plus(result)
return result
except:
return None
def getParam(self, params, name):
try:
result = params[name]
result = urllib.unquote_plus(result)
return result
except:
return None
def getIntParam (self, params, name):
try:
param = self.getParam(params,name)
self.log.debug(name + ' = ' + param)
return int(param)
except:
return None
def getIntParam (self, params, name):
try:
param = self.getParam(params,name)
self.log.debug(name + ' = ' + param)
return int(param)
except:
return None
def getBoolParam (self, params, name):
try:
param = self.getParam(params,name)
self.log.debug(name + ' = ' + param)
return 'True' == param
except:
return None
def getBoolParam (self, params, name):
try:
param = self.getParam(params,name)
self.log.debug(name + ' = ' + param)
return 'True' == param
except:
return None
def getParams(self):
try:
param=[]
paramstring=sys.argv[2]
self.log.info('raw param string: ' + paramstring)
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
except:
return []
def getParams(self):
try:
param=[]
paramstring=sys.argv[2]
self.log.info('raw param string: ' + paramstring)
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
except:
return []
def showSettings(self):
xbmcaddon.Addon(__scriptID__).openSettings(sys.argv[ 0 ])
def showSettings(self):
xbmcaddon.Addon(__scriptID__).openSettings(sys.argv[ 0 ])

View file

@ -20,6 +20,7 @@ _log = brlog.BrLog('tracker service')
_log.info('Starting the BluRay tracker service')
class MyPlayer(xbmc.Player):
def __init__(self):
xbmc.Player.__init__(self)
@ -37,7 +38,7 @@ class MyPlayer(xbmc.Player):
myPlayer = MyPlayer()
xbmc.sleep(4)
if not makemkv.MakeMkvInteraction().makeMkvExists():
imagePath = os.path.join(__addon__.getAddonInfo('path'),'resources','images', 'alerticon.png')
imagePath = os.path.join(__addon__.getAddonInfo('path'), 'resources', 'images', 'alerticon.png')
xbmc.executebuiltin('Notification("MakeMkv", "The MakeMKV bluray plugin cannot find MakeMkv. Please configure the plugin to point to it", "15000", "%s")' % (imagePath))
while (not xbmc.abortRequested):