def getCmd(path, fanart, desc, window, filename, isFolder, meta):
    import favourite

    if path.lower().startswith('addons://user/'):
        path = path.replace('addons://user/', 'plugin://')
        isFolder = True
        window = 10025

    if window == 10003:  #FileManager
        import sfile
        import os
        isFolder = sfile.isdir(path)
        if isFolder:
            #special paths fail to open - http://trac.kodi.tv/ticket/17333
            if path.startswith('special://'):
                path = xbmc.translatePath(path)
            path = path.replace('%s%s' % (os.sep, os.sep), os.sep)
            path = path.replace(os.sep, '/')
            folder = path
            if folder.endswith('/'):
                folder = folder[:-1]
            folder = folder.rsplit('/', 1)[-1]
            #if not utils.DialogYesNo(GETTEXT(30271) % folder, GETTEXT(30272)):
            #    return None

    if isFolder:
        cmd = 'ActivateWindow(%d,"%s' % (window, path)
    elif path.lower().startswith('script'):
        #if path[-1] == '/':
        #    path = path[:-1]
        cmd = 'RunScript("%s' % path.replace('script://', '')
    elif path.lower().startswith('videodb') and len(filename) > 0:
        cmd = 'PlayMedia("%s' % filename.replace('\\', '\\\\')
    #elif path.lower().startswith('musicdb') and len(filename) > 0:
    #    cmd = 'PlayMedia("%s")' % filename
    elif path.lower().startswith('androidapp'):
        cmd = 'StartAndroidActivity("%s")' % path.replace(
            'androidapp://sources/apps/', '', 1)
    else:
        cmd = 'PlayMedia("%s")' % path
        cmd = favourite.updateSFOption(cmd, 'winID', window)

    cmd = favourite.addFanart(cmd, fanart)
    cmd = favourite.updateSFOption(cmd, 'desc', desc)

    if meta:
        import urllib
        meta = utils.convertDictToURL(meta)
        cmd = favourite.updateSFOption(cmd, 'meta', urllib.quote_plus(meta))

    if isFolder:
        cmd = cmd.replace('")', '",return)')

    return cmd
Beispiel #2
0
def _setPasteProperties(thumb='', fanart='', desc='', label=None, cmd=None, meta=None):
    if not thumb:  thumb  = ''
    if not fanart: fanart = ''
    if not desc:   desc   = ''
    if not cmd:    cmd    = ''
    if not label:  label  = ''
    if not meta:   meta   = ''

    xbmcgui.Window(10000).setProperty('SF_THUMB',       thumb)
    xbmcgui.Window(10000).setProperty('SF_FANART',      fanart)
    xbmcgui.Window(10000).setProperty('SF_DESCRIPTION', urllib.quote(desc))
    xbmcgui.Window(10000).setProperty('SF_LABEL',       label)
    xbmcgui.Window(10000).setProperty('SF_META',        utils.convertDictToURL(meta))

    if len(xbmcgui.Window(10000).getProperty('SF_TYPE')) > 0:
        return

    xbmcgui.Window(10000).setProperty('SF_TYPE', 'capture')
    xbmcgui.Window(10000).setProperty('SF_CMD',  cmd)
Beispiel #3
0
def getCmd(path, fanart, desc, window, filename, isFolder, meta):
    import favourite

    if path.lower().startswith('addons://user/'):
        path = path.replace('addons://user/', 'plugin://')
        isFolder = True
        window = 10025

    if isFolder:
        cmd = 'ActivateWindow(%d,"%s' % (window, path)
    elif path.lower().startswith('script'):
        #if path[-1] == '/':
        #    path = path[:-1]
        cmd = 'RunScript("%s' % path.replace('script://', '')
    elif path.lower().startswith('videodb') and len(filename) > 0:
        cmd = 'PlayMedia("%s' % filename.replace('\\', '\\\\')
    #elif path.lower().startswith('musicdb') and len(filename) > 0:
    #    cmd = 'PlayMedia("%s")' % filename
    elif path.lower().startswith('androidapp'):
        cmd = 'StartAndroidActivity("%s")' % path.replace(
            'androidapp://sources/apps/', '', 1)
    else:
        cmd = 'PlayMedia("%s")' % path
        cmd = favourite.updateSFOption(cmd, 'winID', window)

    cmd = favourite.addFanart(cmd, fanart)
    cmd = favourite.updateSFOption(cmd, 'desc', desc)

    if meta:
        import urllib
        meta = utils.convertDictToURL(meta)
        cmd = favourite.updateSFOption(cmd, 'meta', urllib.quote_plus(meta))

    if isFolder:
        cmd = cmd.replace('")', '",return)')

    return cmd
