This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
forked from desolat/plugin.makemkvbluray
-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.py
194 lines (164 loc) · 7.11 KB
/
default.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import xbmc, xbmcgui, subprocess, os, time, sys, urllib, re
import xbmcplugin, xbmcaddon
__scriptname__ = "MakeMKV BluRay Watch Plugin"
__scriptID__ = "plugin.makemkvbluray"
__author__ = "Magnetism"
__url__ = "http://bultsblog.com/arne"
__credits__ = ""
__version__ = "0.1"
__addon__ = xbmcaddon.Addon(__scriptID__)
# Shared resources
BASE_RESOURCE_PATH = os.path.join( __addon__.getAddonInfo('path'), "resources" )
sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib" ) )
__language__ = __addon__.getLocalizedString
_ = sys.modules[ "__main__" ].__language__
import settings, file, mkvparser, brlog, makemkv
_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())
else:
# Add the selections as selectable files.
self.browse(self.settings.rootURL)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
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 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 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:
_log.info(arg)
_log.info("done args")
mydisplay = BluRayStarter()
mydisplay.handleListing()