Python xbmc.makeLegalFilename() Examples

The following are 12 code examples of xbmc.makeLegalFilename(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xbmc , or try the search function .
Example #1
Source File: downloadtools.py    From tvalacarta with GNU General Public License v3.0 5 votes vote down vote up
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("tvalacarta.core.downloadtools GetTitleFromFile: titulo="+title )
    #logger.info("tvalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform();
    logger.info("tvalacarta.core.downloadtools GetTitleFromFile: plataforma="+plataforma)
    
    #nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    if plataforma=="xbox":
        nombrefichero = title[:38] + title[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title
    return nombrefichero 
Example #2
Source File: addon_menu.py    From plugin.program.openwizard with GNU General Public License v3.0 5 votes vote down vote up
def install_addon_pack(self, name, url):
        from resources.libs.downloader import Downloader
        from resources.libs import db
        from resources.libs import extract
        from resources.libs.common import logging
        from resources.libs.common import tools

        progress_dialog = xbmcgui.DialogProgress()

        response = tools.open_url(url, check=True)

        if not response:
            logging.log_notify("[COLOR {0}]Addon Installer[/COLOR]".format(CONFIG.COLOR1),
                               '[COLOR {0}]{1}:[/COLOR] [COLOR {2}]Invalid Zip Url![/COLOR]'.format(CONFIG.COLOR1, name, CONFIG.COLOR2))
            return

        if not os.path.exists(CONFIG.PACKAGES):
            os.makedirs(CONFIG.PACKAGES)
        
        progress_dialog.create(CONFIG.ADDONTITLE,
                      '[COLOR {0}][B]Downloading:[/B][/COLOR] [COLOR {1}]{2}[/COLOR]'.format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                      '', '[COLOR {0}]Please Wait[/COLOR]'.format(CONFIG.COLOR2))
        urlsplits = url.split('/')
        lib = xbmc.makeLegalFilename(os.path.join(CONFIG.PACKAGES, urlsplits[-1]))
        try:
            os.remove(lib)
        except:
            pass
        Downloader().download(url, lib)
        title = '[COLOR {0}][B]Installing:[/B][/COLOR] [COLOR {1}]{2}[/COLOR]'.format(CONFIG.COLOR2, CONFIG.COLOR1, name)
        progress_dialog.update(0, title, '', '[COLOR {0}]Please Wait[/COLOR]'.format(CONFIG.COLOR2))
        percent, errors, error = extract.all(lib, CONFIG.ADDONS, title=title)
        installed = db.grab_addons(lib)
        db.addon_database(installed, 1, True)
        progress_dialog.close()
        logging.log_notify("[COLOR {0}]Addon Installer[/COLOR]".format(CONFIG.COLOR1),
                           '[COLOR {0}]{1}: Installed![/COLOR]'.format(CONFIG.COLOR2, name))
        xbmc.executebuiltin('UpdateAddonRepos()')
        xbmc.executebuiltin('UpdateLocalAddons()')
        xbmc.executebuiltin('Container.Refresh()') 
Example #3
Source File: downloadtools.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def getfilefromtitle(url, title):
    # Imprime en el log lo que va a descartar
    logger.info("title=" + title)
    logger.info("url=" + url)
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    from . import scrapertools

    nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
    logger.info("nombrefichero=%s" % nombrefichero)
    if "videobb" in url or "videozer" in url or "putlocker" in url:
        nombrefichero = title + ".flv"
    if "videobam" in url:
        nombrefichero = title + "." + url.rsplit(".", 1)[1][0:3]

    logger.info("nombrefichero=%s" % nombrefichero)

    nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("nombrefichero=%s" % nombrefichero)

    fullpath = filetools.join(config.get_setting("downloadpath"), nombrefichero)
    logger.info("fullpath=%s" % fullpath)

    if config.is_xbmc() and fullpath.startswith("special://"):
        import xbmc
        fullpath = xbmc.translatePath(fullpath)

    return fullpath 
Example #4
Source File: downloadtools.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("titulo=" + title)
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    nombrefichero = title
    return nombrefichero 
Example #5
Source File: downloadtools.py    From pelisalacarta-ce with GNU General Public License v3.0 5 votes vote down vote up
def getfilefromtitle(url, title):
    # Imprime en el log lo que va a descartar
    logger.info("title=" + title)
    logger.info("url=" + url)
    # logger.info("pelisalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    import scrapertools
    if plataforma == "xbox":
        nombrefichero = title[:38] + scrapertools.get_filename_from_url(url)[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
        logger.info("nombrefichero=%s" % nombrefichero)
        if "videobb" in url or "videozer" in url or "putlocker" in url:
            nombrefichero = title + ".flv"
        if "videobam" in url:
            nombrefichero = title + "." + url.rsplit(".", 1)[1][0:3]

        logger.info("nombrefichero=%s" % nombrefichero)

        nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("nombrefichero=%s" % nombrefichero)

    fullpath = os.path.join(config.get_setting("downloadpath"), nombrefichero)
    logger.info("fullpath=%s" % fullpath)

    if config.is_xbmc() and fullpath.startswith("special://"):
        import xbmc
        fullpath = xbmc.translatePath(fullpath)

    return fullpath 
Example #6
Source File: downloadtools.py    From pelisalacarta-ce with GNU General Public License v3.0 5 votes vote down vote up
def GetTitleFromFile(title):
    # Imprime en el log lo que va a descartar
    logger.info("titulo=" + title)
    # logger.info("pelisalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform()
    logger.info("plataforma=" + plataforma)

    # nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    if plataforma == "xbox":
        nombrefichero = title[:38] + title[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title
    return nombrefichero 
Example #7
Source File: downloader.py    From filmkodi with Apache License 2.0 5 votes vote down vote up
def downloadMovie(self, url, path, title, extension):
        if not os.path.exists(path):
            common.log('Path does not exist')
            return None
        if title == '':
            common.log('No title given')
            return None

        file_path = xbmc.makeLegalFilename(os.path.join(path, title + extension))
        file_path = urllib.unquote_plus(file_path)
        # Overwrite existing file?
        if os.path.isfile(file_path):
            self.pDialog = xbmcgui.Dialog()

            if not common.ask('File already exists. Overwrite?\n' + os.path.basename(file_path)):
                title = common.showOSK(urllib.unquote_plus(title), common.translate(30102))
                if not title:
                    return None
                file_path = xbmc.makeLegalFilename(os.path.join(path, title + extension))
                file_path = urllib.unquote_plus(file_path)

        success = self.__download(url, file_path)
        if success:
            return file_path
        else:
            return None 
Example #8
Source File: downloadtools.py    From tvalacarta with GNU General Public License v3.0 4 votes vote down vote up
def getfilefromtitle(url,title,folder=""):
    logger.info("tvalacarta.core.downloadtools getfilefromtitle: title="+title+" url="+url+" folder="+folder )

    #logger.info("tvalacarta.core.downloadtools downloadtitle: title="+urllib.quote_plus( title ))
    plataforma = config.get_system_platform();
    logger.info("tvalacarta.core.downloadtools getfilefromtitle: plataforma="+plataforma)
    
    #nombrefichero = xbmc.makeLegalFilename(title + url[-4:])
    import scrapertools
    if plataforma=="xbox":
        nombrefichero = title[:38] + scrapertools.get_filename_from_url(url)[-4:]
        nombrefichero = limpia_nombre_excepto_1(nombrefichero)
    else:
        nombrefichero = title + scrapertools.get_filename_from_url(url)[-4:]
        logger.info("tvalacarta.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)
        if "videobb" in url or "videozer" in url or "putlocker" in url:
            nombrefichero = title + ".flv"
        if "videobam" in url:
            nombrefichero = title+"."+url.rsplit(".",1)[1][0:3]
        if "dibujos.tv" in url:
            nombrefichero = title + ".mp4"
        if "filenium" in url:
            # Content-Disposition	filename="filenium_El.Gato.con.Botas.TSScreener.Latino.avi"
            import scrapertools
            content_disposition_header = scrapertools.get_header_from_response(url,header_to_get="Content-Disposition")
            logger.info("content_disposition="+content_disposition_header)
            partes=content_disposition_header.split("=")
            if len(partes)<=1:
                raise Exception('filenium', 'no existe')
                
            extension = partes[1][-5:-1]
            nombrefichero = title + extension
        logger.info("tvalacarta.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)

        nombrefichero = limpia_nombre_caracteres_especiales(nombrefichero)

    logger.info("tvalacarta.core.downloadtools getfilefromtitle: nombrefichero=%s" % nombrefichero)

    if folder=="":
        fullpath = os.path.join( config.get_setting("downloadpath") , nombrefichero )
    else:
        fullpath = os.path.join( config.get_setting("downloadpath") , folder , nombrefichero )

    logger.info("tvalacarta.core.downloadtools getfilefromtitle: fullpath=%s" % fullpath)
    
    return fullpath 
Example #9
Source File: downloadtools.py    From tvalacarta with GNU General Public License v3.0 4 votes vote down vote up
def downloadfileGzipped(url,pathfichero):
    logger.info("tvalacarta.core.downloadtools downloadfileGzipped: url="+url)
    nombrefichero = pathfichero
    logger.info("tvalacarta.core.downloadtools downloadfileGzipped: nombrefichero="+nombrefichero)

    import xbmc
    nombrefichero = xbmc.makeLegalFilename(nombrefichero)
    logger.info("tvalacarta.core.downloadtools downloadfileGzipped: nombrefichero="+nombrefichero)
    patron = "(http://[^/]+)/.+"
    matches = re.compile(patron,re.DOTALL).findall(url)
    
    if len(matches):
        logger.info("tvalacarta.core.downloadtools URL principal :"+matches[0])
        url1= matches[0]
    else:
        url1 = url
    
    txheaders =  {'User-Agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)',
                  'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                  'Accept-Language':'es-es,es;q=0.8,en-us;q=0.5,en;q=0.3',
                  'Accept-Encoding':'gzip,deflate',
                  'Accept-Charset':'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
                  'Keep-Alive':'115',
                  'Connection':'keep-alive',
                  'Referer':url1,
                  }
        
    txdata = ""

    # Crea el diálogo de progreso
    import xbmcgui
    progreso = xbmcgui.DialogProgress()
    progreso.create( "addon" , "Descargando..." , url , nombrefichero )

    # Timeout del socket a 60 segundos
    socket.setdefaulttimeout(10)

    h=urllib2.HTTPHandler(debuglevel=0)
    request = urllib2.Request(url, txdata, txheaders)
    #if existSize > 0:
    #    request.add_header('Range', 'bytes=%d-' % (existSize, ))

    opener = urllib2.build_opener(h)
    urllib2.install_opener(opener)
    try:
        connexion = opener.open(request)
    except urllib2.HTTPError,e:
        logger.info("tvalacarta.core.downloadtools downloadfile: error %d (%s) al abrir la url %s" % (e.code,e.msg,url))
        #print e.code
        #print e.msg
        #print e.hdrs
        #print e.fp
        progreso.close()
        # El error 416 es que el rango pedido es mayor que el fichero => es que ya está completo
        if e.code==416:
            return 0
        else:
            return -2 
Example #10
Source File: addon_menu.py    From plugin.program.openwizard with GNU General Public License v3.0 4 votes vote down vote up
def install_skin(self, name, url):
        from resources.libs.downloader import Downloader
        from resources.libs import db
        from resources.libs import extract
        from resources.libs.common import logging
        from resources.libs import skin
        from resources.libs.common import tools

        progress_dialog = xbmcgui.DialogProgress()

        response = tools.open_url(url, check=False)

        if not response:
            logging.log_notify("[COLOR {0}]Addon Installer[/COLOR]".format(CONFIG.COLOR1),
                               '[COLOR {0}]{1}:[/COLOR] [COLOR {2}]Invalid Zip Url![/COLOR]'.format(CONFIG.COLOR1, name, CONFIG.COLOR2))
            return

        if not os.path.exists(CONFIG.PACKAGES):
            os.makedirs(CONFIG.PACKAGES)
        
        progress_dialog.create(CONFIG.ADDONTITLE,
                      '[COLOR {0}][B]Downloading:[/B][/COLOR] [COLOR {1}]{2}[/COLOR]'.format(CONFIG.COLOR2, CONFIG.COLOR1, name),
                      '', '[COLOR {0}]Please Wait[/COLOR]'.format(CONFIG.COLOR2))

        urlsplits = url.split('/')
        lib = xbmc.makeLegalFilename(os.path.join(CONFIG.PACKAGES, urlsplits[-1]))
        try:
            os.remove(lib)
        except:
            pass
        Downloader().download(url, lib)
        title = '[COLOR {0}][B]Installing:[/B][/COLOR] [COLOR {1}]{2}[/COLOR]'.format(CONFIG.COLOR2, CONFIG.COLOR1, name)
        progress_dialog.update(0, title, '', '[COLOR {0}]Please Wait[/COLOR]'.format(CONFIG.COLOR2))
        percent, errors, error = extract.all(lib, CONFIG.HOME, title=title)
        installed = db.grab_addons(lib)
        db.addon_database(installed, 1, True)
        progress_dialog.close()
        logging.log_notify("[COLOR {0}]Addon Installer[/COLOR]".format(CONFIG.COLOR1),
                           '[COLOR {0}]{1}: Installed![/COLOR]'.format(CONFIG.COLOR2, name))
        xbmc.executebuiltin('UpdateAddonRepos()')
        xbmc.executebuiltin('UpdateLocalAddons()')
        for item in installed:
            if item.startswith('skin.') and not item == 'skin.shortcuts':
                if not CONFIG.BUILDNAME == '' and CONFIG.DEFAULTIGNORE == 'true':
                    CONFIG.set_setting('defaultskinignore', 'true')
                skin.switch_to_skin(item, 'Skin Installer')
        xbmc.executebuiltin('Container.Refresh()') 
Example #11
Source File: download_and_play.py    From pelisalacarta-ce with GNU General Public License v3.0 4 votes vote down vote up
def download_file(self):
        logger.info("Direct download")

        headers=[]

        # Se asegura de que el fichero se podrá crear
        logger.info("nombrefichero="+self.file_name)
        self.file_name = xbmc.makeLegalFilename(self.file_name)
        logger.info("nombrefichero="+self.file_name)
        logger.info("url="+self.url)
    
        # Crea el fichero
        existSize = 0
        f = open(self.file_name, 'wb')
        grabado = 0

        # Interpreta las cabeceras en una URL como en XBMC
        if "|" in self.url:
            additional_headers = self.url.split("|")[1]
            if "&" in additional_headers:
                additional_headers = additional_headers.split("&")
            else:
                additional_headers = [ additional_headers ]
    
            for additional_header in additional_headers:
                logger.info("additional_header: "+additional_header)
                name = re.findall( "(.*?)=.*?" , additional_header )[0]
                value = urllib.unquote_plus(re.findall( ".*?=(.*?)$" , additional_header )[0])
                headers.append( [ name,value ] )
    
            self.url = self.url.split("|")[0]
            logger.info("url="+self.url)
    
        # Timeout del socket a 60 segundos
        socket.setdefaulttimeout(60)

        # Crea la petición y añade las cabeceras
        h=urllib2.HTTPHandler(debuglevel=0)
        request = urllib2.Request(self.url)
        for header in headers:
            logger.info("Header="+header[0]+": "+header[1])
            request.add_header(header[0],header[1])

        # Lanza la petición
        opener = urllib2.build_opener(h)
        urllib2.install_opener(opener)
        try:
            connexion = opener.open(request)
        except urllib2.HTTPError,e:
            logger.error("error %d (%s) al abrir la url %s" % (e.code,e.msg,self.url))
            #print e.code
            #print e.msg
            #print e.hdrs
            #print e.fp
            f.close()

            # El error 416 es que el rango pedido es mayor que el fichero => es que ya está completo
            if e.code==416:
                return 0
            else:
                return -2 
Example #12
Source File: downloadtools.py    From pelisalacarta-ce with GNU General Public License v3.0 4 votes vote down vote up
def downloadfileGzipped(url, pathfichero):
    logger.info("url=" + url)
    nombrefichero = pathfichero
    logger.info("nombrefichero=" + nombrefichero)

    import xbmc
    nombrefichero = xbmc.makeLegalFilename(nombrefichero)
    logger.info("nombrefichero=" + nombrefichero)
    patron = "(http://[^/]+)/.+"
    matches = re.compile(patron, re.DOTALL).findall(url)

    if len(matches):
        logger.info("URL principal :" + matches[0])
        url1 = matches[0]
    else:
        url1 = url

    txheaders = {
        'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; '
                      'Media Center PC 5.0; .NET CLR 3.0.04506)',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'es-es,es;q=0.8,en-us;q=0.5,en;q=0.3',
        'Accept-Encoding': 'gzip,deflate',
        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
        'Keep-Alive': '115',
        'Connection': 'keep-alive',
        'Referer': url1,
        }

    txdata = ""

    # Crea el diálogo de progreso
    from platformcode import platformtools
    progreso = platformtools.dialog_progress("addon", "Descargando...", url.split("|")[0], nombrefichero)

    # Timeout del socket a 60 segundos
    socket.setdefaulttimeout(10)

    h = urllib2.HTTPHandler(debuglevel=0)
    request = urllib2.Request(url, txdata, txheaders)
    # if existSize > 0:
    #    request.add_header('Range', 'bytes=%d-' % (existSize, ))

    opener = urllib2.build_opener(h)
    urllib2.install_opener(opener)
    try:
        connexion = opener.open(request)
    except urllib2.HTTPError, e:
        logger.error("error %d (%s) al abrir la url %s" %
                    (e.code, e.msg, url))
        # print e.code
        # print e.msg
        # print e.hdrs
        # print e.fp
        progreso.close()
        # El error 416 es que el rango pedido es mayor que el fichero => es que ya está completo
        if e.code == 416:
            return 0
        else:
            return -2