Example #1
0
def doDownload(file):
    utils.log('download url: %s' % file)
    dst = ADDON.getSetting('DOWNLOAD_FOLDER')

    import sfile
    sfile.makedirs(dst)

    if not sfile.exists(dst):
        utils.DialogOK(GETTEXT(30256), GETTEXT(30257))
        utils.openSettings(ADDONID, 2.24)
        xbmc.sleep(500)
        while (xbmc.getCondVisibility('Window.IsActive(addonsettings)') == 1):
            xbmc.sleep(100)

    dst = ADDON.getSetting('DOWNLOAD_FOLDER')
    if not sfile.exists(dst):
        utils.DialogOK(GETTEXT(30256))
        return

    import os
    dst = os.path.join(ADDON.getSetting('DOWNLOAD_FOLDER'),
                       getDownloadTitle(file))

    if utils.DialogYesNo(GETTEXT(30243), GETTEXT(30244)):
        xbmc.executebuiltin('Action(Stop)')

    import download
    download.download(file, dst, utils.TITLE)
Example #2
0
def newChannel():
    title = ''

    while True:
        title = getText('Please enter channel name', title)
        if not title:
            return False

        id = createID(title)

        try:
            current, dirs, files = sfile.walk(OTT_CHANNELS)
        except Exception, e:
            return False

        duplicate = False

        for file in files:
            if id.lower() == file.lower():
                duplicate = True
                break

        if not duplicate:
            break

        utils.DialogOK('%s clashes with an existing channel.' % title,
                       'Please enter a different name.')
Example #3
0
def unlocked(path):
    folderConfig = os.path.join(path, FOLDERCFG)
    lock = getParam('LOCK', folderConfig)
    if not lock:
        return True

    import cache
    if cache.exists(path):
        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(ADDON.getSetting('CACHE'))
    period = periods[setting]

    cache.add(path, period)

    return True
Example #4
0
def main():
    if utils.isATV():
        utils.DialogOK(GETTEXT(30118), GETTEXT(30119))
        return False

    key = recordKey()
    if key < 1:
        utils.DialogOK(GETTEXT(30269))
        return

    start = 'key id="%d"' % key
    end = 'key'

    if utils.WriteKeymap(start, end):
        utils.DialogOK(GETTEXT(30270))
        xbmc.executebuiltin('Action(reloadkeymaps)')
Example #5
0
def doExport():
    try:
        include = utils.DialogYesNo(GETTEXT(30129),
                                    line2='',
                                    line3=GETTEXT(30130),
                                    noLabel=None,
                                    yesLabel=None)
        folder = getFolder(GETTEXT(30131))

        if not folder:
            return False

        filename = 'Super Favourites.zip'
        src = os.path.join(HOME, filename)
        dst = os.path.join(folder, filename)

        doZipfile(src, include)

        sfile.remove(dst)
        sfile.rename(src, dst)

        utils.DialogOK(GETTEXT(30132))
        return True

    except Exception, e:
        utils.log('Error in doExport %s' % str(e))
Example #6
0
def deleteFile(path, name):
    if not utils.DialogYesNo(GETTEXT(30044) % name, GETTEXT(30045)):
        return

    import sfile
    sfile.delete(path)
    if sfile.exists(path):
        utils.DialogOK(GETTEXT(30046) % name)
Example #7
0
def download(silent=False):
    params = menuUtils.getCurrentParams()

    if params == None or ('file' not in params):
        if not silent:
            import utils
            utils.DialogOK(utils.GETTEXT(30261))
        return

    menuUtils.doDownload(params['file'])
Example #8
0
def doImport():
    try:
        success = False

        if REMOTE:
            success = _doImportFromRemote()
        else:
            filename = getFile(GETTEXT(30134), 'zip')

            if not filename:
                return False
            success = _doImportFromLocal(filename)

        if success:
            utils.DialogOK(GETTEXT(30133))
            return True
    except:
        pass

    utils.DialogOK(GETTEXT(30137))
Example #9
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
Example #10
0
def createNewFolder(current):
    text = clean(getText(GETTEXT(30013)))
    if not text:
        return False

    folder = os.path.join(current, text)
    if os.path.exists(folder):
        utils.DialogOK('', GETTEXT(30014) % text)
        return False

    os.makedirs(xbmc.translatePath(folder))
    return True
Example #11
0
def getLogos(label, url):
    path = os.path.join(EXTRAS, 'logos')
    zipfile = os.path.join(path, 'logos.zip')

    if utils.DialogYesNo(
            'Would you like to install ' + label,
            'and make it your active logo-pack?',
            'It will be downloaded and installed into your system.'):
        download(path, zipfile)
        utils.DialogOK(label + ' logo-pack has been installed successfully.',
                       'It is now set as your active logo-pack.',
                       'Please restart On-Tapp.TV. Thank you.')
        OTT_ADDON.setSetting('dixie.logo.folder', label)
