Exemple #1
0
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
Exemple #2
0
    def addXBMCFavouritesItem(self):
        if not SHOWXBMC:
            return

        try:
            fullpath = 'special://profile/'

            thumb = parameters.getParam('ICON',
                                        os.path.join(PROFILE, FOLDERCFG))
            if not thumb:
                thumb = os.path.join(HOME, 'resources', 'media',
                                     'icon_favourites.png')

            label = GETTEXT(30106) % DISPLAYNAME
            listitem = xbmcgui.ListItem(label)

            listitem.setIconImage(thumb)
            listitem.setProperty('Icon', thumb)
            listitem.setProperty('Path', fullpath)
            listitem.setProperty('IsFolder', 'true')

            self.favList.addItem(listitem)

        except Exception, e:
            pass
Exemple #3
0
    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
Exemple #4
0
def cutCopyFolder(folder, cut=True):
    reset()
    xbmcgui.Window(10000).setProperty(  'SF_FILE',   folder)
    xbmcgui.Window(10000).setProperty(  'SF_FOLDER', folder.rsplit(os.sep, 1)[0])
    xbmcgui.Window(10000).clearProperty('SF_CMD')
    xbmcgui.Window(10000).setProperty(  'SF_TYPE',  'cutfolder' if cut else 'copyfolder')

    file = os.path.join(folder, FOLDERCFG)
    cfg  = parameters.getParams(file)

    thumb  = parameters.getParam('ICON',   cfg)
    fanart = parameters.getParam('FANART', cfg)
    desc   = parameters.getParam('DESC',   cfg)

    _setPasteProperties(thumb, fanart, desc)

    return True
Exemple #5
0
    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
Exemple #6
0
def getFolderThumb(path, isXBMC=False):
    import parameters

    cfg    = os.path.join(path, FOLDERCFG)
    cfg    = parameters.getParams(cfg)
    thumb  = parameters.getParam('ICON',   cfg)
    fanart = parameters.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

    import locking
    if not locking.unlocked(path):
        thumb  = thumb  if (thumb  != None) else ICON
        fanart = fanart if (fanart != None) else FANART
        return thumb, fanart

    import favourite
    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 getFolderThumb(path, isXBMC=False):
    import parameters

    cfg = os.path.join(path, FOLDERCFG)
    cfg = parameters.getParams(cfg)
    thumb = parameters.getParam('ICON', cfg)
    fanart = parameters.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

    import locking
    if not locking.unlocked(path):
        thumb = thumb if (thumb != None) else ICON
        fanart = fanart if (fanart != None) else FANART
        return thumb, fanart

    import favourite
    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
Exemple #8
0
def unlocked(path, lock=None):
    if not lock:
        folderConfig = os.path.join(path, FOLDERCFG)
        lock = parameters.getParam('LOCK', folderConfig)

    if not lock:
        return True

    if cache.exists(path):
        return True

    return False
Exemple #9
0
def unlocked(path, lock=None):
    if not lock:
        folderConfig = os.path.join(path, FOLDERCFG)
        lock = parameters.getParam('LOCK', folderConfig)

    if not lock:
        return True

    if cache.exists(path):
        return True

    return False
Exemple #10
0
def checkPassword(path, lock=None):
    if not lock:
        folderConfig = os.path.join(path, FOLDERCFG)
        lock = parameters.getParam('LOCK', folderConfig)

    title = GETTEXT(30069)
    
    unlock = utils.GetText(title, hidden=True)

    if not unlock:
        return ''

    md5   = utils.generateMD5(unlock)
    match = md5 == lock

    if not match:
        return 'ERROR'

    return md5
Exemple #11
0
def checkPassword(path, lock=None):
    if not lock:
        folderConfig = os.path.join(path, FOLDERCFG)
        lock = parameters.getParam('LOCK', folderConfig)

    title = GETTEXT(30069)

    unlock = utils.GetText(title, hidden=True)

    if not unlock:
        return ''

    md5 = utils.generateMD5(unlock)
    match = md5 == lock

    if not match:
        return 'ERROR'

    return md5
Exemple #12
0
def remove(path, name):
    title = GETTEXT(30078)
    password = utils.GetText(title, text='', hidden=True)

    if not password:
        return False

    md5 = utils.generateMD5(password)

    cfg = os.path.join(path, FOLDERCFG)
    lock = parameters.getParam('LOCK', cfg)

    if lock != md5:
        utils.DialogOK(GETTEXT(30080))
        return False

    parameters.clearParam('LOCK', cfg)
    utils.DialogOK(GETTEXT(30081))

    return True
Exemple #13
0
def remove(path,name):
    title    = GETTEXT(30078)
    password = utils.GetText(title, text='', hidden=True)

    if not password:
        return False

    md5 = utils.generateMD5(password)

    cfg  = os.path.join(path, FOLDERCFG)
    lock = parameters.getParam('LOCK', cfg)

    if lock != md5:
        utils.DialogOK(GETTEXT(30080))
        return False

    parameters.clearParam('LOCK', cfg)
    utils.DialogOK(GETTEXT(30081))

    return True
Exemple #14
0
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
Exemple #15
0
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
Exemple #16
0
def unlock(path):
    folderConfig = os.path.join(path, FOLDERCFG)
    lock = parameters.getParam('LOCK', folderConfig)

    if unlocked(path, lock):
        return True

    md5 = checkPassword(path, lock)

    if len(md5) == 0:
        return False

    if md5 == 'ERROR':
        utils.DialogOK(GETTEXT(30080))
        return False

    periods = [0, 1, 5, 15]
    setting = int(utils.ADDON.getSetting('CACHE'))
    period = periods[setting]

    cache.add(path, period)

    return True
Exemple #17
0
def unlock(path):
    folderConfig = os.path.join(path, FOLDERCFG)
    lock = parameters.getParam('LOCK', folderConfig)

    if unlocked(path, lock):
        return True
    
    md5 = checkPassword(path, lock)

    if len(md5) == 0:
        return False

    if md5 == 'ERROR':
        utils.DialogOK(GETTEXT(30080))
        return False

    periods = [0, 1, 5, 15]
    setting = int(utils.ADDON.getSetting('CACHE'))
    period  = periods[setting]

    cache.add(path, period)

    return True
Exemple #18
0
    def addXBMCFavouritesItem(self):
        if not SHOWXBMC:
            return

        try:
            fullpath = 'special://profile/'

            thumb = parameters.getParam('ICON', os.path.join(PROFILE, FOLDERCFG))
            if not thumb:
                thumb = os.path.join(HOME, 'resources', 'media', 'icon_favourites.png')

            label    = GETTEXT(30106) % DISPLAYNAME
            listitem = xbmcgui.ListItem(label) 

            listitem.setIconImage(thumb)
            listitem.setProperty('Icon',     thumb)
            listitem.setProperty('Path',     fullpath)
            listitem.setProperty('IsFolder', 'true')

            self.favList.addItem(listitem)


        except Exception, e:
            pass
    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
Exemple #20
0
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