forked from Pityke1105/plugin.video.sl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskins.py
201 lines (176 loc) · 8.58 KB
/
skins.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
# -*- coding: utf-8 -*-
# Author: cache-sk
# Created on: 12.6.2019
import xbmc
import xbmcgui
import xbmcaddon
import shutil
import xbmcvfs
from contextlib import closing
import xml.etree.ElementTree as ET
import time
import random
SKINS = {'skin.estuary':'Estuary','skin.confluence':'Confluence'}
def cleanup(copy_settings, destination, destsettings):
shutil.rmtree(xbmc.translatePath(destination))
if copy_settings:
shutil.rmtree(xbmc.translatePath(destsettings))
def modify():
__language__ = xbmcaddon.Addon(id='plugin.video.sl').getLocalizedString
if not xbmcgui.Dialog().yesno(xbmc.getLocalizedString(19194), __language__(30372)):
return
skin = xbmc.getSkinDir() #simplified skin detection
if skin not in SKINS:
xbmcgui.Dialog().ok(__language__(30373), __language__(30374))
return
newSkin = skin + '.skylink'
newName = SKINS[skin] + '.Skylink'
xbmc.executebuiltin( 'XBMC.ReloadSkin()' )
destination = 'special://home/addons/' + newSkin
destsettings = 'special://userdata/addon_data/' + newSkin
if xbmcvfs.exists(destination + "/"):
xbmcgui.Dialog().ok(newName, __language__(30375))
xbmc.executebuiltin("ActivateWindow(10040,addons://user/xbmc.gui.skin,return)")
return
if not xbmcvfs.exists(destsettings + "/"):
copy_settings = xbmcgui.Dialog().yesno(SKINS[skin], __language__(30376))
else:
copy_settings = False
try:
shutil.copytree(xbmc.translatePath('special://skin'), xbmc.translatePath(destination))
#alter copy addon.xml
with closing(xbmcvfs.File(destination + '/addon.xml')) as f:
addonxml = f.read()
addonxml = addonxml.replace(skin,newSkin)
addonxml = addonxml.replace('name="' + SKINS[skin] + '"','name="' + newName + '"')
with closing(xbmcvfs.File(destination + '/addon.xml', 'w')) as f:
f.write(addonxml)
if copy_settings:
#TODO special://profile
shutil.copytree(xbmc.translatePath('special://userdata/addon_data/' + skin), xbmc.translatePath(destsettings))
#update language
enpo = destination + '/language/resource.language.en_gb/strings.po'
skpo = destination + '/language/resource.language.sk_sk/strings.po'
czpo = destination + '/language/resource.language.cs_cz/strings.po'
with closing(xbmcvfs.File(enpo)) as f:
enstrings = f.read()
with closing(xbmcvfs.File(skpo)) as f:
skstrings = f.read()
with closing(xbmcvfs.File(czpo)) as f:
czstrings = f.read()
newId = str(random.randint(31000,31999))
newIdString = '"#' + newId + '"'
while newIdString in enstrings or newIdString in skstrings or newIdString in czstrings:
newId = str(random.randint(31000,31999))
newIdString = '"#' + newId + '"'
enstrings += '\nmsgctxt ' + newIdString + '\nmsgid "Skylink Archive"\nmsgstr "Skylink Archive"\n'
skstrings += '\nmsgctxt ' + newIdString + '\nmsgid "Skylink Archive"\nmsgstr "Skylink Archív"\n'
czstrings += '\nmsgctxt ' + newIdString + '\nmsgid "Skylink Archive"\nmsgstr "Skylink Archiv"\n'
with closing(xbmcvfs.File(enpo, 'w')) as f:
f.write(enstrings)
with closing(xbmcvfs.File(skpo, 'w')) as f:
f.write(skstrings)
with closing(xbmcvfs.File(czpo, 'w')) as f:
f.write(czstrings)
#update widgets
if skin == 'skin.estuary':
xmlfile = destination + '/xml/Includes_Home.xml'
with closing(xbmcvfs.File(xmlfile)) as f:
xml = f.read()
root = ET.fromstring(xml)
content = root.findall("include[@name='PVRSubMenuContent']/content")
if len(content) != 1:
cleanup(copy_settings, destination, destsettings)
xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
return
content = content[0]
toRemove = []
for item in content:
for child in item:
if child.tag == 'onclick' and 'Search' in child.text:
searchItem = item
if child.tag == 'onclick' and ('Recordings' in child.text or 'Timer' in child.text):
toRemove.append(item)
index = list(content).index(searchItem) + 1
newItem = ET.fromstring(
'<item>\n'+
'\t\t\t<label>$LOCALIZE[' + newId + ']</label>\n'+
'\t\t\t<onclick>ActivateWindow(10025,plugin://plugin.video.sl/?replay=channels,return)</onclick>\n'+
'\t\t\t<thumb>special://home/addons/plugin.video.sl/icon-archive.png</thumb>\n'+
'\t\t\t<visible>System.HasAddon(plugin.video.sl)</visible>\n'+
'</item>\n\t\t')
content.insert(index, newItem)
for item in toRemove:
content.remove(item)
with closing(xbmcvfs.File(xmlfile, 'w')) as f:
f.write(ET.tostring(root,encoding="utf-8"))
elif skin == 'skin.confluence':
xmlfile = destination + '/720p/IncludesHomeMenuItems.xml'
with closing(xbmcvfs.File(xmlfile)) as f:
xml = f.read()
print(xml)
root = ET.fromstring(xml)
print(root)
content = root.findall("include[@name='HomeSubMenuTV']")
if len(content) != 1:
print(content)
print(len(content))
cleanup(copy_settings, destination, destsettings)
xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
return
content = content[0]
toRemove = []
for control in content:
for child in control:
if child.tag == 'onclick' and 'TVSearch' in child.text:
searchControl = control
if child.tag == 'onclick' and ('TVRecordings' in child.text or 'TVTimer' in child.text):
toRemove.append(control)
index = list(content).index(searchControl) + 1
if len(toRemove) == 0:
cleanup(copy_settings, destination, destsettings)
xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
return
newControl = ET.fromstring(
'<control type="button" id="' + toRemove[0].attrib['id'] + '">\n'+
'\t\t\t<include>ButtonHomeSubCommonValues</include>\n'+
'\t\t\t<label>' + newId + '</label>\n'+
'\t\t\t<onclick>ActivateWindow(10025,plugin://plugin.video.sl/?replay=channels,return)</onclick>\n'+
'\t\t\t<visible>System.HasAddon(plugin.video.sl)</visible>\n'
'</control>\n\t\t')
content.insert(index, newControl)
for control in toRemove:
content.remove(control)
with closing(xbmcvfs.File(xmlfile, 'w')) as f:
f.write(ET.tostring(root,encoding="utf-8"))
except:
cleanup(copy_settings, destination, destsettings)
xbmcgui.Dialog().ok(SKINS[skin], __language__(30377))
return
xbmc.executebuiltin("UpdateLocalAddons")
time.sleep(1)
try:
#try enabling skin
xbmc.startServer(xbmc.SERVER_WEBSERVER, True,True)
time.sleep(1)
params = '"method":"Addons.SetAddonEnabled","params":{"addonid":"' + newSkin + '","enabled":true}'
xbmc.executeJSONRPC('{"jsonrpc": "2.0", %s, "id": 1}' % params)
#xbmc.executebuiltin("ActivateWindow(10040,addons://user/xbmc.gui.skin,return)")
if xbmcgui.Dialog().yesno(newName, __language__(30378)):
try: #try activate skin
xbmc.executeJSONRPC('{"jsonrpc":"2.0","method":"Settings.SetSettingValue","id":1,"params":{"setting":"lookandfeel.skin","value":"'+newSkin+'"}}')
xbmc.executebuiltin('SendClick(11)')
time.sleep(1)
xbmc.executebuiltin( 'XBMC.ReloadSkin()' )
xbmcgui.Dialog().ok(newName, xbmc.getLocalizedString(20177))
except:
xbmcgui.Dialog().ok(newName, __language__(30379))
xbmc.executebuiltin("ActivateWindow(10032,return)")
except:
xbmcgui.Dialog().ok(newName, __language__(30380))
xbmc.executebuiltin("ActivateWindow(10040,addons://user/xbmc.gui.skin,return)")
python3 = sys.version_info[0] >= 3
if python3:
xbmcgui.Dialog().ok("Kodi 19 Matrix", xbmcaddon.Addon(id='plugin.video.sl').getLocalizedString(30381))
else:
modify()