Example #12
0
def getDownloadPath(name):
    downloadFolder = ADDON.getSetting('DOWNLOAD_FOLDER')

    if downloadFolder == '':
        utils.DialogOK(GETTEXT(30060))
	ADDON.openSettings() 
	downloadFolder = ADDON.getSetting('DOWNLOAD_FOLDER')

    if downloadFolder == '':
        return None

    import re
    filename = re.sub('[:\\/*?\<>|"]+', '', name)
    return os.path.join(downloadFolder, filename)
Example #13
0
def isKodiCommand(cmd):
    cmd = cmd.lower()
    commands = []
    commands.append('activatewindow')
    commands.append('runscript')
    commands.append('playmedia')
    commands.append('startandroidactivity')
    commands.append('showpicture')

    for command in commands:
        if cmd.startswith(command):
            utils.DialogOK("FLLY FORMED")
            return True

    return False
Example #14
0
def add(silent=False):
    params = menuUtils.getCurrentParams()
    meta = menuUtils.getCurrentMeta()

    import utils
    utils.outputDict(params, 'menu_addtofaves - params')
    utils.outputDict(meta, 'menu_addtofaves - meta')

    if params == None:
        if not silent:
            import utils
            utils.DialogOK(utils.GETTEXT(30260))
        return

    menuUtils.addToFaves(params, meta)
Example #15
0
def main():
    if utils.isATV():
        utils.DialogOK(GETTEXT(30118), GETTEXT(30119))
        return False

    key = recordKey()
    if key < 1:
        return

    start = 'key id="%d"' % key
    end = 'key'

    utils.WriteKeymap(start, end)

    return True
Example #16
0
def doExport():
    try:
        include = utils.DialogYesNo(GETTEXT(30129), line2='', line3=GETTEXT(30130), noLabel=None, yesLabel=None)
        folder  = getFolder(GETTEXT(30131))

        if not folder:
            return False

        filename = os.path.join(folder, 'Super Favourites.zip')

        doZipfile(filename, include)
        utils.DialogOK(GETTEXT(30132))
        return True

    except Exception, e:
        utils.log(e)
Example #17
0
def download(episode, name):
    if xbmcgui.Window(10000).getProperty('GLOBAL-DOWNLOADING'):
        utils.DialogOK(GETTEXT(30047))
        return

    downloadPath = getDownloadPath(name)

    if not downloadPath:
        return

    #add original extension
    downloadPath += '.' + episode.rsplit('.', 1)[-1]

    url = 'http://fs.geronimo.thisisglobal.com/audio/' + episode

    import download
    download. download(url, downloadPath, title=name)
Example #18
0
def pasteFolder(dst, addonid):
    if len(dst) == 0:
        return False

    src = xbmcgui.Window(10000).getProperty('SF_FILE')
    cut = xbmcgui.Window(10000).getProperty('SF_TYPE').lower() == 'cutfolder'

    root       = src.rsplit(os.sep, 1)[0]
    folderName = src.rsplit(os.sep, 1)[-1]

    same = (root == dst)

    link = True

    if dst == 'special://profile': #i.e. Kodi favourites
        if cut:
            cut   = False
            line1 = GETTEXT(30187) % DISPLAYNAME
            line2 = GETTEXT(30188) % folderName
            line3 = GETTEXT(30189)
            link  = utils.DialogYesNo(line1, line2, line3, noLabel=GETTEXT(30190), yesLabel=GETTEXT(30186))
            if not link:
                return
    else:
        if cut:
            link = False
        else:  
            line1 = GETTEXT(30183) % folderName
            link  = True if same else utils.DialogYesNo(line1, GETTEXT(30184), noLabel=GETTEXT(30185), yesLabel=GETTEXT(30186))

    if link:
        success = pasteFolderLink(src, dst, folderName, addonid)
    else:
        success = pasteFolderCopy(src, dst, folderName)

    if not success:
        line1 = GETTEXT(30191) % folderName
        utils.DialogOK(line1)
        return False

    if cut:
        import sfile
        sfile.rmtree(src)

    return success
Example #19
0
def done(title, dest, downloaded):
    playing = xbmc.Player().isPlaying()

    text = xbmcgui.Window(10000).getProperty('GLOBAL-DOWNLOADED')

    if len(text) > 0:
        text += '[CR]'

    if downloaded:
        text += '%s : %s' % (dest.rsplit(os.sep)[-1], GETTEXT(30061))
    else:
        text += '%s : %s' % (dest.rsplit(os.sep)[-1], GETTEXT(30062))

    xbmcgui.Window(10000).setProperty('GLOBAL-DOWNLOADED', text)

    if (not downloaded) or (not playing):
        utils.DialogOK(text)
        xbmcgui.Window(10000).clearProperty('GLOBAL-DOWNLOADED')
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)
Example #21
0
        recommendIMDB(imdb, keyword)

    except:
        winID = xbmcgui.getCurrentWindowId()
        cmd = '%s?mode=%d&keyword=%s&imdb=%s&callback=%s' % (
            sys.argv[0], _RECOMMEND_IMDB, urllib.quote_plus(keyword),
            urllib.quote_plus(imdb), 'callback')
        xbmc.executebuiltin('Container.Refresh(%s)' % cmd)

        cacheToDisc = False
        doEnd = False