Beispiel #4
0
def getCmd(path, fanart, desc, window, filename, isFolder, meta):
    import favourite

    if path.lower().startswith('addons://user/'):
        path     = path.replace('addons://user/', 'plugin://')
        isFolder = True
        window   = 10025

    if isFolder:
        cmd =  'ActivateWindow(%d,"%s' % (window, path)
    elif path.lower().startswith('script'):
        #if path[-1] == '/':
        #    path = path[:-1]
        cmd = 'RunScript("%s' % path.replace('script://', '')
    elif path.lower().startswith('videodb') and len(filename) > 0:
        cmd = 'PlayMedia("%s' % filename.replace('\\', '\\\\')
    #elif path.lower().startswith('musicdb') and len(filename) > 0:
    #    cmd = 'PlayMedia("%s")' % filename
    elif path.lower().startswith('androidapp'):
        cmd = 'StartAndroidActivity("%s")' % path.replace('androidapp://sources/apps/', '', 1)
    else:            
        cmd = 'PlayMedia("%s")' % path
        cmd = favourite.updateSFOption(cmd, 'winID', window)

    cmd = favourite.addFanart(cmd, fanart)
    cmd = favourite.updateSFOption(cmd, 'desc', desc)

    if meta:
        import urllib
        meta = utils.convertDictToURL(meta)
        cmd  = favourite.updateSFOption(cmd, 'meta', urllib.quote_plus(meta))

    if isFolder:
        cmd = cmd.replace('")', '",return)')

    return cmd
