forked from AddonScriptorDE/plugin.program.chrome.launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.py
executable file
·253 lines (219 loc) · 9.64 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib
import sys
import re
import os
import subprocess
import xbmcplugin
import xbmcgui
import xbmcaddon
addon = xbmcaddon.Addon()
pluginhandle = int(sys.argv[1])
addonID = addon.getAddonInfo('id')
addonPath = addon.getAddonInfo('path')
translation = addon.getLocalizedString
useOwnProfile = addon.getSetting("useOwnProfile") == "true"
useCustomPath = addon.getSetting("useCustomPath") == "true"
customPath = xbmc.translatePath(addon.getSetting("customPath"))
userDataFolder = xbmc.translatePath("special://profile/addon_data/"+addonID)
profileFolder = os.path.join(userDataFolder, 'profile')
siteFolder = os.path.join(userDataFolder, 'sites')
if not os.path.isdir(userDataFolder):
os.mkdir(userDataFolder)
if not os.path.isdir(profileFolder):
os.mkdir(profileFolder)
if not os.path.isdir(siteFolder):
os.mkdir(siteFolder)
youtubeUrl = "http://www.youtube.com/leanback"
vimeoUrl = "http://www.vimeo.com/couchmode"
osWin = xbmc.getCondVisibility('system.platform.windows')
osOsx = xbmc.getCondVisibility('system.platform.osx')
osLinux = xbmc.getCondVisibility('system.platform.linux')
def find_exe(pathlist):
for path in pathlist:
if os.path.isfile(path) and os.access(path, os.X_OK):
return path
return None
exePath = None
if useCustomPath:
exePath=find_exe([customPath,])
elif osWin:
exePath = find_exe(['C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'])
elif osOsx:
exePath = find_exe(["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",])
elif osLinux:
exePath = find_exe(["/usr/bin/google-chrome",])
if exePath is None:
xbmc.executebuiltin('XBMC.Notification(Info:,'+str(translation(30005))+'!,5000)')
addon.openSettings()
def index():
files = os.listdir(siteFolder)
for file in files:
if file.endswith(".link"):
fh = open(os.path.join(siteFolder, file), 'r')
title = ""
url = ""
thumb = ""
kiosk = "yes"
stopPlayback = "no"
for line in fh.readlines():
entry = line[:line.find("=")]
content = line[line.find("=")+1:]
if entry == "title":
title = content.strip()
elif entry == "url":
url = content.strip()
elif entry == "thumb":
thumb = content.strip()
elif entry == "kiosk":
kiosk = content.strip()
elif entry == "stopPlayback":
stopPlayback = content.strip()
fh.close()
addSiteDir(title, url, 'showSite', thumb, stopPlayback, kiosk)
addDir("[ Vimeo Couchmode ]", vimeoUrl, 'showSite', os.path.join(addonPath, "vimeo.png"), "yes", "yes")
addDir("[ Youtube Leanback ]", youtubeUrl, 'showSite', os.path.join(addonPath, "youtube.png"), "yes", "yes")
addDir("[B]- "+translation(30001)+"[/B]", "", 'addSite', "")
xbmcplugin.endOfDirectory(pluginhandle)
def addSite(site="", title=""):
if site:
filename = getFileName(title)
content = "title="+title+"\nurl="+site+"\nthumb=DefaultFolder.png\nstopPlayback=no\nkiosk=yes"
fh = open(os.path.join(siteFolder, filename+".link"), 'w')
fh.write(content)
fh.close()
else:
keyboard = xbmc.Keyboard('', translation(30003))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
title = keyboard.getText()
keyboard = xbmc.Keyboard('http://', translation(30004))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
url = keyboard.getText()
keyboard = xbmc.Keyboard('no', translation(30009))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
stopPlayback = keyboard.getText()
keyboard = xbmc.Keyboard('yes', translation(30016))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
kiosk = keyboard.getText()
content = "title="+title+"\nurl="+url+"\nthumb=DefaultFolder.png\nstopPlayback="+stopPlayback+"\nkiosk="+kiosk
fh = open(os.path.join(siteFolder, getFileName(title)+".link"), 'w')
fh.write(content)
fh.close()
xbmc.executebuiltin("Container.Refresh")
def getFileName(title):
return (''.join(c for c in unicode(title, 'utf-8') if c not in '/\\:?"*|<>')).strip()
def getFullPath(exePath, url, useKiosk, userAgent):
args = [exePath,]
if useOwnProfile:
args.append('--user-data-dir=%s' % profileFolder)
if useKiosk == 'yes':
args.append('--kiosk')
if userAgent:
args.append('--user-agent="%s" % userAgent')
args+=['--start-maximized', '--disable-translate', '--disable-new-tab-first-run', '--no-default-browser-check', '--no-first-run', url]
return args
def showSite(url, stopPlayback, kiosk, userAgent):
if stopPlayback == "yes":
xbmc.Player().stop()
params = getFullPath(exePath, url, kiosk, userAgent)
s = subprocess.Popen(params, shell=False)
s.communicate()
xbmcplugin.endOfDirectory(pluginhandle)
xbmc.executebuiltin("ReplaceWindow(Programs,%s)" % ("plugin://"+addonID+"/"))
def removeSite(title):
os.remove(os.path.join(siteFolder, getFileName(title)+".link"))
xbmc.executebuiltin("Container.Refresh")
def editSite(title):
filenameOld = getFileName(title)
file = os.path.join(siteFolder, filenameOld+".link")
fh = open(file, 'r')
title = ""
url = ""
kiosk = "yes"
thumb = "DefaultFolder.png"
stopPlayback = "no"
for line in fh.readlines():
entry = line[:line.find("=")]
content = line[line.find("=")+1:]
if entry == "title":
title = content.strip()
elif entry == "url":
url = content.strip()
elif entry == "kiosk":
kiosk = content.strip()
elif entry == "thumb":
thumb = content.strip()
elif entry == "stopPlayback":
stopPlayback = content.strip()
fh.close()
oldTitle = title
keyboard = xbmc.Keyboard(title, translation(30003))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
title = keyboard.getText()
keyboard = xbmc.Keyboard(url, translation(30004))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
url = keyboard.getText()
keyboard = xbmc.Keyboard(stopPlayback, translation(30009))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
stopPlayback = keyboard.getText()
keyboard = xbmc.Keyboard(kiosk, translation(30016))
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText():
kiosk = keyboard.getText()
content = "title="+title+"\nurl="+url+"\nthumb="+thumb+"\nstopPlayback="+stopPlayback+"\nkiosk="+kiosk
fh = open(os.path.join(siteFolder, getFileName(title)+".link"), 'w')
fh.write(content)
fh.close()
if title != oldTitle:
os.remove(os.path.join(siteFolder, filenameOld+".link"))
xbmc.executebuiltin("Container.Refresh")
def parameters_string_to_dict(parameters):
paramDict = {}
if parameters:
paramPairs = parameters[1:].split("&")
for paramsPair in paramPairs:
paramSplits = paramsPair.split('=')
if (len(paramSplits)) == 2:
paramDict[paramSplits[0]] = paramSplits[1]
return paramDict
def addDir(name, url, mode, iconimage, stopPlayback="", kiosk=""):
u = sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+urllib.quote_plus(mode)+"&stopPlayback="+urllib.quote_plus(stopPlayback)+"&kiosk="+urllib.quote_plus(kiosk)
ok = True
liz = xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo(type="Video", infoLabels={"Title": name})
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True)
return ok
def addSiteDir(name, url, mode, iconimage, stopPlayback, kiosk):
u = sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+urllib.quote_plus(mode)+"&stopPlayback="+urllib.quote_plus(stopPlayback)+"&kiosk="+urllib.quote_plus(kiosk)
ok = True
liz = xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo(type="Video", infoLabels={"Title": name})
liz.addContextMenuItems([(translation(30006), 'RunPlugin(plugin://'+addonID+'/?mode=editSite&url='+urllib.quote_plus(name)+')',), (translation(30002), 'RunPlugin(plugin://'+addonID+'/?mode=removeSite&url='+urllib.quote_plus(name)+')',)])
ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=True)
return ok
params = parameters_string_to_dict(sys.argv[2])
mode = urllib.unquote_plus(params.get('mode', ''))
name = urllib.unquote_plus(params.get('name', ''))
url = urllib.unquote_plus(params.get('url', ''))
stopPlayback = urllib.unquote_plus(params.get('stopPlayback', 'no'))
kiosk = urllib.unquote_plus(params.get('kiosk', 'yes'))
userAgent = urllib.unquote_plus(params.get('userAgent', ''))
if mode == 'addSite':
addSite()
elif mode == 'showSite':
showSite(url, stopPlayback, kiosk, userAgent)
elif mode == 'removeSite':
removeSite(url)
elif mode == 'editSite':
editSite(url)
else:
index()