elif mode == _PLAYTRAILER:
    import yt
    if not yt.PlayVideo(path):
        utils.DialogOK(GETTEXT(30092))

elif mode == _MAIN:
    main()

else:
    #do nothing
    nItem = 1

#make sure at least 1 line is showing to allow context menu to be displayed
if nItem < 1:
    addDir('', _SEPARATOR, thumbnail=BLANK, isFolder=False)

if doRefresh:
    refresh()
Example #22
0
def doMenu():
    try:
        import utils
    except:
        doStandard(useScript=False)
        return

    active = [1, 2, 25, 40, 500, 501, 502]  #28 is video Playlist
    window = xbmcgui.getCurrentWindowId()
    utils.log('Window     : %d' % window)
    if window - 10000 not in active:
        doStandard(useScript=False)
        return

    import contextmenu

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

    folder = xbmc.getInfoLabel('Container.FolderPath')
    #ignore if in Super Favourites
    if utils.ADDONID in folder:
        doStandard(useScript=False)
        return

    choice = 0
    label = xbmc.getInfoLabel('ListItem.Label')
    path = xbmc.getInfoLabel('ListItem.FolderPath')
    filename = xbmc.getInfoLabel('ListItem.FilenameAndPath')
    name = xbmc.getInfoLabel('ListItem.Label')
    thumb = xbmc.getInfoLabel('ListItem.Thumb')
    playable = xbmc.getInfoLabel(
        'ListItem.Property(IsPlayable)').lower() == 'true'
    fanart = xbmc.getInfoLabel('ListItem.Property(Fanart_Image)')
    isFolder = xbmc.getCondVisibility('ListItem.IsFolder') == 1

    try:
        file = xbmc.Player().getPlayingFile()
    except:
        file = None

    isStream = False
    if file:
        isStream = file.startswith('http://')

    #GOTHAM only
    #if hasattr(xbmc.Player(), 'isInternetStream'):
    #    isStream = xbmc.Player().isInternetStream()
    #elif file:
    #    isStream = file.startswith('http://')

    utils.log('**** Context Menu Information ****')
    utils.log('Label      : %s' % label)
    utils.log('Folder     : %s' % folder)
    utils.log('Path       : %s' % path)
    utils.log('Filename   : %s' % filename)
    utils.log('Name       : %s' % name)
    utils.log('Thumb      : %s' % thumb)
    utils.log('Fanart     : %s' % fanart)
    utils.log('Window     : %d' % window)
    utils.log('IsPlayable : %s' % playable)
    utils.log('IsFolder   : %s' % isFolder)
    utils.log('File       : %s' % file)
    utils.log('IsStream   : %s' % isStream)

    menu = []

    #if (len(menu) == 0) and window == 12005: #video playing
    #if isStream:
    #    menu.append(('Download  %s' % label, _DOWNLOAD))
    #    menu.append(('Show Playlist',        _PLAYLIST))
    #else:
    #    return doStandard()
    #cancel download feature for now
    #return doStandard()

    if (len(menu) == 0) and len(path) > 0:
        ytID = ''

        if path.startswith(
                'plugin://plugin.video.youtube') and 'videoid=' in path:
            try:
                ytID = path.rsplit('videoid=', 1)[-1][0:11]
                menu.append((utils.GETTEXT(30104), _PLAYTUBE))
            except:
                ytID = ''

        utils.verifySuperSearch()

        default = getDefaultSearch()

        menu.append((utils.GETTEXT(30047), _ADDTOFAVES))
        menu.append((utils.GETTEXT(30049), _SF_SETTINGS))
        menu.append((utils.GETTEXT(30054), _SEARCH))

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

        menu.append((utils.GETTEXT(30048), _STD_SETTINGS))

    #elif window == 10000: #Home screen
    #    menu.append((utils.GETTEXT(30053), _LAUNCH_SF))
    #    menu.append((utils.GETTEXT(30049), _SF_SETTINGS))

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

    xbmcgui.Window(10000).setProperty('SF_MENU_VISIBLE', 'true')
    choice = contextmenu.showMenu(utils.ADDONID, menu)

    if choice == _STD_SETTINGS:
        doStandard()
        return

    xbmc.executebuiltin('Dialog.Close(all, true)')

    if choice == _PLAYLIST:
        xbmc.executebuiltin('ActivateWindow(videoplaylist)')

    #if choice == _DOWNLOAD:
    #    import download
    #    download.download(file, 'c:\\temp\\file.mpg', 'Super Favourites')

    if choice == _PLAYTUBE:
        if len(ytID) != 11:
            return
        import yt
        if not yt.PlayVideo(ytID):
            utils.DialogOK(utils.GETTEXT(30105))

    if choice == _STD_SETTINGS:
        doStandard()

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

    if choice == _ADDTOFAVES:
        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
        #elif path.lower().startswith('musicdb') and len(filename) > 0:
        #    cmd = 'PlayMedia("%s")' % filename
        else:
            cmd = 'PlayMedia("%s&sf_win_id=%d_' % (path, window)

        import urllib
        if '?' in cmd:
            cmd += '&'
        else:
            cmd += '?'

        cmd += 'sf_fanart=%s_")' % urllib.quote_plus(fanart)

        copyFave(name, thumb, cmd)

    if choice == _LAUNCH_SF:
        xbmc.executebuiltin('ActivateWindow(programs,plugin://%s)' %
                            utils.ADDONID)

    if choice == _SEARCH or choice == _SEARCHDEF:
        if utils.ADDON.getSetting('STRIPNUMBERS') == 'true':
            name = clean(name)

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

        _SUPERSEARCH = 0  #declared as  0 in default.py
        _SUPERSEARCHDEF = 10  #declared as 10 in default.py

        mode = _SUPERSEARCH if (choice == _SEARCH) else _SUPERSEARCHDEF
        videoID = 10025  #video

        if window == 10000:  #don't activate on home screen, push to video
            window = videoID

        import urllib

        cmd = 'ActivateWindow(%d,"plugin://%s/?mode=%d&keyword=%s&image=%s&fanart=%s")' % (
            window, utils.ADDONID, mode, urllib.quote_plus(name),
            urllib.quote_plus(thumb), urllib.quote_plus(fanart))
        activateCommand(cmd)
