def addToXBMC(name, thumb, cmd): cmd = '"%s"' % cmd folder = '&mode=%d' % _FOLDER search = '&mode=%d' % _SUPERSEARCH edit = '&mode=%d' % _EDITTERM #activate = '&mode=%d' % _ACTIVATEWINDOW #if (folder in cmd) or (search in cmd) or (edit in cmd) or (activate in cmd): if (folder in cmd) or (search in cmd) or (edit in cmd): cmd = cmd.replace('+', '%20') cmd = 'ActivateWindow(%d,%s)' % (getCurrentWindowId(), cmd) else: cmd = 'PlayMedia(%s)' % cmd if (search in cmd) and ('keyword' not in cmd): replace = '%s&keyword=%s' % (search, ISEARCH_EMPTY) cmd = cmd.replace(search, replace) if not cmd.lower().endswith(',return)'): cmd = cmd[:-1] + ',return)' fave = [name, thumb, cmd] file = os.path.join(xbmc.translatePath('special://profile'), FILENAME) #if it is already in there don't add again if favourite.findFave(file, cmd)[0]: return False faves = favourite.getFavourites(file) faves.append(fave) favourite.writeFavourites(file, faves) return True
def getFolderThumb(path, isXBMC=False): cfg = os.path.join(path, FOLDERCFG) thumb = getParam('ICON', cfg) fanart = getParam('FANART', cfg) if thumb and fanart: return thumb, fanart if isXBMC: thumb = thumb if (thumb != None) else 'DefaultFolder.png' fanart = fanart if (fanart != None) else FANART return thumb, fanart if not INHERIT: thumb = thumb if (thumb != None) else ICON fanart = fanart if (fanart != None) else FANART return thumb, fanart faves = favourite.getFavourites(os.path.join(path, FILENAME), 1) if len(faves) < 1: thumb = thumb if (thumb != None) else ICON fanart = fanart if (fanart != None) else FANART return thumb, fanart tFave = faves[0][1] fFave = favourite.getFanart(faves[0][2]) thumb = thumb if (thumb != None) else tFave fanart = fanart if (fanart != None) else fFave fanart = fanart if (fanart and len(fanart) > 0) else FANART return thumb, fanart
def __init__(self, addonID): super(Application, self).__init__() #in case it was set whilst addon not running xbmcgui.Window(10000).clearProperty('LB_RELAUNCH') self.ADDONID = addonID self.skin = utils.getSetting('SKIN') self.properties = {} self.lists = [] self.start = None self.context = False self.busy = None self.osd = None self.showBack = True self.timer = None self.faves = str(favourite.getFavourites()) self.counter = 0 self.listSize = -1 self.playbackStart = None self.playbackEnd = None self.firstRun = True self.checkForUpdatesFreq = 1 #immediately self.checkForInternetFreq = 5 self.checkForInternet = True self.checkForInternetSkip = False self.checkForEmail = True self.checkForInitialSetup = True self.updatedPageVisible = False self.updatePageDelay = 0
def parseFile(file): global separator faves = favourite.getFavourites(file) for fave in faves: label = fave[0] thumb = fave[1] cmd = fave[2] menu = [] menu.append((GETTEXT(30068), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s&name=%s)' % (sys.argv[0], _EDITFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd), urllib.quote_plus(label)))) if isPlaylist(cmd) and (not PLAY_PLAYLISTS): menu.append((GETTEXT(30084), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _PLAYLIST, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #menu.append((GETTEXT(30041), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _UP, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #menu.append((GETTEXT(30042), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _DOWN, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #menu.append((GETTEXT(30007), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _COPY, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #menu.append((GETTEXT(30008), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _MOVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #menu.append((GETTEXT(30009), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _REMOVEFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #menu.append((GETTEXT(30010), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _RENAMEFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #menu.append((GETTEXT(30043), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _THUMBFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) #if 'sf_win_id=' in cmd: # menu.append((GETTEXT(30052), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _PLAYBACKMODE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) if 'playmedia(' in cmd.lower(): addDir(label, _PLAYMEDIA, cmd=cmd, thumbnail=thumb, isFolder=False, menu=menu) else: addDir(label, _ACTIVATEWINDOW, cmd=cmd, thumbnail=thumb, isFolder=True, menu=menu) separator = len(faves) > 0
def ShowSFShortcuts(): if not SF_INSTALLED: return faves = favourite.getFavourites(SFFILE) mode = _SUPERFAVE isFolder = False isPlayable = False replaceItems = False for fave in faves: name = fave[0] icon = fave[1] path = fave[2] #these currently don't work as they are removed by chooser.py :( fanart = favourite.getFanart(path) desc = favourite.getOption(path, 'desc') menu = [] menu.append( ('Remove %s Super Favourite' % (name), '?mode=%d&url=%s' % (_REMOVESUPERFAVE, urllib.quote_plus(path)))) AddDir(name, path, mode, icon, desc, isFolder, isPlayable, fanart=fanart, contextMenu=menu, replaceItems=False)
def pasteFolderLink(src, dst, folderName, addonid): import urllib thumbnail, fanart = utils.getFolderThumb(src) folderConfig = os.path.join(src, FOLDERCFG) colour = parameters.getParam('COLOUR', folderConfig) if colour: folderName = '[COLOR %s]%s[/COLOR]' % (colour, folderName) path = utils.convertToHome(src) path = path.replace(PROFILE, '') path = path.replace('\\', '/') if path.startswith('/'): path = path[1:] cmd = '%s?label=%s&mode=%d&folder=%s' % (addonid, folderName, utils._FOLDER, urllib.quote_plus(path)) cmd = '"%s"' % cmd cmd = cmd.replace('+', '%20') cmd = 'ActivateWindow(%d,%s)' % (utils.getCurrentWindowId(), cmd) cmd = favourite.addFanart(cmd, fanart) file = os.path.join(dst, FILENAME) if favourite.findFave(file, cmd)[0]: return True faves = favourite.getFavourites(file, validate=False) fave = [folderName, thumbnail, cmd] faves.append(fave) favourite.writeFavourites(file, faves) return True
def addToXBMC(name, thumb, cmd): cmd = '"%s"' % cmd folder = '&mode=%d' % _FOLDER search = '&mode=%d' % _SUPERSEARCH edit = '&mode=%d' % _EDITSEARCH if (folder in cmd) or (search in cmd) or (edit in cmd): cmd = cmd.replace('+', '%20') cmd = 'ActivateWindow(%d,%s)' % (xbmcgui.getCurrentWindowId(), cmd) else: cmd = 'PlayMedia(%s)' % cmd fave = [name, thumb, cmd] file = os.path.join(xbmc.translatePath('special://profile'), FILENAME) #if it is already in there don't add again if findFave(file, cmd)[0]: return False faves = favourite.getFavourites(file) faves.append(fave) favourite.writeFavourites(file, faves) return True
def parseFile(file): global separator faves = favourite.getFavourites(file) text = GETTEXT(30099) if mode == _XBMC else GETTEXT(30068) for fave in faves: label = fave[0] thumb = fave[1] cmd = fave[2] try: fanart = urllib.unquote_plus(re.compile('sf_fanart=(.+?)_').search(cmd).group(1)) except: fanart = '' menu = [] menu.append((text, 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s&name=%s&thumb=%s)' % (sys.argv[0], _EDITFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd), urllib.quote_plus(label), urllib.quote_plus(thumb)))) if isPlaylist(cmd) and (not PLAY_PLAYLISTS): menu.append((GETTEXT(30084), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _PLAYLIST, urllib.quote_plus(file), urllib.quote_plus(cmd)))) if 'playmedia(' in cmd.lower(): addDir(label, _PLAYMEDIA, cmd=cmd, thumbnail=thumb, isFolder=False, menu=menu, fanart=fanart) else: addDir(label, _ACTIVATEWINDOW, cmd=cmd, thumbnail=thumb, isFolder=True, menu=menu, fanart=fanart) separator = len(faves) > 0
def verifySuperSearch(): dst = os.path.join(xbmc.translatePath(ROOT), 'Search') src = os.path.join(HOME, 'resources', 'Search', FILENAME) try: os.makedirs(dst) except: pass dst = os.path.join(dst, FILENAME) if not os.path.exists(dst): try: import shutil shutil.copyfile(src, dst) except: pass return import favourite new = favourite.getFavourites(src, validate=False) line1 = GETTEXT(30123) line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: line = line1 % item[0] if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def parseFile(file, reqSep=False, isXBMC=False): faves = favourite.getFavourites(file) if reqSep and len(faves) > 0: addSeparatorItem() for fave in faves: label = fave[0] thumb = fave[1] cmd = fave[2] menu = [] include = True #originally set to (not isXBMC) to prevent altering XBMC favourites themselves if include: menu.append((GETTEXT(30041), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _UP, urllib.quote_plus(file), urllib.quote_plus(cmd)))) menu.append((GETTEXT(30042), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _DOWN, urllib.quote_plus(file), urllib.quote_plus(cmd)))) menu.append((GETTEXT(30007), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _COPY, urllib.quote_plus(file), urllib.quote_plus(cmd)))) if include: menu.append((GETTEXT(30008), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _MOVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) menu.append((GETTEXT(30009), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _REMOVEFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) menu.append((GETTEXT(30010), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _RENAMEFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) menu.append((GETTEXT(30043), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _THUMBFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) if 'sf_win_id=' in cmd: menu.append((GETTEXT(30052), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _PLAYBACKMODE, urllib.quote_plus(file), urllib.quote_plus(cmd)))) addDir(label, _COMMAND, cmd=cmd, thumbnail=thumb, isFolder=False, menu=menu) return len(faves) > 0
def getDefaultSearch(): file = os.path.join(ROOT, 'S', FILENAME) faves = favourite.getFavourites(file) if len(faves) > 0: return faves[0] return None
def getDefaultSearch(): file = os.path.join(xbmc.translatePath(ROOT), 'Search', FILENAME) faves = favourite.getFavourites(file) if len(faves) > 0: return faves[0] return None
def findFave(file, cmd): faves = favourite.getFavourites(file) index = -1 for fave in faves: index += 1 if fave[2] == cmd: return fave, index, len(faves) return None, -1, 0
def removeFave(file, cmd): copy = [] faves = favourite.getFavourites(file) for fave in faves: if fave[2] != cmd: copy.append(fave) if len(copy) == len(faves): return False favourite.writeFavourites(file, copy) return True
def verifySuperSearch(): src = os.path.join(xbmc.translatePath(ROOT), 'Search') dst = os.path.join(xbmc.translatePath(ROOT), 'S') renameFolder(src, dst) dst = os.path.join(xbmc.translatePath(ROOT), 'S') src = os.path.join(HOME, 'resources', 'Search', FILENAME) try: os.makedirs(dst) except: pass dst = os.path.join(dst, FILENAME) if not os.path.exists(dst): try: import shutil shutil.copyfile(src, dst) except: pass return try: #patch any changes ch1 = open(dst, 'r') xml = ch1.read() ch1.close() xml = xml.replace('1channel/?mode=7000', '1channel/?mode=Search') xml = xml.replace('plugin.video.genesis/?action=actors_movies', 'plugin.video.genesis/?action=people_movies') xml = xml.replace('plugin.video.genesis/?action=actors_shows', 'plugin.video.genesis/?action=people_shows') ch1 = open(dst, 'w') ch1.write(xml) ch1.close() except: pass import favourite new = favourite.getFavourites(src, validate=False) line1 = GETTEXT(30123) line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: line = line1 % item[0] if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def renameFave(file, cmd): copy = [] faves = favourite.getFavourites(file) for fave in faves: if fave[2] == cmd: text = getText(GETTEXT(30021), text=fave[0]) if not text: return fave[0] = text copy.append(fave) favourite.writeFavourites(file, copy) return True
def insertFave(file, newFave, index): copy = [] faves = favourite.getFavourites(file) for fave in faves: if len(copy) == index: copy.append(newFave) copy.append(fave) if index >= len(copy): copy.append(newFave) favourite.writeFavourites(file, copy) return True
def superSearch(keyword='', image=BLANK, fanart=BLANK): #if len(keyword) < 1: # keyword = xbmcgui.Window(10000).getProperty('SF_KEYWORD') if len(keyword) < 1: kb = xbmc.Keyboard(keyword, GETTEXT(30054)) kb.doModal() if kb.isConfirmed(): keyword = kb.getText() #xbmcgui.Window(10000).setProperty('SF_KEYWORD', keyword) if len(keyword) > 0: cmd = '%s?mode=%d&keyword=%s&image=%s&fanart=%s' % (sys.argv[0], _SUPERSEARCH, keyword, image, fanart) xbmc.executebuiltin('XBMC.Container.Update(%s)' % cmd) return if len(keyword) < 1: return if not SHOWSS_FANART: fanart = BLANK file = os.path.join(xbmc.translatePath(ROOT), 'Search', FILENAME) faves = favourite.getFavourites(file) menu = [] menu.append((GETTEXT(30057), 'XBMC.Container.Update(%s?mode=%d&keyword=%s)' % (sys.argv[0], _EDITSEARCH, keyword))) addDir(GETTEXT(30066) % keyword, _EDITSEARCH, thumbnail=image, isFolder=True, menu=menu, fanart=fanart, keyword=keyword) #reset menu, since adddir call will have added to it menu = [] menu.append((GETTEXT(30057), 'XBMC.Container.Update(%s?mode=%d&keyword=%s)' % (sys.argv[0], _EDITSEARCH, keyword))) addSeparatorItem(menu) keyword = urllib.quote_plus(keyword.replace('&', '')) for fave in faves: label = fave[0] thumb = fave[1] cmd = fave[2].replace('[%SF%]', keyword) if 'plugin' in cmd: addPluginSearch(label, thumb, cmd, keyword, fanart) if 'RunScript' in cmd: addScriptSearch(label, thumb, cmd, keyword, fanart)
def changePlaybackMode(file, cmd): copy = [] faves = favourite.getFavourites(file) for fave in faves: if favourite.equals(fave[2], cmd): if cmd.startswith('PlayMedia'): try: winID = re.compile('sf_win_id=(.+?)_').search(cmd).group(1) except: winID = '10025' cmd = cmd.replace('PlayMedia(', 'ActivateWindow(%s,' % winID) elif cmd.startswith('ActivateWindow'): cmd = 'PlayMedia(' + cmd.split(',', 1)[-1] fave[2] = cmd copy.append(fave) favourite.writeFavourites(file, copy) return True
def verifySuperSearch(): old = os.path.join(ROOT, 'Search') dst = os.path.join(ROOT, 'S') sfile.rename(old, dst) try: sfile.makedirs(dst) except: pass src = os.path.join(HOME, 'resources', 'search', FILENAME) dst = os.path.join(dst, FILENAME) if not sfile.exists(dst): sfile.copy(src, dst) try: #patch any changes xml = sfile.read(dst) xml = xml.replace('is/?action=movies_search&', 'is/?action=movieSearch&') xml = xml.replace('is/?action=people_movies&', 'is/?action=moviePerson&') xml = xml.replace('is/?action=shows_search&', 'is/?action=tvSearch&') xml = xml.replace('is/?action=people_shows&', 'is/?action=tvPerson&') f = sfile.file(dst, 'w') f.write(xml) f.close() except: pass import favourite new = favourite.getFavourites(src, validate=False) #line1 = GETTEXT(30123) #line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: #line = line1 % item[0] #if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def verifySuperSearch(): src = os.path.join(ROOT, 'Search') dst = os.path.join(ROOT, 'S') sfile.rename(src, dst) dst = os.path.join(ROOT, 'S') src = os.path.join(HOME, 'resources', 'Search', FILENAME) try: sfile.makedirs(dst) except: pass dst = os.path.join(dst, FILENAME) if not sfile.exists(dst): sfile.copy(src, dst) try: #patch any changes xml = sfile.read(dst) xml = xml.replace('1channel/?mode=7000', '1channel/?mode=Search') xml = xml.replace('plugin.video.genesis/?action=actors_movies', 'plugin.video.genesis/?action=people_movies') xml = xml.replace('plugin.video.genesis/?action=actors_shows', 'plugin.video.genesis/?action=people_shows') f = sfile.file(dst, 'w') f.write(xml) f.close() except: pass import favourite new = favourite.getFavourites(src, validate=False) line1 = GETTEXT(30123) line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: line = line1 % item[0] if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def addToXBMC(name, thumb, cmd): p = get_params(cmd.replace('?', '&')) try: mode = int(p['mode']) if mode == _FOLDER: label = urllib.unquote_plus(p['label']) path = urllib.unquote_plus(p['path']) path = favourite.convertToHome(path) cmd = '%s?label=%s&mode=%d&path=%s' % (sys.argv[0], label, _FOLDER, urllib.quote_plus(path)) except: pass cmd = '"%s"' % cmd folder = '&mode=%d' % _FOLDER search = '&mode=%d' % _SUPERSEARCH edit = '&mode=%d' % _EDITTERM if (folder in cmd) or (search in cmd) or (edit in cmd): cmd = cmd.replace('+', '%20') cmd = 'ActivateWindow(%d,%s,return)' % (getCurrentWindowId(), cmd) else: cmd = 'PlayMedia(%s)' % cmd if (search in cmd) and ('keyword' not in cmd): replace = '%s&keyword=%s' % (search, ISEARCH_EMPTY) cmd = cmd.replace(search, replace) if not cmd.lower().endswith(',return)'): cmd = cmd[:-1] + ',return)' fave = [name, thumb, cmd] file = os.path.join(xbmc.translatePath('special://profile'), FILENAME) #if it is already in there don't add again if favourite.findFave(file, cmd)[0]: return False faves = favourite.getFavourites(file, validate=False) faves.append(fave) favourite.writeFavourites(file, faves) return True
def verifySuperSearch(): src = os.path.join(ROOT, "Search") dst = os.path.join(ROOT, "S") sfile.rename(src, dst) dst = os.path.join(ROOT, "S") src = os.path.join(HOME, "resources", "Search", FILENAME) try: sfile.makedirs(dst) except: pass dst = os.path.join(dst, FILENAME) if not sfile.exists(dst): sfile.copy(src, dst) try: # patch any changes xml = sfile.read(dst) xml = xml.replace("1channel/?mode=7000", "1channel/?mode=Search") xml = xml.replace("plugin.video.genesis/?action=actors_movies", "plugin.video.genesis/?action=people_movies") xml = xml.replace("plugin.video.genesis/?action=actors_shows", "plugin.video.genesis/?action=people_shows") f = sfile.file(dst, "w") f.write(xml) f.close() except: pass import favourite new = favourite.getFavourites(src, validate=False) line1 = GETTEXT(30123) line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: line = line1 % item[0] if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def getDefaultSearch(): file = os.path.join(xbmc.translatePath(ROOT), 'Search', FILENAME) faves = favourite.getFavourites(file) for fave in faves: label = fave[0] thumb = fave[1] cmd = fave[2] if 'plugin' in cmd: if utils.verifyPlugin(cmd): return fave if 'RunScript' in cmd: if utils.verifyScript(cmd): return fave return None
def parseFile(file): global separator faves = favourite.getFavourites(file) text = GETTEXT(30099) if mode == _XBMC else GETTEXT(30068) for fave in faves: label = fave[0] thumb = fave[1] cmd = fave[2] fanart = favourite.getFanart(cmd) menu = [] menu.append( (text, 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s&name=%s&thumb=%s)' % (sys.argv[0], _EDITFAVE, urllib.quote_plus(file), urllib.quote_plus(cmd), urllib.quote_plus(label), urllib.quote_plus(thumb)))) if isPlaylist(cmd) and (not PLAY_PLAYLISTS): menu.append( (GETTEXT(30084), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s)' % (sys.argv[0], _PLAYLIST, urllib.quote_plus(file), urllib.quote_plus(cmd)))) if 'playmedia(' in cmd.lower(): addDir(label, _PLAYMEDIA, cmd=cmd, thumbnail=thumb, isFolder=False, menu=menu, fanart=fanart) else: addDir(label, _ACTIVATEWINDOW, cmd=cmd, thumbnail=thumb, isFolder=True, menu=menu, fanart=fanart) separator = len(faves) > 0
def colourFave(file, cmd): colour = getColour() if not colour: return False copy = [] faves = favourite.getFavourites(file) for fave in faves: if favourite.equals(fave[2], cmd): fave[0] = decolourize(fave[0]) if colour != 'SF_RESET': fave[0] = '[COLOR %s]%s[/COLOR]' % (colour, fave[0]) copy.append(fave) favourite.writeFavourites(file, copy) return True
def playSF(url): try: import urllib params = url.split('?', 1)[-1] params = get_params(params) try: path = urllib.unquote_plus(params['path']) except: path = None if path: try: current, dirs, files = os.walk(path).next() except: pass if len(dirs) == 0: path = os.path.join(path, 'favourites.xml') sfAddon = xbmcaddon.Addon(id='plugin.program.super.favourites') sfPath = sfAddon.getAddonInfo('path') sys.path.insert(0, sfPath) import favourite faves = favourite.getFavourites(path) if len(faves) == 1: fave = faves[0][2] if fave.lower().startswith('playmedia'): import re cmd = re.compile('"(.+?)"').search(fave).group(1) return False, cmd except: pass url = 'ActivateWindow(10025,%s)' % url xbmc.executebuiltin(url) return True, ''
def copyFave(name, thumb, cmd): import favourite import utils text = utils.GETTEXT(30019) folder = utils.GetFolder(text) if not folder: return False file = os.path.join(folder, utils.FILENAME) faves = favourite.getFavourites(file) #if it is already in there don't add again for fave in faves: if favourite.equals(fave[2], cmd): return False fave = [name, thumb, cmd] return favourite.copyFave(file, fave)
def getFolderThumb(path): cfg = os.path.join(path, FOLDERCFG) thumb = parameters.getParam('ICON', cfg) if thumb: return thumb if not INHERIT: return ICON faves = favourite.getFavourites(os.path.join(path, FILENAME), 1, chooser=True) if len(faves) < 1: return ICON thumb = faves[0][1] if len(thumb) > 0: return thumb return ICON
def addToXBMC(name, thumb, cmd): cmd = cmd.replace('&', '&') cmd = cmd.replace('+', '%20') cmd = '"%s"' % cmd cmd = 'ActivateWindow(10001,%s)' % cmd fave = [name, thumb, cmd] file = os.path.join(xbmc.translatePath('special://profile'), FILENAME) #if it is already in there don't add again if findFave(file, cmd): return False faves = favourite.getFavourites(file) faves.append(fave) favourite.writeFavourites(file, faves) return True
def getFolderThumb(path): cfg = os.path.join(path, FOLDERCFG) thumb = getParam('ICON', cfg) if thumb: return thumb if not INHERIT: #return 'DefaultFolder.png' return ICON faves = favourite.getFavourites(os.path.join(path, FILENAME), 1) if len(faves) < 1: return ICON thumb = faves[0][1] if len(thumb) > 0: return thumb return ICON
def ShowSFShortcuts(): if not SF_INSTALLED: return faves = favourite.getFavourites(SFFILE) mode = _SUPERFAVE isFolder = False isPlayable = False replaceItems = False for fave in faves: name = fave[0] icon = fave[1] path = fave[2] #these currently don't work as they are removed by chooser.py :( fanart = favourite.getFanart(path) desc = favourite.getOption(path, 'desc') menu = [] menu.append(('Remove %s Super Favourite' % (name), '?mode=%d&url=%s' % (_REMOVESUPERFAVE, urllib.quote_plus(path)))) AddDir(name, path, mode, icon, desc, isFolder, isPlayable, fanart=fanart, contextMenu=menu, replaceItems=False)
def copyFave(file, cmd, move=False): copy, index, nFaves = findFave(file, cmd) if not copy: return text = GETTEXT(30020) if move else GETTEXT(30019) folder = getFolder(text) if not folder: return False file = os.path.join(folder, FILENAME) faves = favourite.getFavourites(file) #if it is already in there don't add again for fave in faves: if fave[2] == cmd: return False faves.append(copy) favourite.writeFavourites(file, faves) return True
def playSF(url): try: import urllib params = url.split('?', 1)[-1] params = get_params(params) try: path = urllib.unquote_plus(params['path']) except: path = None if path: try: current, dirs, files = os.walk(path).next() except: pass if len(dirs) == 0: path = os.path.join(path, 'favourites.xml') sfAddon = xbmcaddon.Addon(id = 'plugin.program.super.favourites') sfPath = sfAddon.getAddonInfo('path') sys.path.insert(0, sfPath) import favourite faves = favourite.getFavourites(path) if len(faves) == 1: fave = faves[0][2] if fave.lower().startswith('playmedia'): import re cmd = re.compile('"(.+?)"').search(fave).group(1) return False, cmd except: pass url = 'ActivateWindow(10025,%s)' % url xbmc.executebuiltin(url) return True, ''
def ShowMovie(): sfave = favourite.getFavourites(SFMOV) if SFMOV else [] addon = utils.getSetting('MOVIE') if utils.getSetting('UseKodiLib') == 'true': AddLibrary('Movies', '', _MOVIE, icon=os.path.join(IMAGES, 'OTTV-Movies.png')) elif (len(sfave) == 0) and (addon == ''): AddLibrary('Movies', '', _MOVIEOPTIONS, icon=os.path.join(IMAGES, 'OTTV-Movies.png')) elif not addon == '': AddMovieLibrary('Movies', '', _MOVIEADDON, icon=os.path.join(IMAGES, 'OTTV-Movies.png')) else: ShowSFShortcuts(SFMOV, _REMOVESFMOVIE)
def ShowTV(): sfave = favourite.getFavourites(SFTV) if SFTV else [] addon = utils.getSetting('TV') if utils.getSetting('UseKodiLib') == 'true': AddLibrary('TV Shows', '', _TV, icon=os.path.join(IMAGES, 'OTTV-TV_Shows.png')) elif (len(sfave) == 0) and (addon == ''): AddLibrary('TV Shows', '', _TVOPTIONS, icon=os.path.join(IMAGES, 'OTTV-TV_Shows.png')) elif not addon == '': AddTVLibrary('TV Shows', '', _TVADDON, icon=os.path.join(IMAGES, 'OTTV-TV_Shows.png')) else: ShowSFShortcuts(SFTV, _REMOVESFTV)
class Main: def __init__(self, property=None, path='', changeTitle=False): xbmcgui.Window(10000).setProperty('Super_Favourites_Chooser', 'true') if property: self.init(property, path, changeTitle) else: self._parse_argv() faves = self.getFaves() MyDialog(faves, self.PROPERTY, self.CHANGETITLE, self.PATH, self.MODE) def _parse_argv(self): try: params = dict(arg.split('=') for arg in sys.argv[1].split('&')) except: params = {} path = params.get('path', '') property = params.get('property', '') changeTitle = params.get('changetitle', '').lower() == 'true' path = path.replace('SF_AMP_SF', '&') self.init(property, path, changeTitle) def init(self, property, path, changeTitle): self.PATH = path self.PROPERTY = property self.CHANGETITLE = changeTitle self.MODE = 'folder' if len(self.PATH) > 0 else 'root' if self.PATH == 'special://profile/': self.MODE = 'xbmc' self.FULLPATH = xbmc.translatePath(self.PATH) else: self.FULLPATH = xbmc.translatePath( os.path.join(utils.PROFILE, self.PATH)) self.FULLPATH = urllib.unquote_plus(self.FULLPATH) def getFaves(self): file = os.path.join(self.FULLPATH, FILENAME).decode('utf-8') faves = [] if self.MODE != 'xbmc': try: current, dirs, files = os.walk(self.FULLPATH).next() dirs = sorted(dirs, key=str.lower) for dir in dirs: path = os.path.join(self.FULLPATH, dir) folderCfg = os.path.join(path, FOLDERCFG) colour = getParam('COLOUR', folderCfg) thumb = getFolderThumb(path) label = dir if len(colour) > 0: label = '[COLOR %s]%s[/COLOR]' % (colour, label) fave = [label, thumb, os.path.join(self.PATH, dir), True] faves.append(fave) except Exception, e: pass faves.extend(favourite.getFavourites(file)) return faves
def superSearch(keyword='', image=BLANK, fanart=FANART, imdb=''): if len(keyword) < 1: kb = xbmc.Keyboard(keyword, GETTEXT(30054)) kb.doModal() if kb.isConfirmed(): keyword = kb.getText() if len(keyword) > 0: mode = _SUPERSEARCH cmd = '%s?mode=%d&keyword=%s&image=%s&fanart=%s' % ( sys.argv[0], mode, keyword, image, fanart) xbmc.executebuiltin('XBMC.Container.Update(%s)' % cmd) return False if len(keyword) < 1: return if keyword == ISEARCH_EMPTY: keyword = '' if not SHOW_FANART: fanart = BLANK menu = [] menu.append( (GETTEXT(30057), 'XBMC.Container.Update(%s?mode=%d&keyword=%s)' % (sys.argv[0], _EDITTERM, keyword))) infolabels = {} if METARECOMMEND and len(imdb) > 0: from metahandler import metahandlers grabber = metahandlers.MetaData() infolabels = getMeta(grabber, '', 'movie', year=None, imdb=imdb) getMovieMenu(infolabels, menu) addDir(GETTEXT(30066) % keyword.strip(), _EDITTERM, thumbnail=image, isFolder=True, menu=menu, fanart=fanart, keyword=keyword, infolabels=infolabels) #reset menu, since adddir call will have added to it menu = [] menu.append( (GETTEXT(30057), 'XBMC.Container.Update(%s?mode=%d&keyword=%s)' % (sys.argv[0], _EDITTERM, keyword))) addSeparatorItem(menu) if SHOWRECOMMEND: menu = [] menu.append( (GETTEXT(30057), 'XBMC.Container.Update(%s?mode=%d&keyword=%s)' % (sys.argv[0], _EDITTERM, keyword))) getMovieMenu(infolabels, menu) if len(imdb) > 0: addDir(GETTEXT(30088), _RECOMMEND_IMDB, thumbnail=image, isFolder=True, menu=menu, fanart=fanart, keyword=keyword, imdb=imdb, infolabels=infolabels) else: addDir(GETTEXT(30088), _RECOMMEND_KEY, thumbnail=image, isFolder=True, menu=menu, fanart=fanart, keyword=keyword) keyword = urllib.quote_plus(keyword.replace('&', '')) file = os.path.join(xbmc.translatePath(ROOT), 'Search', FILENAME) faves = favourite.getFavourites(file, superSearch=True) if len(faves) == 0: #try shipped search file file = os.path.join(xbmc.translatePath(HOME), 'resources', 'Search', FILENAME) faves = favourite.getFavourites(file) for fave in faves: label = fave[0] thumb = fave[1] cmd = fave[2].replace('[%SF%]', keyword) fan = fanart if SHOW_FANART: fan = favourite.getFanart(cmd) if len(fan) == 0: fan = fanart menu = [] menu.append( (GETTEXT(30057), 'XBMC.Container.Update(%s?mode=%d&keyword=%s)' % (sys.argv[0], _EDITTERM, keyword))) menu.append( (GETTEXT(30103), 'XBMC.RunPlugin(%s?mode=%d&file=%s&cmd=%s&name=%s&thumb=%s)' % (sys.argv[0], _EDITSEARCH, urllib.quote_plus(file), urllib.quote_plus(cmd), urllib.quote_plus(label), urllib.quote_plus(thumb)))) #special fix for GlobalSearch, use local launcher (globalsearch.py) to bypass keyboard cmd = cmd.replace('script.globalsearch', os.path.join(HOME, 'globalsearch.py')) addDir(label, _ACTIVATESEARCH, cmd=cmd, thumbnail=thumb, isFolder=True, menu=menu, fanart=fan) return True
def getFaves(self): file = os.path.join(self.FULLPATH, FILENAME).decode('utf-8') faves = [] index = 0 label_numeric = LABEL_NUMERIC if self.MODE == 'folder': folderCfg = os.path.join(self.FULLPATH, FOLDERCFG) numeric = parameters.getParam('NUMERICAL', folderCfg) if numeric: label_numeric = numeric.lower() == 'true' if label_numeric: label_numeric = LABEL_NUMERIC_QL if self.MODE != 'xbmc': try: current, dirs, files = sfile.walk(self.FULLPATH) dirs = sorted(dirs, key=str.lower) for dir in dirs: path = os.path.join(self.FULLPATH, dir) folderCfg = os.path.join(path, FOLDERCFG) folderCfg = parameters.getParams(folderCfg) lock = parameters.getParam('LOCK', folderCfg) if lock: continue colour = parameters.getParam('COLOUR', folderCfg) thumb = getFolderThumb(path) label = dir if colour and colour.lower() <> 'none': label = '[COLOR %s]%s[/COLOR]' % (colour, label) label, index = utils.addPrefixToLabel( index, label, label_numeric) fave = [label, thumb, os.path.join(self.PATH, dir), True] faves.append(fave) except Exception as e: pass items = favourite.getFavourites(file, chooser=True) sortorder = 0 if self.MODE == 'folder': folderCfg = os.path.join(self.FULLPATH, FOLDERCFG) try: sortorder = int(parameters.getParam('SORT', folderCfg)) except: sortorder = 0 if sortorder == 0: sortorder = 1 if ALPHA_SORT else 2 if sortorder == 1: #ALPHA_SORT: items = sorted(items, key=lambda x: utils.CleanForSort(x)) if not label_numeric: faves.extend(items) else: for fave in items: label = fave[0] thumb = fave[1] cmd = fave[2] label, index = utils.addPrefixToLabel(index, label, label_numeric) faves.append([label, thumb, cmd]) return faves
def playSF(url): launchID = '10025' if xbmcgui.Window(10000).getProperty('OTT_LAUNCH_ID') == launchID: url = url.replace('ActivateWindow(%s' % launchID, 'ActivateWindow(10501') launchID = '10501' try: if url.startswith('__SF__'): url = url.replace('__SF__', '') if url.lower().startswith('playmedia'): xbmc.executebuiltin(url) return True, '' if url.lower().startswith('runscript'): xbmc.executebuiltin(url) return True, '' if url.lower().startswith('activatewindow'): import sys sfAddon = xbmcaddon.Addon(id='plugin.program.super.favourites') sfPath = sfAddon.getAddonInfo('path') sys.path.insert(0, sfPath) import favourite import re import urllib original = re.compile('"(.+?)"').search(url).group(1) original = original.replace( '%26', 'SF_AMP_SF') #protect '&' within parameters cmd = urllib.unquote_plus(original) try: noFanart = favourite.removeFanart(cmd) except: pass try: noFanart = favourite.removeSFOptions(cmd) except: pass if noFanart.endswith(os.path.sep): noFanart = noFanart[:-1] noFanart = noFanart.replace('+', '%2B') noFanart = noFanart.replace(' ', '+') url = url.replace(original, noFanart) url = url.replace('SF_AMP_SF', '%26') #put '&' back xbmc.executebuiltin(url) return True, '' import urllib params = url.split('?', 1)[-1] params = get_params(params) try: mode = int(urllib.unquote_plus(params['mode'])) except: return False, url if mode != 400: return False, url try: path = urllib.unquote_plus(params['path']) except: path = None dirs = [] if path: try: current, dirs, files = os.walk(path).next() except: pass if len(dirs) == 0: import sys path = os.path.join(path, 'favourites.xml') sfAddon = xbmcaddon.Addon(id='plugin.program.super.favourites') sfPath = sfAddon.getAddonInfo('path') sys.path.insert(0, sfPath) import favourite faves = favourite.getFavourites(path) if len(faves) == 1: fave = faves[0][2] if fave.lower().startswith('playmedia'): import re cmd = re.compile('"(.+?)"').search(fave).group(1) return False, cmd except Exception, e: print str(e) pass
class Main: def __init__(self, property=None, path='', changeTitle=False, includePlay=False): xbmcgui.Window(10000).setProperty('Super_Favourites_Chooser', 'true') if property: self.init(property, path, changeTitle, includePlay) else: self._parse_argv() faves = self.getFaves() MyDialog(faves, self.PROPERTY, self.CHANGETITLE, self.PATH, self.MODE, self.INCLUDEPLAY) def _parse_argv(self): try: params = dict(arg.split('=') for arg in sys.argv[1].split('&')) except: params = {} path = params.get('path', '') property = params.get('property', '') changeTitle = params.get('changetitle', '').lower() == 'true' includePlay = params.get('includePlay', '').lower() == 'true' path = path.replace('SF_AMP_SF', '&') self.init(property, path, changeTitle, includePlay) def init(self, property, path, changeTitle, includePlay): self.PATH = path self.PROPERTY = property self.CHANGETITLE = changeTitle self.INCLUDEPLAY = includePlay self.MODE = 'folder' if len(self.PATH) > 0 else 'root' if self.PATH == 'special://profile/': self.MODE = 'xbmc' self.FULLPATH = self.PATH else: self.FULLPATH = os.path.join(utils.PROFILE, self.PATH) self.FULLPATH = urllib.unquote_plus(self.FULLPATH) def getFaves(self): file = os.path.join(self.FULLPATH, FILENAME).decode('utf-8') faves = [] index = 0 label_numeric = LABEL_NUMERIC if self.MODE == 'folder': folderCfg = os.path.join(self.FULLPATH, FOLDERCFG) numeric = parameters.getParam('NUMERICAL', folderCfg) if numeric: label_numeric = numeric.lower() == 'true' if label_numeric: label_numeric = LABEL_NUMERIC_QL if self.MODE != 'xbmc': try: current, dirs, files = sfile.walk(self.FULLPATH) dirs = sorted(dirs, key=str.lower) for dir in dirs: path = os.path.join(self.FULLPATH, dir) folderCfg = os.path.join(path, FOLDERCFG) folderCfg = parameters.getParams(folderCfg) lock = parameters.getParam('LOCK', folderCfg) if lock: continue colour = parameters.getParam('COLOUR', folderCfg) thumb = getFolderThumb(path) label = dir if colour and colour.lower() <> 'none': label = '[COLOR %s]%s[/COLOR]' % (colour, label) label, index = utils.addPrefixToLabel( index, label, label_numeric) fave = [label, thumb, os.path.join(self.PATH, dir), True] faves.append(fave) except Exception, e: pass items = favourite.getFavourites(file, chooser=True) sortorder = 0 if self.MODE == 'folder': folderCfg = os.path.join(self.FULLPATH, FOLDERCFG) try: sortorder = int(parameters.getParam('SORT', folderCfg)) except: sortorder = 0 if sortorder == 0: sortorder = 1 if ALPHA_SORT else 2 if sortorder == 1: #ALPHA_SORT: items = sorted(items, key=lambda x: utils.CleanForSort(x)) if not label_numeric: faves.extend(items) else: for fave in items: label = fave[0] thumb = fave[1] cmd = fave[2] label, index = utils.addPrefixToLabel(index, label, label_numeric) faves.append([label, thumb, cmd]) return faves
def browse(): items = favourite.getFavourites(FILENAME, validate=False) items.sort() return items