def doMenu(mode):
    import menuUtils

    utils.log('**** Context Menu Information ****')

    window = xbmcgui.getCurrentWindowId()

    DEBUG = ADDON.getSetting('DEBUG') == 'true'
    if DEBUG:
        utils.DialogOK('Current Window ID %d' % window)

    utils.log('Capture window\t: %d' % window)

    if window > 12999:
        doStandard(useScript=False)
        return

    # to prevent master profile setting being used in other profiles
    if mode == 0 and ADDON.getSetting('CONTEXT') != 'true':
        doStandard(useScript=False)
        return

    folder = xbmc.getInfoLabel('Container.FolderPath')
    path = xbmc.getInfoLabel('ListItem.FolderPath')

    #ignore if in Super Favourites
    if (ADDONID in folder) or (ADDONID in path):
        doStandard(useScript=False)
        return

    if mode == 0 and whitelisted():
        doStandard(useScript=False)
        return

    try:
        params = menuUtils.getCurrentParams()
    except:
        params = None

    if params == None:
        doStandard(useScript=False)
        return

    try:
        meta = menuUtils.getCurrentMeta()
    except:
        meta = {}

    utils.outputDict(params, 'Capture Parameters')
    utils.outputDict(meta, 'Capture Metadata')

    folder = params['folder']
    path = params['path']
    label = params['label']
    filename = params['filename']
    thumb = params['thumb']
    icon = params['icon']
    playable = params['isplayable']
    fanart = params['fanart']
    isFolder = params['isfolder']
    hasVideo = params['hasVideo']
    desc = params['description']
    window = params['window']
    file = params['file']
    isStream = params['isstream']

    choice = 0
    menu = []
    localAddon = None

    if MENU_QUICKLAUNCH:
        menu.append((GETTEXT(30219), _QUICKLAUNCH))

    plugins = []
    try:
        plugins = getPlugins()
        addPlugins(menu, plugins, params, _EXTRABASE)
    except Exception as e:
        utils.log('Error adding plugins : %s' % str(e))

    if len(path) > 0:

        if MENU_ADDTOFAVES:
            menu.append((GETTEXT(30047), _ADDTOFAVES))

        if MENU_ADDON_SETTINGS:
            localAddon = utils.findAddon(path)
            if localAddon:
                name = utils.getSettingsLabel(localAddon)
                menu.append((name, _SETTINGS))

        if MENU_DEF_ISEARCH:
            default = getDefaultSearch()
            if len(default) > 0:
                menu.append((GETTEXT(30098) % default, _SEARCHDEF))

        if MENU_ISEARCH: menu.append((GETTEXT(30054), _SEARCH))

        if MENU_IRECOMMEND: menu.append((GETTEXT(30088), _RECOMMEND))

        if MENU_COPY_PROPS: menu.append((GETTEXT(30209), _COPYITEM))

        if MENU_VIEW_IMAGES:
            if len(thumb) > 0 or len(fanart) > 0:
                menu.append((GETTEXT(30216), _SHOWIMAGE))

    if MENU_SF_SETTINGS:
        menu.append((GETTEXT(30049), _SF_SETTINGS))

    stdMenu = False
    if MENU_STD_MENU:
        if (len(path) > 0) or (window == 10034):  #10034 is profile dialog
            stdMenu = True
            menu.append((GETTEXT(30048), _STD_MENU))

    if hasVideo:
        if MENU_DOWNLOADS and isStream:
            menu.append((GETTEXT(30259), _DOWNLOAD))

        if len(menu) == 0:
            doStandard(useScript=False)
            return

        nowPlaying = GETTEXT(30220)
        menu.append((nowPlaying, _PLAYLIST))

    if len(menu) == 0 or (len(menu) == 1 and stdMenu):
        doStandard(useScript=False)
        return

    xbmcgui.Window(10000).setProperty('SF_MENU_VISIBLE', 'true')

    dialog = ADDON.getSetting('CONTEXT_STYLE') == '1'

    import menus

    if dialog:
        choice = menus.selectMenu(utils.TITLE, menu)
    else:
        choice = menus.showMenu(
            ADDONID, menu,
            useBuiltin=False)  #False to allow right-click to std context menu

    utils.log('selection\t\t: %s' % choice)

    if choice >= _EXTRABASE:
        module = (choice - _EXTRABASE) / 1000
        option = (choice - _EXTRABASE) % 1000

        utils.log('plugin\t\t: %s' % module)
        utils.log('option\t\t: %s' % option)

        try:
            plugins[module].process(option, params)
        except Exception as e:
            utils.log('Error processing plugin: %s' % str(e))

    if choice == _QUICKLAUNCH:
        try:
            quickLaunch()
        except:
            pass

    if choice == _STD_MENU:
        doStandard(useScript=True)

    if choice == _PLAYLIST:
        activateWindow('videoplaylist')

    if choice == _DOWNLOAD:
        try:
            menuUtils.doDownload(file)
        except:
            pass

    if choice == _SF_SETTINGS:
        utils.ADDON.openSettings()

    if choice == _SETTINGS:
        xbmcaddon.Addon(localAddon).openSettings()

    if choice == _ADDTOFAVES:
        menuUtils.addToFaves(params, meta)

    if choice == _LAUNCH_SF:
        utils.LaunchSF()

    if choice in [_SEARCH, _SEARCHDEF, _RECOMMEND]:
        if utils.ADDON.getSetting('STRIPNUMBERS') == 'true':
            label = utils.Clean(label)

        thumb = thumb if len(thumb) > 0 else 'null'
        fanart = fanart if len(fanart) > 0 else 'null'

        #declared in default.py
        _SUPERSEARCH = 0
        _SUPERSEARCHDEF = 10
        _RECOMMEND_KEY = 2700

        valid = [10001, 10002, 10025, 10502]

        if window not in valid:
            window = 10025  #video window

        import urllib

        if choice == _RECOMMEND:
            mode = _RECOMMEND_KEY
        else:
            mode = _SUPERSEARCH if (choice == _SEARCH) else _SUPERSEARCHDEF

        if mode == _SUPERSEARCHDEF:
            return launchDefaultSearch(label)

        try:
            meta = urllib.quote_plus(utils.convertDictToURL(meta))
        except:
            meta = ''

        cmd = 'ActivateWindow(%d,"plugin://%s/?mode=%d&keyword=%s&image=%s&fanart=%s&meta=%s")' % (
            window, ADDONID, mode, urllib.quote_plus(label),
            urllib.quote_plus(thumb), urllib.quote_plus(fanart), meta)

        activateCommand(cmd)

    if choice == _COPYITEM:
        #if not fanart:
        #    fanart = thumb

        cmd = menuUtils.getCmd(path, fanart, desc, window, filename, isFolder,
                               meta)

        import clipboard
        clipboard.setPasteProperties(thumb, fanart, desc, label, cmd, meta)

    if choice == _SHOWIMAGE:
        #if not fanart:
        #    fanart = thumb

        import viewer
        viewer.show(fanart, thumb, ADDONID)