Example #23
0
def doMenu(mode):
    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)

    #active = [0, 1, 2, 3, 25, 40, 500, 501, 502, 601, 2005]
    #if window-10000 not in active:
    #    doStandard(useScript=False)
    #    return

    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
        
    choice   = 0
    label    = xbmc.getInfoLabel('ListItem.Label')
    filename = xbmc.getInfoLabel('ListItem.FilenameAndPath')
    thumb    = xbmc.getInfoLabel('ListItem.Thumb')    
    icon     = xbmc.getInfoLabel('ListItem.ActualIcon')    
    #thumb   = xbmc.getInfoLabel('ListItem.Art(thumb)')
    playable = xbmc.getInfoLabel('ListItem.Property(IsPlayable)').lower() == 'true'
    fanart   = xbmc.getInfoLabel('ListItem.Property(Fanart_Image)')
    fanart   = xbmc.getInfoLabel('ListItem.Art(fanart)')
    isFolder = xbmc.getCondVisibility('ListItem.IsFolder') == 1
    hasVideo = xbmc.getCondVisibility('Player.HasVideo') == 1
    desc     = getDescription()
   
    if not thumb:
        thumb = icon

    try:    file = xbmc.Player().getPlayingFile()
    except: file = None

    isStream = False
   
    #if hasattr(xbmc.Player(), 'isInternetStream'):
    #    isStream = xbmc.Player().isInternetStream()
    #elif file:
    if file:
        isStream = file.startswith('http')

    if window == 10003: #filemanager
        control = 0
        if xbmc.getCondVisibility('Control.HasFocus(20)') == 1:
            control = 20
        elif xbmc.getCondVisibility('Control.HasFocus(21)') == 1:
            control = 21

        if control == 0:
            return doStandard(useScript=False)

        label    = xbmc.getInfoLabel('Container(%d).ListItem.Label' % control)
        root     = xbmc.getInfoLabel('Container(%d).ListItem.Path'  % control)
        path     = root + label
        isFolder = True
        thumb    = 'DefaultFolder.png'
        #if not path.endswith(os.sep):
        #    path += os.sep

    if isFolder:
        path     = path.replace('\\', '\\\\')
        filename = filename.replace('\\', '\\\\')

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


    for key in params:
        utils.log('%s\t\t: %s' % (key, params[key]))

    menu       = []
    localAddon = None

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

    plugins    = []
    try:
        plugins = getPlugins()
        addPlugins(menu, plugins, params, _EXTRABASE)
    except Exception, e:
        utils.log('Error adding plugins : %s' % str(e))
Example #24
0
def doMenu():
    try:
        import utils
    except:
        doStandard(useScript=False)
        return

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

    active = [0, 1, 2, 25, 40, 500, 501, 502, 601]
    window = xbmcgui.getCurrentWindowId()
    utils.log('Window     : %d' % window)
    if window - 10000 not in active:
        doStandard(useScript=False)
        return

    import menus

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

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

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

    choice = 0
    label = xbmc.getInfoLabel('ListItem.Label')
    filename = xbmc.getInfoLabel('ListItem.FilenameAndPath')
    name = xbmc.getInfoLabel('ListItem.Label')
    thumb = xbmc.getInfoLabel('ListItem.Thumb')
    thumb = xbmc.getInfoLabel('ListItem.Art(thumb)')
    playable = xbmc.getInfoLabel(
        'ListItem.Property(IsPlayable)').lower() == 'true'
    fanart = xbmc.getInfoLabel('ListItem.Property(Fanart_Image)')
    fanart = xbmc.getInfoLabel('ListItem.Art(fanart)')
    isFolder = xbmc.getCondVisibility('ListItem.IsFolder') == 1
    desc = getDescription()

    try:
        file = xbmc.Player().getPlayingFile()
    except:
        file = None

    isStream = False
    if file:
        isStream = file.startswith('http://')

    #GOTHAM only
    #if hasattr(xbmc.Player(), 'isInternetStream'):
    #    isStream = xbmc.Player().isInternetStream()
    #elif file:
    #    isStream = file.startswith('http://')

    if isFolder:
        path = path.replace('\\', '\\\\')
        filename = filename.replace('\\', '\\\\')

    utils.log('**** Context Menu Information ****')
    utils.log('Label      : %s' % label)
    utils.log('Folder     : %s' % folder)
    utils.log('Path       : %s' % path)
    utils.log('Filename   : %s' % filename)
    utils.log('Name       : %s' % name)
    utils.log('Thumb      : %s' % thumb)
    utils.log('Fanart     : %s' % fanart)
    utils.log('Window     : %d' % window)
    utils.log('IsPlayable : %s' % playable)
    utils.log('IsFolder   : %s' % isFolder)
    utils.log('File       : %s' % file)
    utils.log('IsStream   : %s' % isStream)

    menu = []

    #if (len(menu) == 0) and window == 12005: #video playing
    #if isStream:
    #    menu.append(('Download  %s' % label, _DOWNLOAD))
    #    menu.append(('Show Playlist',        _PLAYLIST))
    #else:
    #    return doStandard()
    #cancel download feature for now
    #return doStandard()

    if (len(menu) == 0) and len(path) > 0:
        menu.append((utils.GETTEXT(30047), _ADDTOFAVES))
        menu.append((utils.GETTEXT(30049), _SF_SETTINGS))

        if utils.ADDON.getSetting('SHOWSS') == 'true':
            menu.append((utils.GETTEXT(30054), _SEARCH))

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

        menu.append((utils.GETTEXT(30048), _STD_SETTINGS))

    elif window == 10000:  #Home screen
        #menu.append((utils.GETTEXT(30053), _LAUNCH_SF))
        #menu.append((utils.GETTEXT(30049), _SF_SETTINGS))
        pass

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

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

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

    if dialog:
        choice = menus.selectMenu(utils.TITLE, menu)
    else:
        choice = menus.showMenu(utils.ADDONID, menu, utils.HELIX)

    if choice == _STD_SETTINGS:
        doStandard()
        return

    xbmc.executebuiltin('Dialog.Close(all, true)')

    if choice == _PLAYLIST:
        xbmc.executebuiltin('ActivateWindow(videoplaylist)')

    #if choice == _DOWNLOAD:
    #    import download
    #    download.download(file, 'c:\\temp\\file.mpg', 'Super Favourites')

    if choice == _STD_SETTINGS:
        doStandard()

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

    if choice == _ADDTOFAVES:
        import favourite
        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
        #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 isFolder:
            cmd = cmd.replace('")', '",return)')

        copyFave(name, thumb, cmd)

    if choice == _LAUNCH_SF:
        utils.LaunchSF()

    if choice == _SEARCH or choice == _SEARCHDEF:
        if utils.ADDON.getSetting('STRIPNUMBERS') == 'true':
            name = utils.Clean(name)

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

        _SUPERSEARCH = 0  #declared as  0 in default.py
        _SUPERSEARCHDEF = 10  #declared as 10 in default.py

        mode = _SUPERSEARCH if (choice == _SEARCH) else _SUPERSEARCHDEF
        videoID = 10025  #video

        if window == 10000:  #don't activate on home screen, push to video
            window = videoID

        import urllib

        cmd = 'ActivateWindow(%d,"plugin://%s/?mode=%d&keyword=%s&image=%s&fanart=%s")' % (
            window, utils.ADDONID, mode, urllib.quote_plus(name),
            urllib.quote_plus(thumb), urllib.quote_plus(fanart))
        activateCommand(cmd)
