2011-12-26 21:13:33 +01:00
|
|
|
import subprocess, settings, brlog, tempfile, os, threading, xbmcgui, urllib, re, xbmc, xbmcplugin
|
2011-12-26 12:45:54 +01:00
|
|
|
from functools import partial
|
|
|
|
|
|
|
|
class MakeMkvInteraction:
|
|
|
|
def __init__(self):
|
|
|
|
self.settings = settings.BluRaySettings()
|
|
|
|
self.log = brlog.BrLog('makemkvinteraction')
|
|
|
|
|
|
|
|
def discList(self):
|
|
|
|
# First stop any old one
|
|
|
|
self.killMkv()
|
|
|
|
tmpf = tempfile.NamedTemporaryFile(delete=True)
|
2011-12-26 21:13:33 +01:00
|
|
|
sp = os.system(r'%s -r --cache=1 --messages=%s info disc:10' %(self.settings.mkvLocation, tmpf.name))
|
2011-12-26 12:45:54 +01:00
|
|
|
|
|
|
|
tmpf = open(tmpf.name)
|
|
|
|
content = tmpf.read()
|
|
|
|
tmpf.close()
|
|
|
|
disclist = [x for x in content.splitlines() if x.startswith('DRV:')]
|
|
|
|
readableDiscs = list()
|
|
|
|
for item in disclist:
|
|
|
|
info = [x.replace('"','') for x in item[4:].split(',')]
|
|
|
|
if len(info[5]) > 0:
|
|
|
|
readableDiscs.append( (info[0],info[5]))
|
|
|
|
return readableDiscs
|
|
|
|
|
|
|
|
def startStream(self, disc):
|
|
|
|
self.log.info("Starting stream on disc %s with local url %s" %(disc, self.settings.rootURL))
|
|
|
|
# Then fork the makemkv process
|
|
|
|
return self.__runandregistershutdown('%s -r --cache=128 stream disc:%s' %(self.settings.mkvLocation, disc))
|
|
|
|
|
|
|
|
def startFileStream(self, choice):
|
|
|
|
type = ''
|
|
|
|
if re.search("BDMV.index.bdmv", choice) :
|
|
|
|
# Treat as file
|
|
|
|
type = 'file'
|
|
|
|
choice = choice[:-15]
|
|
|
|
elif re.search("BDMV.MovieObject.bdmv", choice) :
|
|
|
|
# Treat as file
|
|
|
|
type = 'file'
|
|
|
|
choice = choice[:-21]
|
|
|
|
else:
|
|
|
|
# Treat as iso
|
|
|
|
type = 'iso'
|
|
|
|
|
|
|
|
# Check if the file is reachable through the filesystem, to prevent errors with smb:// shares etc.
|
|
|
|
if not os.path.exists(choice) :
|
2011-12-26 21:13:33 +01:00
|
|
|
dialog = xbmcgui.Dialog()
|
2011-12-26 12:45:54 +01:00
|
|
|
dialog.ok("Info", _(50073))
|
|
|
|
return False
|
2011-12-26 21:13:33 +01:00
|
|
|
|
2011-12-26 12:45:54 +01:00
|
|
|
return self.__runandregistershutdown('"%s" -r --cache=128 stream \'%s:%s\'' %(self.settings.mkvLocation, type, choice))
|
|
|
|
|
|
|
|
|
|
|
|
def __runandregistershutdown(self, mkvStart):
|
|
|
|
result = self.__runmkvstream(mkvStart)
|
|
|
|
if result >= 0:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def __runmkvstream(self, mkvStart):
|
|
|
|
self.log.info('Starting %s' %(mkvStart))
|
|
|
|
# First stop any old one
|
|
|
|
self.killMkv()
|
|
|
|
timeSlept = 0
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
def killMkv(self):
|
|
|
|
# Linux
|
|
|
|
try :
|
2011-12-26 21:13:33 +01:00
|
|
|
self.log.info('attempting linux kill of makemkvcon')
|
2011-12-26 12:45:54 +01:00
|
|
|
subprocess.call('killall -9 makemkvcon', shell=True)
|
2011-12-26 21:13:33 +01:00
|
|
|
self.log.info('Linux call successful')
|
2011-12-26 12:45:54 +01:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
#Windows.
|
|
|
|
try :
|
2011-12-26 21:13:33 +01:00
|
|
|
self.log.info('attempting windows kill of makemkvcon')
|
2011-12-26 12:45:54 +01:00
|
|
|
subprocess.call('taskkill /F /IM makemkvcon.exe', shell=True)
|
2011-12-26 21:13:33 +01:00
|
|
|
self.log.info('Windows call successful')
|
2011-12-26 12:45:54 +01:00
|
|
|
except:
|
|
|
|
pass
|
2011-12-26 21:13:33 +01:00
|
|
|
|