Beispiel #6
0
def _getCmd(path, fanart, desc, window, filename, isFolder, meta, picture):
    if path.lower().startswith('addons://user/'):
        path     = path.replace('addons://user/', 'plugin://')
        isFolder = True
        window   = 10025

    window = fixWindowID(window)

    if window == 10003:#FileManager
        import sfile
        import os

        isFolder = sfile.isdir(path)
        if isFolder:
            #special paths fail to open - http://trac.kodi.tv/ticket/17333
            if path.startswith('special://'):
                path = xbmc.translatePath(path)
            path = path.replace('%s%s' % (os.sep, os.sep), os.sep)
            path = path.replace(os.sep, '/')
            folder = path
            if folder.endswith('/'):
                folder = folder[:-1]
            folder = folder.rsplit('/', 1)[-1]
            #if not utils.DialogYesNo(GETTEXT(30271) % folder, GETTEXT(30272)):
            #    return None
        else:
            if not sfile.isfile(path):
                return None

    if favourite.isKodiCommand(path):
        return path
    elif len(picture) > 0:
        cmd = 'ShowPicture("%s")'  % picture
    elif isFolder:
        cmd =  'ActivateWindow(%d,"%s' % (window, path)
    elif path.lower().startswith('script'):
        #if path[-1] == '/':
        #    path = path[:-1]
        cmd = 'RunScript("%s' % path.replace('script://', '')
    elif path.lower().startswith('videodb') and len(filename) > 0:
        cmd = 'PlayMedia("%s' % filename.replace('\\', '\\\\')
    #elif path.lower().startswith('musicdb') and len(filename) > 0:
    #    cmd = 'PlayMedia("%s")' % filename
    elif path.lower().startswith('androidapp'):
        cmd = 'StartAndroidActivity("%s")' % path.replace('androidapp://sources/apps/', '', 1)
    else:            
        cmd = 'PlayMedia("%s")' % path
        cmd = favourite.updateSFOption(cmd, 'winID', window)

    cmd = favourite.addFanart(cmd, fanart)
    cmd = favourite.updateSFOption(cmd, 'desc', desc)

    if meta:
        import urllib
        meta = utils.convertDictToURL(meta)
        cmd  = favourite.updateSFOption(cmd, 'meta', urllib.quote_plus(meta))

    if isFolder:
        cmd = cmd.replace('")', '",return)')

    return cmd
Beispiel #7
0
        if window not in valid:
            window = 10025  #video window

        import urllib

        if choice == _RECOMMEND:
            mode = _RECOMMEND_KEY
        else:
            mode = _SUPERSEARCH if (choice == _SEARCH) else _SUPERSEARCHDEF

        if mode == _SUPERSEARCHDEF:
            return launchDefaultSearch(label)

        try:
            meta = urllib.quote_plus(utils.convertDictToURL(meta))
        except:
            meta = ''

        cmd = 'ActivateWindow(%d,"plugin://%s/?mode=%d&keyword=%s&image=%s&fanart=%s&meta=%s")' % (
            window, ADDONID, mode, urllib.quote_plus(label),
            urllib.quote_plus(thumb), urllib.quote_plus(fanart), meta)

        activateCommand(cmd)

    if choice == _COPYITEM:
        #if not fanart:
        #    fanart = thumb

        cmd = menuUtils.getCmd(path, fanart, desc, window, filename, isFolder,
                               meta)
Beispiel #8
0
        valid = [10001, 10002, 10025, 10502]

        if window not in valid:
            window = 10025 #video window

        import urllib   

        if choice == _RECOMMEND:
            mode = _RECOMMEND_KEY
        else:
            mode = _SUPERSEARCH if (choice == _SEARCH) else _SUPERSEARCHDEF

        if mode == _SUPERSEARCHDEF:
            return launchDefaultSearch(label)

        try:    meta = urllib.quote_plus(utils.convertDictToURL(meta))
        except: meta = ''
             
        cmd = 'ActivateWindow(%d,"plugin://%s/?mode=%d&keyword=%s&image=%s&fanart=%s&meta=%s")' % (window, ADDONID, mode, urllib.quote_plus(label), urllib.quote_plus(thumb), urllib.quote_plus(fanart), meta)

        activateCommand(cmd)

    if choice == _COPYITEM:  
        #if not fanart:
        #    fanart = thumb

        cmd = menuUtils.getCmd(path, fanart, desc, window, filename, isFolder, meta)

        import clipboard
        clipboard.setPasteProperties(thumb, fanart, desc, label, cmd, meta)