Example #25
0
def doMenu():
    DEBUG = ADDON.getSetting('DEBUG') == 'true'
    if DEBUG:
        window = xbmcgui.getCurrentWindowId()
        utils.DialogOK('Current Window ID %d' % window)

    active = [0, 1, 2, 3, 25, 40, 500, 501, 502, 601, 2005]
    window = xbmcgui.getCurrentWindowId()
    utils.log('Window     : %d' % window)
    if window - 10000 not in active:
        doStandard(useScript=False)
        return

    import menus

    # to prevent master profile setting being used in other profiles
    if 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

    choice = 0
    label = xbmc.getInfoLabel('ListItem.Label')
    filename = xbmc.getInfoLabel('ListItem.FilenameAndPath')
    name = xbmc.getInfoLabel('ListItem.Label')
    thumb = xbmc.getInfoLabel('ListItem.Thumb')
    icon = xbmc.getInfoLabel('ListItem.ActualIcon')
    #thumb    = xbmc.getInfoLabel('ListItem.Art(thumb)')
    playable = xbmc.getInfoLabel(
        'ListItem.Property(IsPlayable)').lower() == 'true'
    fanart = xbmc.getInfoLabel('ListItem.Property(Fanart_Image)')
    fanart = xbmc.getInfoLabel('ListItem.Art(fanart)')
    isFolder = xbmc.getCondVisibility('ListItem.IsFolder') == 1
    desc = getDescription()

    if not thumb:
        thumb = icon

    try:
        file = xbmc.Player().getPlayingFile()
    except:
        file = None

    isStream = False

    if hasattr(xbmc.Player(), 'isInternetStream'):
        isStream = xbmc.Player().isInternetStream()
    elif file:
        isStream = file.startswith('http://')

    if window == 10003:  #filemanager
        control = 0
        if xbmc.getCondVisibility('Control.HasFocus(20)') == 1:
            control = 20
        elif xbmc.getCondVisibility('Control.HasFocus(21)') == 1:
            control = 21

        if control == 0:
            return doStandard()

        name = xbmc.getInfoLabel('Container(%d).ListItem.Label' % control)
        root = xbmc.getInfoLabel('Container(%d).ListItem.Path' % control)
        path = root + name
        isFolder = True
        thumb = 'DefaultFolder.png'
        #if not path.endswith(os.sep):
        #    path += os.sep

    if isFolder:
        path = path.replace('\\', '\\\\')
        filename = filename.replace('\\', '\\\\')

    utils.log('**** Context Menu Information ****')
    utils.log('Label      : %s' % label)
    utils.log('Folder     : %s' % folder)
    utils.log('Path       : %s' % path)
    utils.log('Filename   : %s' % filename)
    utils.log('Name       : %s' % name)
    utils.log('Thumb      : %s' % thumb)
    utils.log('Fanart     : %s' % fanart)
    utils.log('Window     : %d' % window)
    utils.log('IsPlayable : %s' % playable)
    utils.log('IsFolder   : %s' % isFolder)
    utils.log('File       : %s' % file)
    utils.log('IsStream   : %s' % isStream)

    menu = []
    localAddon = None

    #if xbmc.getCondVisibility('Player.HasVideo') == 1:
    #    if isStream:
    #        menu.append(('Download  %s' % label, _DOWNLOAD))
    #        menu.append(('Now playing...',       _PLAYLIST))

    if len(path) > 0:
        if MENU_ADDTOFAVES: menu.append((GETTEXT(30047), _ADDTOFAVES))

        if MENU_ADDON_SETTINGS:
            localAddon = utils.findAddon(path)
            if localAddon:
                label = utils.getSettingsLabel(localAddon)
                menu.append((label, _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:
            if len(thumb) > 0 or len(fanart) > 0:
                menu.append((GETTEXT(30209), _COPYIMAGES))
                if MENU_VIEW_IMAGES: menu.append((GETTEXT(30216), _SHOWIMAGE))
            else:
                if len(description) > 0:
                    menu.append((GETTEXT(30209), _COPYIMAGES))

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

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

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

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

    if dialog:
        choice = menus.selectMenu(utils.TITLE, menu)
    else:
        choice = menus.showMenu(ADDONID, menu)

    #if choice == _STD_MENU:
    #    doStandard()
    #    return

    xbmc.executebuiltin('Dialog.Close(all, true)')

    if choice == _PLAYLIST:
        xbmc.executebuiltin('ActivateWindow(videoplaylist)')

    if choice == _DOWNLOAD:
        import download
        download.doDownload(file, 'c:\\temp\\file.mpg', 'Super Favourites', '',
                            True)

    if choice == _STD_MENU:
        doStandard()

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

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

    if choice == _ADDTOFAVES:
        import favourite
        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
        #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 isFolder:
            cmd = cmd.replace('")', '",return)')

        copyFave(name, thumb, cmd)

    if choice == _LAUNCH_SF:
        utils.LaunchSF()

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

        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

        videoID = 10025  #video

        if window == 10000:  #don't activate on home screen, push to video
            window = videoID

        import urllib

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

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

        activateCommand(cmd)

    if choice == _COPYIMAGES:
        if not fanart:
            fanart = thumb

        xbmcgui.Window(10000).setProperty('SF_THUMB', thumb)
        xbmcgui.Window(10000).setProperty('SF_FANART', fanart)
        xbmcgui.Window(10000).setProperty('SF_DESCRIPTION', desc)

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

        import viewer
        viewer.show(fanart, thumb, ADDONID)
Example #26
0
def editChannels():
    channelzip = xbmc.translatePath(
        'special://home/addons/script.tvportal.tools/resources/channels.zip')
    cfgfile = os.path.join(TVP_PROFILE, 'settings.cfg')
    channels = getAllChannels(ALPHASORT)
    totalItems = len(channels)
    if not totalItems:
        utils.DialogOK(
            'There are no channels scanned in, a dummy channel will now be created so you can start to create your own channels.'
        )
        if os.path.exists(cfgfile):
            os.remove(cfgfile)
        extract.all(channelzip, TVP_PROFILE)
        xbmc.executebuiltin('Container.Refresh')
    else:
        for ch in channels:
            channel = ch[2]
            id = ch[1]
            title = channel.title
            logo = channel.logo
            weight = channel.weight
            hidden = channel.visible == 0
            stream = channel.streamUrl
            userDef = channel.userDef == 1
            desc = channel.desc
            categories = channel.categories
            isClone = channel.isClone == 1

            if hidden and not SHOWHIDDEN:
                continue

            menu = []
            #menu.append(('Rename channel', 'XBMC.RunPlugin(%s?mode=%d&id=%s)' % (sys.argv[0], _RENAME, urllib.quote_plus(id))))
            #menu.append(('Change logo',    'XBMC.RunPlugin(%s?mode=%d&id=%s)' % (sys.argv[0], _LOGO,   urllib.quote_plus(id))))
            menu.append(('Edit channel', 'XBMC.RunPlugin(%s?mode=%d&id=%s)' %
                         (sys.argv[0], _EDIT, urllib.quote_plus(id))))

            if inSelection(weight):
                menu.append(
                    ('Hide selection',
                     'XBMC.RunPlugin(%s?mode=%d)' % (sys.argv[0], _HIDE)))
                if SHOWHIDDEN:
                    menu.append(
                        ('Show selection',
                         'XBMC.RunPlugin(%s?mode=%d)' % (sys.argv[0], _SHOW)))
            else:
                hideLabel = 'Show channel' if hidden else 'Hide channel'
                menu.append(
                    (hideLabel, 'XBMC.RunPlugin(%s?mode=%d&id=%s)' %
                     (sys.argv[0], _TOGGLEHIDE, urllib.quote_plus(id))))

            if (not ALPHASORT) and (weight != START_WEIGHT) and (weight !=
                                                                 END_WEIGHT):
                menu.append(
                    ('Select channel',
                     'XBMC.RunPlugin(%s?mode=%d&id=%s&weight=%d)' %
                     (sys.argv[0], _SELECT, urllib.quote_plus(id), weight)))

            if inSelection(weight):
                pass
            elif isSelection() and (not ALPHASORT):
                menu.append(('Insert selection above',
                             'XBMC.RunPlugin(%s?mode=%d&weight=%d)' %
                             (sys.argv[0], _INSERTABOVE, weight)))
                menu.append(('Insert selection below',
                             'XBMC.RunPlugin(%s?mode=%d&weight=%d)' %
                             (sys.argv[0], _INSERTBELOW, weight)))

            if START_WEIGHT > -1:
                menu.append(('Clear selection', 'XBMC.RunPlugin(%s?mode=%d)' %
                             (sys.argv[0], _CANCELSELECT)))

            if not userDef:
                menu.append(
                    ('Clone channel', 'XBMC.RunPlugin(%s?mode=%d&id=%s)' %
                     (sys.argv[0], _CLONE, urllib.quote_plus(id))))


#            menu.append(('Create new channel', 'XBMC.RunPlugin(%s?mode=%d)' % (sys.argv[0], _NEWCHANNEL)))

            if userDef or isClone:
                menu.append(
                    ('Remove channel', 'XBMC.RunPlugin(%s?mode=%d&id=%s)' %
                     (sys.argv[0], _REMOVE, urllib.quote_plus(id))))

            #if len(stream):
            #    menu.append(('Activate stream', 'XBMC.RunPlugin(%s?mode=%d&stream=%s)' % (sys.argv[0], _PLAY, urllib.quote_plus(stream))))

            addStdMenu(menu)

            if userDef:
                title += ' (user-defined)'

            if SHOWSTREAM:
                if len(stream) > 0:
                    title += ' (stream set)'

            if len(desc):
                title += ' - %s' % desc

            if hidden:
                title = '[COLOR red]' + title + '[/COLOR]'

            if inSelection(weight):
                title = '[I]' + title + '[/I]'

            addDir(title,
                   _EDIT,
                   id,
                   weight=weight,
                   thumbnail=logo,
                   fanart=FANART,
                   isFolder=False,
                   menu=menu,
                   infolabels={},
                   totalItems=totalItems)
Example #27
0
def doDownload(url, dest, title, referer='', agent='', cookie='', quiet=False):
    #unquote parameters
    url = urllib.unquote_plus(url).split('|')[0]
    dest = urllib.unquote_plus(dest)
    title = urllib.unquote_plus(title)
    referer = urllib.unquote_plus(referer)
    agent = urllib.unquote_plus(agent)
    cookie = urllib.unquote_plus(cookie)

    file = dest.rsplit(os.sep, 1)[-1]

    resp, error = getResponse(url, 0, referer, agent, cookie)

    if not resp:
        utils.DialogOK(dest, GETTEXT(30063), error)
        return

    try:
        content = int(resp.headers['Content-Length'])
    except:
        content = 0

    try:
        resumable = 'bytes' in resp.headers['Accept-Ranges'].lower()
    except:
        resumable = False

    utils.log('Download Header')
    utils.log(resp.headers)
    if resumable:
        utils.log('Download is resumable')

    if content < 1:
        utils.DialogOK(file, GETTEXT(30064), GETTEXT(30065))
        return

    size = 1024 * 1024
    mb = content / (1024 * 1024)

    if content < size:
        size = content

    total = 0
    notify = 0
    errors = 0
    count = 0
    resume = 0
    sleep = 0

    #if (not quiet) and xbmcgui.Dialog().yesno(TITLE, file, 'Complete file is %dMB' % mb, 'Continue with download?', 'Confirm',  'Cancel') == 1:
    #    return

    f = sfile.file(dest, type='wb')

    chunk = None
    chunks = []

    while True:
        downloaded = total
        for c in chunks:
            downloaded += len(c)
        percent = min(100 * downloaded / content, 100)
        if percent >= notify:
            if not quiet:
                xbmc.executebuiltin(
                    "XBMC.Notification(%s,%s,%i)" %
                    (title.replace(',', '') + ' - ' + GETTEXT(30066) + ' - ' +
                     str(percent) + '%', dest, 10000))

            utils.log(
                'Download percent : %s %s %dMB downloaded : %sMB File Size : %sMB'
                % (str(percent) + '%', dest, mb, downloaded / 1000000,
                   content / 1000000))

            notify += 25

        chunk = None
        error = False

        try:
            chunk = resp.read(size)
            if not chunk:
                if percent < 99:
                    error = True
                else:
                    while len(chunks) > 0:
                        c = chunks.pop(0)
                        f.write(c)
                        del c

                    f.close()
                    utils.log('%s download complete' % (dest))
                    if not quiet:
                        done(title, dest, True)
                    return

        except Exception, e:
            utils.log(str(e))
            error = True
            sleep = 10
            errno = 0

            if hasattr(e, 'errno'):
                errno = e.errno

            if errno == 10035:  # 'A non-blocking socket operation could not be completed immediately'
                pass

            if errno == 10054:  #'An existing connection was forcibly closed by the remote host'
                errors = 10  #force resume
                sleep = 30

            if errno == 11001:  # 'getaddrinfo failed'
                errors = 10  #force resume
                sleep = 30

        if chunk:
            errors = 0
            chunks.append(chunk)
            if len(chunks) > 5:
                c = chunks.pop(0)
                f.write(c)
                total += len(c)
                del c

        if error:
            errors += 1
            count += 1
            utils.log('%d Error(s) whilst downloading %s' % (count, dest))
            xbmc.sleep(sleep * 1000)

        if (resumable and errors > 0) or errors >= 10:
            if (not resumable and resume >= 50) or resume >= 500:
                #Give up!
                utils.log(
                    '%s download canceled - too many error whilst downloading'
                    % (dest))
                if not quiet:
                    done(title, dest, False)
                return

            resume += 1
            errors = 0
            if resumable:
                chunks = []
                #create new response
                utils.log('Download resumed (%d) %s' % (resume, dest))
                resp, error = getResponse(url, total, referer, agent, cookie)
            else:
                #use existing response
                pass
Example #28
0
#  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 os
import shutil
import utils

CACHE = xbmc.translatePath(os.path.join(utils.PROFILE, 'c'))
print "CAHCE"
print CACHE

try:
    shutil.rmtree(CACHE)
except:
    pass

utils.DialogOK('', utils.GETTEXT(30004))
Example #29
0
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, e:
        utils.log('Error adding plugins : %s' % str(e))