[0dea54]: plugin.program.super.favourites / utils.py  Maximize  Restore  History

Download this file

236 lines (165 with data), 5.9 kB

  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
#
# Copyright (C) 2014
# Sean Poyser (seanpoyser@gmail.com)
#
# 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; either version 2, or (at your option)
# any later version.
#
# 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 XBMC; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
#
import xbmc
import xbmcaddon
import xbmcgui
import os
def GetXBMCVersion():
#xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["version", "name"]}, "id": 1 }')
version = xbmcaddon.Addon('xbmc.addon').getAddonInfo('version')
version = version.split('.')
return int(version[0]), int(version[1]) #major, minor
ADDONID = 'plugin.program.super.favourites'
ADDON = xbmcaddon.Addon(ADDONID)
HOME = ADDON.getAddonInfo('path')
ROOT = ADDON.getSetting('FOLDER')
PROFILE = os.path.join(ROOT, 'Super Favourites')
VERSION = '1.0.8'
ICON = os.path.join(HOME, 'icon.png')
FANART = os.path.join(HOME, 'fanart.jpg')
SEARCH = os.path.join(HOME, 'resources', 'media', 'search.png')
GETTEXT = ADDON.getLocalizedString
TITLE = GETTEXT(30000)
KEYMAP_HOT = 'super_favourites_hot.xml'
KEYMAP_MENU = 'super_favourites_menu.xml'
MAJOR, MINOR = GetXBMCVersion()
FRODO = (MAJOR == 12) and (MINOR < 9)
GOTHAM = (MAJOR == 13) or (MAJOR == 12 and MINOR == 9)
FILENAME = 'favourites.xml'
FOLDERCFG = 'folder.cfg'
def DialogOK(line1, line2='', line3=''):
d = xbmcgui.Dialog()
d.ok(TITLE + ' - ' + VERSION, line1, line2 , line3)
def DialogYesNo(line1, line2='', line3='', noLabel=None, yesLabel=None):
d = xbmcgui.Dialog()
if noLabel == None or yesLabel == None:
return d.yesno(TITLE + ' - ' + VERSION, line1, line2 , line3) == True
else:
return d.yesno(TITLE + ' - ' + VERSION, line1, line2 , line3, noLabel, yesLabel) == True
def generateMD5(text):
if not text:
return ''
try:
import hashlib
return hashlib.md5(text).hexdigest()
except:
pass
try:
import md5
return md5.new(text).hexdigest()
except:
pass
return '0'
#def Verify():
# CheckVersion()
# VerifyKeymaps()
def CheckVersion():
prev = ADDON.getSetting('VERSION')
curr = VERSION
VerifyKeymaps()
if prev == curr:
return
ADDON.setSetting('VERSION', curr)
verifySuperSearch(replace=False)
if prev == '0.0.0' or prev== '1.0.0':
folder = xbmc.translatePath(PROFILE)
if not os.path.isdir(folder):
os.makedirs(folder)
def verifySuperSearch(replace=False):
dst = os.path.join(xbmc.translatePath(ROOT), 'Search', FILENAME)
if (not replace) and os.path.exists(dst):
return
src = os.path.join(HOME, 'resources', 'Search', FILENAME)
try: os.mkdir(os.path.join(xbmc.translatePath(ROOT), 'Search'))
except: pass
f = open(src, mode='r')
t = f.read()
f.close()
f = open(dst, mode='w')
f.write(t)
f.close()
def UpdateKeymaps():
DeleteKeymap(KEYMAP_HOT)
DeleteKeymap(KEYMAP_MENU)
VerifyKeymaps()
def DeleteKeymap(map):
path = os.path.join(xbmc.translatePath('special://profile/keymaps'), map)
tries = 5
while os.path.exists(path) and tries > 0:
tries -= 1
try:
os.remove(path)
break
except:
xbmc.sleep(500)
def VerifyKeymaps():
reload = False
if VerifyKeymapHot(): reload = True
if VerifyKeymapMenu(): reload = True
if not reload:
return
xbmc.sleep(1000)
xbmc.executebuiltin('Action(reloadkeymaps)')
def VerifyKeymapHot():
dest = os.path.join(xbmc.translatePath('special://profile/keymaps'), KEYMAP_HOT)
if os.path.exists(dest):
return False
key = ADDON.getSetting('HOTKEY').lower()
includeKey = key in ['f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'g']
if not includeKey:
DeleteKeymap(KEYMAP_HOT)
return True
cmd = '<keymap><Global><keyboard><%s>XBMC.RunScript(special://home/addons/plugin.program.super.favourites/hot.py)</%s></keyboard></Global></keymap>' % (key, key)
f = open(dest, mode='w')
f.write(cmd)
f.close()
xbmc.sleep(1000)
tries = 4
while not os.path.exists(dest) and tries > 0:
tries -= 1
f = open(dest, mode='w')
f.write(t)
f.close()
xbmc.sleep(1000)
return True
def VerifyKeymapMenu():
dest = os.path.join(xbmc.translatePath('special://profile/keymaps'), KEYMAP_MENU)
if os.path.exists(dest):
return False
context = ADDON.getSetting('CONTEXT') == 'true'
if not context:
DeleteKeymap(KEYMAP_MENU)
return True
src = os.path.join(HOME, 'resources', 'keymaps', KEYMAP_MENU)
dst = os.path.join(xbmc.translatePath('special://profile/keymaps'), KEYMAP_MENU)
import shutil
shutil.copy(src, dst)
return True
def GetFolder(title):
default = ROOT #ADDON.getAddonInfo('profile')
folder = xbmc.translatePath(PROFILE)
if not os.path.isdir(folder):
os.makedirs(folder)
folder = xbmcgui.Dialog().browse(3, title, 'files', '', False, False, default)
if folder == default:
return None
return xbmc.translatePath(folder)
if __name__ == '__main__':
pass

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks