-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault.py
116 lines (100 loc) · 3.31 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
#
# plugin.video.makemkvbluray
#
# Copyright (C) 2012 Adam Sutton <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ############################################################################
# Module Setup/Info
# ############################################################################
# Global imports
import os, sys, time
import urlparse
import xbmc, xbmcaddon, xbmcplugin, xbmcgui
# Addon info
__addon__ = xbmcaddon.Addon()
__cwd__ = __addon__.getAddonInfo('path')
sys.path.append(xbmc.translatePath(os.path.join(__cwd__, 'lib')))
# Local imports
import plugin, makemkv, makemkvcon
# Add directory
def addDir ( name, url, icon = '', folder = False):
li = xbmcgui.ListItem(name, iconImage=icon, thumbnailImage='')
li.setInfo(type='Video', infoLabels={ 'Title' : name })
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li)
# Add link
def addLink ( name, url, icon = '' ):
url = sys.argv[0] + url
li = xbmcgui.ListItem(name, iconImage=icon, thumbnailImage='')
li.setInfo(type='Video', infoLabels={ 'Title' : name })
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li)
# Add a title
def addTitle ( title, icon = 'DefaultVideo.png' ):
name = 'Title %d [%s]' % (title['id'], title['duration'])
url = title['file0']
li = xbmcgui.ListItem(name, iconImage=icon, thumbnailImage='')
li.setInfo(type='Video', infoLabels={ 'Title' : name })
li.setProperty('IsPlayable', 'true')
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=li)
# Parse query string
def parseQuery ():
ret = {}
if sys.argv[2].startswith('?'):
tmp = urlparse.parse_qs(sys.argv[2][1:])
for k in tmp:
ret[k] = tmp[k][0]
return ret
# Play a title
def playTitle ( title ):
plugin.log('playing %s' % title['file0'])
xbmc.executebuiltin('PlayMedia("%s")' % title['file0'])
# Check installed
plugin.log('checking makemkvcon installed')
if not makemkvcon.installed():
plugin.notify(plugin.lang(50001))
sys.exit(1)
# Start
makemkvcon.start()
# Check that service is running
st = time.time()
ok = False
# TODO: dialog
while not ok and (time.time() - st) < plugin.get_int('disc_timeout'):
plugin.log('waiting for makemkvcon')
ok = makemkvcon.ready()
time.sleep(0.5)
if not ok:
plugin.notify(plugin.lang(50006))
sys.exit(1)
plugin.log('makemkvcon ready')
# Process
params = parseQuery()
# Get titles
titles = makemkvcon.listTitles()
plugin.log('titles = %s' % str(titles))
if not titles:
plugin.notify(plugin.lang(50007))
# List?
if not plugin.get_bool('disc_autoplay'):
for t in titles:
addTitle(t)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
# Play longest
else:
title = None
for t in titles:
if not title or t['length'] > title['length']:
title = t
if title:
playTitle(title)