def test_samba():
    from core import samba
    #print samba.file_exists("00000005.txt","smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
    #print samba.file_exists("00000004.txt","smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
    
    print samba.get_files("smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
    
    handle = samba.get_file_handle_for_reading("00000007.txt","smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
    lines = handle.readlines()
    for line in lines:
        print line
    handle.close()

    samba.remove_file("00000007.txt","smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
Exemplo n.º 2
0
def torrent(item):
    comprimidos = ["rar","zip"]
    if not item.url:
      folder=os.path.join(config.get_setting("downloadpath"),"Torrent") 
      if not os.path.exists(folder):
        os.mkdir(folder)
    else:
      folder=item.url
    logger.info("[descargas.py] torrent")
    itemlist=[]
    if usingsamba(folder):
        ficheros = samba.get_files(folder)
    else:
        ficheros = os.listdir(filesystem.EncodePath(folder))
    for fichero in ficheros:
      fichero = filesystem.DecodePath(fichero)
      url = os.path.join(folder, fichero)
      if not os.path.isdir(filesystem.EncodePath(url)):
        if url.split(".")[len(url.split("."))-1] in comprimidos:
          itemlist.append( Item(channel="descargas", action="play", title=fichero, context="Eliminar Archivo,borrar_torrent|Extraer,extract", url=url, server="local", folder=False))
        else:
          itemlist.append( Item(channel="descargas", action="play", title=fichero, context="Eliminar Archivo,borrar_torrent", url=url, server="local", folder=False))
      else:
        itemlist.append( Item(channel="descargas", action="torrent", title=fichero,context="Eliminar Carpeta,borrar_torrent",url=url, folder=True))
    return itemlist
def errores(item):
    logger.info("[descargas.py] errores")
    itemlist=[]

    # Crea un listado con las entradas de favoritos
    if usingsamba:
        ficheros = samba.get_files(ERROR_PATH)
    else:
        ficheros = os.listdir(ERROR_PATH)

    # Ordena el listado por orden de incorporaci�n
    ficheros.sort()
    
    # Crea un listado con las entradas de la lista de descargas
    for fichero in ficheros:
        logger.info("[descargas.py] fichero="+fichero)
        try:
            # Lee el bookmark
            canal,titulo,thumbnail,plot,server,url,fulltitle = favoritos.readbookmark(fichero,ERROR_PATH)
            if canal=="":
                canal="descargas"

            # Crea la entrada
            # En la categor�a va el nombre del fichero para poder borrarlo
            itemlist.append( Item( channel=canal , action="play" , url=url , server=server, title=titulo, fulltitle=fulltitle, thumbnail=thumbnail, plot=plot, fanart=thumbnail, category="errores", extra=os.path.join( ERROR_PATH, fichero ), folder=False ))

        except:
            pass
            logger.info("[descargas.py] error al leer bookmark")
            for line in sys.exc_info():
                logger.error( "%s" % line )

    return itemlist
Exemplo n.º 4
0
def downloadall(item):
    logger.info("[descargas.py] downloadall")

    if usingsamba(DOWNLOAD_LIST_PATH):
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)
        
    ficheros.sort()
    for fichero in ficheros:
        if fichero.endswith('.txt'):
            try:
                item = LeerDescarga(fichero,DOWNLOAD_LIST_PATH)
                dev = download(item)
                if dev == -1:
                    logger.info("[descargas.py] Descarga cancelada")
                    guitools.Dialog_OK("pelisalacarta", "Descargas canceladas")
                    break
                elif dev == -2:
                    logger.info("[descargas.py] ERROR EN DESCARGA DE "+fichero)
                    BorrarDescarga(item, DOWNLOAD_LIST_PATH)
                    GuardarDescarga(item, ERROR_PATH)
                else:
                    BorrarDescarga(item, DOWNLOAD_LIST_PATH)
            except:
                logger.info("[descargas.py] ERROR EN DESCARGA DE "+fichero)
                import traceback
                logger.error(traceback.format_exc())
                GuardarDescarga(item,ERROR_PATH)
                BorrarDescarga(item, DOWNLOAD_LIST_PATH)
    
    return ""  
Exemplo n.º 5
0
def mainlist(item):
    logger.info("[descargas.py] mainlist")
    itemlist = []

    itemlist.append(
        Item(channel="descargas",
             action="pendientes",
             title="Descargas pendientes"))
    itemlist.append(
        Item(channel="descargas",
             action="errores",
             title="Descargas con error"))
    if usingsamba(DOWNLOAD_PATH):
        ficheros = samba.get_files(DOWNLOAD_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_PATH)
    for fichero in ficheros:
        url = os.path.join(DOWNLOAD_PATH, fichero)
        if not os.path.isdir(url) and not fichero.endswith(
                ".nfo") and not fichero.endswith(".tbn"):
            itemlist.append(
                Item(channel="descargas",
                     action="play",
                     title=fichero,
                     url=url,
                     server="local",
                     folder=False))

    return itemlist
Exemplo n.º 6
0
def downloadall(item):
    logger.info("[descargas.py] downloadall")

    if usingsamba(DOWNLOAD_LIST_PATH):
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)

    ficheros.sort()
    for fichero in ficheros:
        if fichero.endswith('.txt'):
            try:
                item = LeerDescarga(fichero, DOWNLOAD_LIST_PATH)
                dev = download(item)
                if dev == -1:
                    logger.info("[descargas.py] Descarga cancelada")
                    guitools.Dialog_OK("pelisalacarta", "Descargas canceladas")
                    break
                elif dev == -2:
                    logger.info("[descargas.py] ERROR EN DESCARGA DE " +
                                fichero)
                    BorrarDescarga(item, DOWNLOAD_LIST_PATH)
                    GuardarDescarga(item, ERROR_PATH)
                else:
                    BorrarDescarga(item, DOWNLOAD_LIST_PATH)
            except:
                logger.info("[descargas.py] ERROR EN DESCARGA DE " + fichero)
                import traceback
                logger.error(traceback.format_exc())
                GuardarDescarga(item, ERROR_PATH)
                BorrarDescarga(item, DOWNLOAD_LIST_PATH)

    return ""
def errores(item):
    logger.info("[descargas.py] errores")
    itemlist=[]

    # Crea un listado con las entradas de favoritos
    if usingsamba:
        ficheros = samba.get_files(ERROR_PATH)
    else:
        ficheros = os.listdir(ERROR_PATH)

    # Ordena el listado por orden de incorporaci�n
    ficheros.sort()
    
    # Crea un listado con las entradas de la lista de descargas
    for fichero in ficheros:
        logger.info("[descargas.py] fichero="+fichero)
        try:
            # Lee el bookmark
            canal,titulo,thumbnail,plot,server,url,fulltitle = favoritos.readbookmark(fichero,ERROR_PATH)
            if canal=="":
                canal="descargas"

            # Crea la entrada
            # En la categor�a va el nombre del fichero para poder borrarlo
            itemlist.append( Item( channel=canal , action="play" , url=url , server=server, title=titulo, fulltitle=fulltitle, thumbnail=thumbnail, plot=plot, fanart=thumbnail, category="errores", extra=os.path.join( ERROR_PATH, fichero ), folder=False ))

        except:
            pass
            logger.info("[descargas.py] error al leer bookmark")
            for line in sys.exc_info():
                logger.error( "%s" % line )

    return itemlist
Exemplo n.º 8
0
def mainlist(item):
    logger.info("[descargas.py] mainlist")
    itemlist=[]
    
    itemlist.append( Item( channel="descargas", action="pendientes", title="Descargas pendientes"))
    itemlist.append( Item( channel="descargas", action="errores", title="Descargas con error"))
    itemlist.append( Item( channel="descargas", action="torrent", title="Descargas Torrent"))

    if usingsamba(DOWNLOAD_PATH):
        ficheros = samba.get_files(DOWNLOAD_PATH)
    else:
        ficheros = os.listdir(filesystem.EncodePath(DOWNLOAD_PATH))
    for fichero in ficheros:
      fichero = filesystem.DecodePath(fichero)
      url = os.path.join(DOWNLOAD_PATH, fichero)
      if not os.path.isdir(url) and not fichero.endswith(".nfo") and not fichero.endswith(".tbn"):
        fileName, fileExtension = os.path.splitext(url)
        if os.path.exists(fileName + ".nfo"):
          Archivo = open(fileName + ".nfo","rb")
          lines = Archivo.read()
          Archivo.close();
          print lines
          title = scrapertools.find_single_match(lines,'<title>\((.*?)\)</title>')
          thumbnail = scrapertools.find_single_match(lines,'<thumb>(.*?)</thumb>')
          plot = scrapertools.find_single_match(lines,'<plot>(.*?)</plot>')
          itemlist.append( Item(channel="descargas", action="play", title=title, url=url, thumbnail=thumbnail, plot=plot, server="local", folder=False))
        else:
          itemlist.append( Item(channel="descargas", action="play", title=fichero, url=url, server="local", folder=False))

    return itemlist
Exemplo n.º 9
0
def test_samba():
    from core import samba
    #print samba.file_exists("00000005.txt","smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
    #print samba.file_exists("00000004.txt","smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")

    print samba.get_files("smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")

    handle = samba.get_file_handle_for_reading(
        "00000007.txt", "smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
    lines = handle.readlines()
    for line in lines:
        print line
    handle.close()

    samba.remove_file("00000007.txt",
                      "smb://MEDIASERVER/DESCARGAS/XBMC/favoritos")
Exemplo n.º 10
0
def get_all_videos(item):
    logger.info("tvalacarta.core.favoritos get_all_videos")
    itemlist=[]

    # Crea un listado con las entradas de favoritos
    if usingsamba(BOOKMARK_PATH):
        ficheros = samba.get_files(BOOKMARK_PATH)
    else:
        ficheros = os.listdir(BOOKMARK_PATH)
    
    # Ordena el listado por nombre de fichero (orden de incorporaci?)
    ficheros.sort()
    
    # Rellena el listado
    for fichero in ficheros:

        try:
            # Lee el bookmark
            canal,titulo,thumbnail,plot,server,url,fulltitle = readbookmark(fichero)
            if canal=="":
                canal="favoritos"

            # Crea la entrada
            # En extra va el nombre del fichero para poder borrarlo
            ## <-- A?do fulltitle con el titulo de la peli
            if server=="":
                itemlist.append( Item( channel=canal , action="play" , url=url , server=server, title=fulltitle, thumbnail=thumbnail, plot=plot, fanart=thumbnail, extra=os.path.join( BOOKMARK_PATH, fichero ), fulltitle=fulltitle, folder=False ))
            else:
                itemlist.append( Item( channel=canal , action="play" , url=url , server=server, title=fulltitle, thumbnail=thumbnail, plot=plot, fanart=thumbnail, extra=os.path.join( BOOKMARK_PATH, fichero ), fulltitle=fulltitle, folder=False ))
        except:
            for line in sys.exc_info():
                logger.error( "%s" % line )
    
    return itemlist
Exemplo n.º 11
0
def pendientes(item):
    logger.info("[descargas.py] pendientes")
    itemlist = []

    # Crea un listado con las entradas de favoritos
    if usingsamba:
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)

    # Ordena el listado por orden de incorporación
    ficheros.sort()

    # Crea un listado con las entradas de la lista de descargas
    for fichero in ficheros:
        logger.info("fichero=" + fichero)
        try:
            # Lee el bookmark
            canal, titulo, thumbnail, plot, server, url, fulltitle = favoritos.readbookmark(
                fichero, DOWNLOAD_LIST_PATH)
            if canal == "":
                canal = "descargas"

            logger.info("canal=" + canal + ", titulo=" + titulo +
                        ", thumbnail=" + thumbnail + ", server=" + server +
                        ", url=" + url + ", fulltitle=" + fulltitle +
                        ", plot=" + plot)

            # Crea la entrada
            # En la categoría va el nombre del fichero para poder borrarlo
            itemlist.append(
                Item(channel=canal,
                     action="play",
                     url=url,
                     server=server,
                     title=titulo,
                     fulltitle=fulltitle,
                     thumbnail=thumbnail,
                     plot=plot,
                     fanart=thumbnail,
                     extra=os.path.join(DOWNLOAD_LIST_PATH, fichero),
                     folder=False))

        except:
            pass
            logger.info("[descargas.py] error al leer bookmark")
            for line in sys.exc_info():
                logger.error("%s" % line)

    itemlist.append(
        Item(channel=CHANNELNAME,
             action="downloadall",
             title="(Empezar la descarga de la lista)",
             thumbnail=os.path.join(IMAGES_PATH,
                                    "Crystal_Clear_action_db_update.png"),
             folder=False))

    return itemlist
Exemplo n.º 12
0
def get_all_videos(item):
    logger.info("tvalacarta.core.favoritos get_all_videos")
    itemlist = []

    # Crea un listado con las entradas de favoritos
    if usingsamba(BOOKMARK_PATH):
        ficheros = samba.get_files(BOOKMARK_PATH)
    else:
        ficheros = os.listdir(BOOKMARK_PATH)

    # Ordena el listado por nombre de fichero (orden de incorporaci?)
    ficheros.sort()

    # Rellena el listado
    for fichero in ficheros:

        try:
            # Lee el bookmark
            canal, titulo, thumbnail, plot, server, url, fulltitle = readbookmark(
                fichero)
            if canal == "":
                canal = "favoritos"

            # Crea la entrada
            # En extra va el nombre del fichero para poder borrarlo
            ## <-- A?do fulltitle con el titulo de la peli
            if server == "":
                itemlist.append(
                    Item(channel=canal,
                         action="play",
                         url=url,
                         server=server,
                         title=fulltitle,
                         thumbnail=thumbnail,
                         plot=plot,
                         fanart=thumbnail,
                         extra=os.path.join(BOOKMARK_PATH, fichero),
                         fulltitle=fulltitle,
                         folder=False))
            else:
                itemlist.append(
                    Item(channel=canal,
                         action="play",
                         url=url,
                         server=server,
                         title=fulltitle,
                         thumbnail=thumbnail,
                         plot=plot,
                         fanart=thumbnail,
                         extra=os.path.join(BOOKMARK_PATH, fichero),
                         fulltitle=fulltitle,
                         folder=False))
        except:
            for line in sys.exc_info():
                logger.error("%s" % line)

    return itemlist
Exemplo n.º 13
0
def savebookmark(canal=CHANNELNAME,titulo="",url="",thumbnail="",server="",plot="",fulltitle="",savepath=BOOKMARK_PATH):
    logger.info("tvalacarta.core.favoritos savebookmark(path="+savepath+")")

    # Crea el directorio de favoritos si no existe
    if not usingsamba(savepath):
        try:
            os.mkdir(savepath)
        except:
            pass

    # Lee todos los ficheros
    if usingsamba(savepath):
        ficheros = samba.get_files(savepath)
    else:
        ficheros = os.listdir(savepath)
    ficheros.sort()
    
    # Averigua el ?ltimo n?mero
    if len(ficheros)>0:
        # XRJ: Linea problem?ica, sustituida por el bucle siguiente
        #filenumber = int( ficheros[len(ficheros)-1][0:-4] )+1
        filenumber = 1
        for fichero in ficheros:
            logger.info("tvalacarta.core.favoritos fichero="+fichero)
            try:
                tmpfilenumber = int( fichero[0:8] )+1
                if tmpfilenumber > filenumber:
                    filenumber = tmpfilenumber
            except:
                pass
    else:
        filenumber=1

    # Genera el contenido
    filecontent = ""
    filecontent = filecontent + urllib.quote_plus(downloadtools.limpia_nombre_excepto_1(titulo))+'\n'
    filecontent = filecontent + urllib.quote_plus(url)+'\n'
    filecontent = filecontent + urllib.quote_plus(thumbnail)+'\n'
    filecontent = filecontent + urllib.quote_plus(server)+'\n'
    filecontent = filecontent + urllib.quote_plus(downloadtools.limpia_nombre_excepto_1(plot))+'\n'
    filecontent = filecontent + urllib.quote_plus(fulltitle)+'\n'
    filecontent = filecontent + urllib.quote_plus(canal)+'\n'

    # Genera el nombre de fichero
    from core import scrapertools
    filename = '%08d-%s.txt' % (filenumber,scrapertools.slugify(fulltitle))
    logger.info("tvalacarta.core.favoritos savebookmark filename="+filename)

    # Graba el fichero
    if not usingsamba(savepath):
        fullfilename = os.path.join(savepath,filename)
        bookmarkfile = open(fullfilename,"w")
        bookmarkfile.write(filecontent)
        bookmarkfile.flush();
        bookmarkfile.close()
    else:
        samba.write_file(filename, filecontent, savepath)
Exemplo n.º 14
0
def mainlist(item):
    logger.info("[descargas.py] mainlist")
    itemlist = []

    itemlist.append(
        Item(channel="descargas",
             action="pendientes",
             title="Descargas pendientes"))
    itemlist.append(
        Item(channel="descargas",
             action="errores",
             title="Descargas con error"))
    itemlist.append(
        Item(channel="descargas", action="torrent", title="Descargas Torrent"))

    if usingsamba(DOWNLOAD_PATH):
        ficheros = samba.get_files(DOWNLOAD_PATH)
    else:
        ficheros = os.listdir(filesystem.EncodePath(DOWNLOAD_PATH))
    for fichero in ficheros:
        fichero = filesystem.DecodePath(fichero)
        url = os.path.join(DOWNLOAD_PATH, fichero)
        if not os.path.isdir(url) and not fichero.endswith(
                ".nfo") and not fichero.endswith(".tbn"):
            fileName, fileExtension = os.path.splitext(url)
            if os.path.exists(fileName + ".nfo"):
                Archivo = open(fileName + ".nfo", "rb")
                lines = Archivo.read()
                Archivo.close()
                print lines
                title = scrapertools.find_single_match(
                    lines, '<title>\((.*?)\)</title>')
                thumbnail = scrapertools.find_single_match(
                    lines, '<thumb>(.*?)</thumb>')
                plot = scrapertools.find_single_match(lines,
                                                      '<plot>(.*?)</plot>')
                itemlist.append(
                    Item(channel="descargas",
                         action="play",
                         title=title,
                         url=url,
                         thumbnail=thumbnail,
                         plot=plot,
                         server="local",
                         folder=False))
            else:
                itemlist.append(
                    Item(channel="descargas",
                         action="play",
                         title=fichero,
                         context="Eliminar Archivo,BorrarDescarga",
                         url=url,
                         server="local",
                         folder=False))

    return itemlist
Exemplo n.º 15
0
def errores(item):
    logger.info("[descargas.py] errores")
    itemlist=[]
    if usingsamba(ERROR_PATH):
        ficheros = samba.get_files(ERROR_PATH)
    else:
        ficheros = os.listdir(ERROR_PATH)
    ficheros.sort()
    for fichero in ficheros:
      item = LeerDescarga(fichero,ERROR_PATH)
      item.file= os.path.join(ERROR_PATH, fichero)
      itemlist.append(item)
    return itemlist
Exemplo n.º 16
0
def errores(item):
    logger.info("[descargas.py] errores")
    itemlist = []
    if usingsamba(ERROR_PATH):
        ficheros = samba.get_files(ERROR_PATH)
    else:
        ficheros = os.listdir(ERROR_PATH)
    ficheros.sort()
    for fichero in ficheros:
        item = LeerDescarga(fichero, ERROR_PATH)
        item.extra = extra = os.path.join(ERROR_PATH, fichero)
        itemlist.append(item)
    return itemlist
Exemplo n.º 17
0
def pendientes(item):
    logger.info("[descargas.py] pendientes")
    itemlist=[]
    if usingsamba(DOWNLOAD_LIST_PATH):
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)
    ficheros.sort()
    for fichero in ficheros:
      item = LeerDescarga(fichero,DOWNLOAD_LIST_PATH)
      itemlist.append(item)
      
    itemlist.append( Item( channel=CHANNELNAME , action="downloadall" , title="(Empezar la descarga de la lista)", thumbnail=os.path.join(IMAGES_PATH, "Crystal_Clear_action_db_update.png") , folder=False ))
    return itemlist
Exemplo n.º 18
0
def GuardarDescarga(item, Ruta=DOWNLOAD_LIST_PATH):
    logger.info("[descargas.py] GuardarDescarga")
    if usingsamba(Ruta):
        ficheros = samba.get_files(Ruta)
    else:
        ficheros = os.listdir(Ruta)
    ficheros.sort()

    # Averigua el último número
    if len(ficheros) > 0:
        # XRJ: Linea problemática, sustituida por el bucle siguiente
        #filenumber = int( ficheros[len(ficheros)-1][0:-4] )+1
        filenumber = 1
        for fichero in ficheros:
            logger.info("[favoritos.py] fichero=" + fichero)
            try:
                tmpfilenumber = int(fichero[0:8]) + 1
                if tmpfilenumber > filenumber:
                    filenumber = tmpfilenumber
            except:
                pass
    else:
        filenumber = 1

    # Genera el nombre de fichero
    from core import scrapertools
    filename = '%08d-%s.txt' % (filenumber, scrapertools.slugify(item.title))
    fullfilename = os.path.join(Ruta, filename)
    logger.info("[descargas.py] GuardarDescarga filename=" + fullfilename)

    # Genera el contenido
    if Ruta == DOWNLOAD_LIST_PATH: item.category = "pendientes"
    if Ruta == ERROR_PATH: item.category = "errores"
    item.channel = "descargas"
    item.extra = fullfilename
    item.folder = False

    filecontent = item.serialize()

    # Graba el fichero
    if not usingsamba(Ruta):
        bookmarkfile = open(fullfilename.decode("utf-8"), "w")
        bookmarkfile.write(filecontent)
        bookmarkfile.flush()
        bookmarkfile.close()
    else:
        samba.write_file(filename, filecontent, Ruta)
Exemplo n.º 19
0
def torrent(item):
    comprimidos = ["rar", "zip"]
    if not item.url:
        folder = os.path.join(config.get_setting("downloadpath"), "Torrent")
        if not os.path.exists(folder):
            os.mkdir(folder)
    else:
        folder = item.url
    logger.info("[descargas.py] torrent")
    itemlist = []
    if usingsamba(folder):
        ficheros = samba.get_files(folder)
    else:
        ficheros = os.listdir(filesystem.EncodePath(folder))
    for fichero in ficheros:
        fichero = filesystem.DecodePath(fichero)
        url = os.path.join(folder, fichero)
        if not os.path.isdir(filesystem.EncodePath(url)):
            if url.split(".")[len(url.split(".")) - 1] in comprimidos:
                itemlist.append(
                    Item(channel="descargas",
                         action="play",
                         title=fichero,
                         context=
                         "Eliminar Archivo,borrar_torrent|Extraer,extract",
                         url=url,
                         server="local",
                         folder=False))
            else:
                itemlist.append(
                    Item(channel="descargas",
                         action="play",
                         title=fichero,
                         context="Eliminar Archivo,borrar_torrent",
                         url=url,
                         server="local",
                         folder=False))
        else:
            itemlist.append(
                Item(channel="descargas",
                     action="torrent",
                     title=fichero,
                     context="Eliminar Carpeta,borrar_torrent",
                     url=url,
                     folder=True))
    return itemlist
Exemplo n.º 20
0
def GuardarDescarga(item, Ruta=DOWNLOAD_LIST_PATH):
    logger.info("[descargas.py] GuardarDescarga")
    if usingsamba(Ruta):
        ficheros = samba.get_files(Ruta)
    else:
        ficheros = os.listdir(Ruta)
    ficheros.sort()
    
    # Averigua el último número
    if len(ficheros)>0:
        # XRJ: Linea problemática, sustituida por el bucle siguiente
        #filenumber = int( ficheros[len(ficheros)-1][0:-4] )+1
        filenumber = 1
        for fichero in ficheros:
            logger.info("[favoritos.py] fichero="+fichero)
            try:
                tmpfilenumber = int( fichero[0:8] )+1
                if tmpfilenumber > filenumber:
                    filenumber = tmpfilenumber
            except:
                pass
    else:
        filenumber=1

    # Genera el nombre de fichero
    from core import scrapertools
    filename = '%08d-%s.txt' % (filenumber,scrapertools.slugify(item.title))
    fullfilename = os.path.join(Ruta,filename)
    logger.info("[descargas.py] GuardarDescarga filename="+fullfilename)
    
    # Genera el contenido
    if Ruta==DOWNLOAD_LIST_PATH: item.category="pendientes"
    if Ruta==ERROR_PATH: item.category="errores"
    item.channel="descargas"
    item.file=fullfilename
    item.folder=False
    filecontent = item.serialize()

    # Graba el fichero
    if not usingsamba(Ruta):
        bookmarkfile = open(fullfilename.decode("utf-8"),"w")
        bookmarkfile.write(filecontent)
        bookmarkfile.flush();
        bookmarkfile.close()
    else:
        samba.write_file(filename, filecontent, Ruta)
Exemplo n.º 21
0
def pendientes(item):
    logger.info("[descargas.py] pendientes")
    itemlist = []
    if usingsamba(DOWNLOAD_LIST_PATH):
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)
    ficheros.sort()
    for fichero in ficheros:
        item = LeerDescarga(fichero, DOWNLOAD_LIST_PATH)
        itemlist.append(item)

    itemlist.append(
        Item(channel=CHANNELNAME,
             action="downloadall",
             title="(Empezar la descarga de la lista)",
             thumbnail="%s/thumb_nofolder.png",
             folder=False))
    return itemlist
Exemplo n.º 22
0
def descargas_pendientes(item):
    logger.info("core.descargas descargas_pendientes")
    itemlist=[]

    # Crea un listado con las entradas de favoritos
    if usingsamba:
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)

    # Ordena el listado por orden de incorporación
    ficheros.sort()
    
    # Crea un listado con las entradas de la lista de descargas
    for fichero in ficheros:
        logger.info("fichero="+fichero)
        try:
            # Lee el bookmark
            canal,titulo,thumbnail,plot,server,url,fulltitle = favoritos.readbookmark(fichero,DOWNLOAD_LIST_PATH)
            if canal=="":
                canal="descargas"

            logger.info("canal="+canal+", titulo="+titulo+", thumbnail="+thumbnail+", server="+server+", url="+url+", fulltitle="+fulltitle+", plot="+plot)

            # Crea la entrada
            # En la categoría va el nombre del fichero para poder borrarlo
            itemlist.append( Item( channel=canal , action="play" , url=url , server=server, title=titulo, fulltitle=fulltitle, thumbnail=thumbnail, plot=plot, fanart=thumbnail, extra=os.path.join( DOWNLOAD_LIST_PATH, fichero ), folder=False ))

        except:
            pass
            logger.info("core.descargas error al leer bookmark")
            for line in sys.exc_info():
                logger.error( "%s" % line )

    itemlist.append( Item( channel=CHANNELNAME , action="downloadall" , title="(Empezar la descarga de la lista)", thumbnail=os.path.join(IMAGES_PATH, "Crystal_Clear_action_db_update.png") , folder=False ))

    return itemlist
def downloadall(item):
    logger.info("[descargas.py] downloadall")

    # Lee la lista de ficheros
    if usingsamba:
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)

    logger.info("[descargas.py] numero de ficheros=%d" % len(ficheros))

    # La ordena
    ficheros.sort()
    
    # Crea un listado con las entradas de favoritos
    for fichero in ficheros:
        # El primer video de la lista
        logger.info("[descargas.py] fichero="+fichero)

        if fichero!="error" and fichero!=".DS_Store":
            # Descarga el v�deo
            try:
                # Lee el bookmark
                canal,titulo,thumbnail,plot,server,url,fulltitle = favoritos.readbookmark(fichero,DOWNLOAD_LIST_PATH)
                logger.info("[descargas.py] url="+url)

                # Averigua la URL del v�deo
                video_urls,puedes,motivo = servertools.resolve_video_urls_for_playing(server,url,"",False)

                # La �ltima es la de mayor calidad, lo mejor para la descarga
                mediaurl = video_urls[ len(video_urls)-1 ][1]
                logger.info("[descargas.py] mediaurl="+mediaurl)

                # Genera el NFO
                nfofilepath = downloadtools.getfilefromtitle("sample.nfo",fulltitle)
                outfile = open(nfofilepath,"w")
                outfile.write("<movie>\n")
                outfile.write("<title>("+fulltitle+")</title>\n")
                outfile.write("<originaltitle></originaltitle>\n")
                outfile.write("<rating>0.000000</rating>\n")
                outfile.write("<year>2009</year>\n")
                outfile.write("<top250>0</top250>\n")
                outfile.write("<votes>0</votes>\n")
                outfile.write("<outline></outline>\n")
                outfile.write("<plot>"+plot+"</plot>\n")
                outfile.write("<tagline></tagline>\n")
                outfile.write("<runtime></runtime>\n")
                outfile.write("<thumb></thumb>\n")
                outfile.write("<mpaa>Not available</mpaa>\n")
                outfile.write("<playcount>0</playcount>\n")
                outfile.write("<watched>false</watched>\n")
                outfile.write("<id>tt0432337</id>\n")
                outfile.write("<filenameandpath></filenameandpath>\n")
                outfile.write("<trailer></trailer>\n")
                outfile.write("<genre></genre>\n")
                outfile.write("<credits></credits>\n")
                outfile.write("<director></director>\n")
                outfile.write("<actor>\n")
                outfile.write("<name></name>\n")
                outfile.write("<role></role>\n")
                outfile.write("</actor>\n")
                outfile.write("</movie>")
                outfile.flush()
                outfile.close()
                logger.info("[descargas.py] Creado fichero NFO")
                
                # Descarga el thumbnail
                if thumbnail != "":
                   logger.info("[descargas.py] thumbnail="+thumbnail)
                   thumbnailfile = downloadtools.getfilefromtitle(thumbnail,fulltitle)
                   thumbnailfile = thumbnailfile[:-4] + ".tbn"
                   logger.info("[descargas.py] thumbnailfile="+thumbnailfile)
                   try:
                       downloadtools.downloadfile(thumbnail,thumbnailfile)
                       logger.info("[descargas.py] Thumbnail descargado")
                   except:
                       logger.info("[descargas.py] error al descargar thumbnail")
                       for line in sys.exc_info():
                           logger.error( "%s" % line )
                
                # Descarga el video
                #dev = downloadtools.downloadtitle(mediaurl,fulltitle)
                dev = downloadtools.downloadbest(video_urls,fulltitle)
                if dev == -1:
                    # El usuario ha cancelado la descarga
                    logger.info("[descargas.py] Descarga cancelada")
                    return
                elif dev == -2:
                    # Error en la descarga, lo mueve a ERROR y continua con el siguiente
                    logger.info("[descargas.py] ERROR EN DESCARGA DE "+fichero)
                    if not usingsamba:
                        origen = os.path.join( DOWNLOAD_LIST_PATH , fichero )
                        destino = os.path.join( ERROR_PATH , fichero )
                        import shutil
                        shutil.move( origen , destino )
                    else:
                        favoritos.savebookmark(canal,titulo, url, thumbnail, server, plot, fulltitle, ERROR_PATH)
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                else:
                    logger.info("[descargas.py] Video descargado")
                    # Borra el bookmark e itera para obtener el siguiente video
                    filepath = os.path.join( DOWNLOAD_LIST_PATH , fichero )
                    if usingsamba:
                        os.remove(filepath)
                    else:
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                    logger.info("[descargas.py] "+fichero+" borrado")
            except:
                logger.info("[descargas.py] ERROR EN DESCARGA DE "+fichero)
                import sys
                for line in sys.exc_info():
                    logger.error( "%s" % line )
                if not usingsamba:
                    origen = os.path.join( DOWNLOAD_LIST_PATH , fichero )
                    destino = os.path.join( ERROR_PATH , fichero )
                    import shutil
                    shutil.move( origen , destino )
                else:
                    favoritos.savebookmark(canal,titulo, url, thumbnail, server, plot, fulltitle,ERROR_PATH)
                    favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
Exemplo n.º 24
0
def downloadall(item):
    logger.info("[descargas.py] downloadall")

    if usingsamba(DOWNLOAD_LIST_PATH):
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)
    ficheros.sort()

    for fichero in ficheros:
        if fichero.endswith('.txt'):
            try:
                item = LeerDescarga(fichero, DOWNLOAD_LIST_PATH)
                video_urls, puedes, motivo = servertools.resolve_video_urls_for_playing(
                    item.server, item.url, "", False)
                # La última es la de mayor calidad, lo mejor para la descarga
                mediaurl = video_urls[len(video_urls) - 1][1]

                # Genera el NFO
                nfofilepath = downloadtools.getfilefromtitle(
                    "sample.nfo", item.title)
                outfile = open(nfofilepath, "w")
                outfile.write("<movie>\n")
                outfile.write("<title>(" + item.title + ")</title>\n")
                outfile.write("<originaltitle></originaltitle>\n")
                outfile.write("<rating>0.000000</rating>\n")
                outfile.write("<year>2009</year>\n")
                outfile.write("<top250>0</top250>\n")
                outfile.write("<votes>0</votes>\n")
                outfile.write("<outline></outline>\n")
                outfile.write("<plot>" + item.plot + "</plot>\n")
                outfile.write("<tagline></tagline>\n")
                outfile.write("<runtime></runtime>\n")
                outfile.write("<thumb>" + item.thumbnail + "</thumb>\n")
                outfile.write("<mpaa>Not available</mpaa>\n")
                outfile.write("<playcount>0</playcount>\n")
                outfile.write("<watched>false</watched>\n")
                outfile.write("<id>tt0432337</id>\n")
                outfile.write("<filenameandpath></filenameandpath>\n")
                outfile.write("<trailer></trailer>\n")
                outfile.write("<genre></genre>\n")
                outfile.write("<credits></credits>\n")
                outfile.write("<director></director>\n")
                outfile.write("<actor>\n")
                outfile.write("<name></name>\n")
                outfile.write("<role></role>\n")
                outfile.write("</actor>\n")
                outfile.write("</movie>")
                outfile.flush()
                outfile.close()

                # Descarga el thumbnail
                if item.thumbnail != "":
                    thumbnailfile = downloadtools.getfilefromtitle(
                        item.thumbnail, item.title)
                    thumbnailfile = thumbnailfile[:-4] + ".tbn"
                    try:
                        downloadtools.downloadfile(item.thumbnail,
                                                   thumbnailfile)
                    except:
                        logger.info(
                            "[descargas.py] error al descargar thumbnail")
                        for line in sys.exc_info():
                            logger.error("%s" % line)

                dev = downloadtools.downloadbest(video_urls, item.title)
                if dev == -1:
                    logger.info("[descargas.py] Descarga cancelada")
                    break
                elif dev == -2:
                    logger.info("[descargas.py] ERROR EN DESCARGA DE " +
                                fichero)
                    BorrarDescarga(item, DOWNLOAD_LIST_PATH)
                    GuardarDescarga(item, ERROR_PATH)
                else:
                    BorrarDescarga(item, DOWNLOAD_LIST_PATH)
            except:
                logger.info("[descargas.py] ERROR EN DESCARGA DE " + fichero)
                import sys
                for line in sys.exc_info():
                    logger.error("%s" % line)
                    GuardarDescarga(item, ERROR_PATH)
                    BorrarDescarga(item, DOWNLOAD_LIST_PATH)

    return ""
Exemplo n.º 25
0
def savebookmark(canal=CHANNELNAME,
                 titulo="",
                 url="",
                 thumbnail="",
                 server="",
                 plot="",
                 fulltitle="",
                 savepath=BOOKMARK_PATH):
    logger.info("tvalacarta.core.favoritos savebookmark(path=" + savepath +
                ")")

    # Crea el directorio de favoritos si no existe
    if not usingsamba(savepath):
        try:
            os.mkdir(savepath)
        except:
            pass

    # Lee todos los ficheros
    if usingsamba(savepath):
        ficheros = samba.get_files(savepath)
    else:
        ficheros = os.listdir(savepath)
    ficheros.sort()

    # Averigua el ?ltimo n?mero
    if len(ficheros) > 0:
        # XRJ: Linea problem?ica, sustituida por el bucle siguiente
        #filenumber = int( ficheros[len(ficheros)-1][0:-4] )+1
        filenumber = 1
        for fichero in ficheros:
            logger.info("tvalacarta.core.favoritos fichero=" + fichero)
            try:
                tmpfilenumber = int(fichero[0:8]) + 1
                if tmpfilenumber > filenumber:
                    filenumber = tmpfilenumber
            except:
                pass
    else:
        filenumber = 1

    # Genera el contenido
    filecontent = ""
    filecontent = filecontent + urllib.quote_plus(
        downloadtools.limpia_nombre_excepto_1(titulo)) + '\n'
    filecontent = filecontent + urllib.quote_plus(url) + '\n'
    filecontent = filecontent + urllib.quote_plus(thumbnail) + '\n'
    filecontent = filecontent + urllib.quote_plus(server) + '\n'
    filecontent = filecontent + urllib.quote_plus(
        downloadtools.limpia_nombre_excepto_1(plot)) + '\n'
    filecontent = filecontent + urllib.quote_plus(fulltitle) + '\n'
    filecontent = filecontent + urllib.quote_plus(canal) + '\n'

    # Genera el nombre de fichero
    from core import scrapertools
    filename = '%08d-%s.txt' % (filenumber, scrapertools.slugify(fulltitle))
    logger.info("tvalacarta.core.favoritos savebookmark filename=" + filename)

    # Graba el fichero
    if not usingsamba(savepath):
        fullfilename = os.path.join(savepath, filename)
        bookmarkfile = open(fullfilename, "w")
        bookmarkfile.write(filecontent)
        bookmarkfile.flush()
        bookmarkfile.close()
    else:
        samba.write_file(filename, filecontent, savepath)
Exemplo n.º 26
0
def downloadall(item):
    logger.info("[descargas.py] downloadall")

    # Lee la lista de ficheros
    if usingsamba:
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)

    logger.info("[descargas.py] numero de ficheros=%d" % len(ficheros))

    # La ordena
    ficheros.sort()

    # Crea un listado con las entradas de favoritos
    for fichero in ficheros:
        # El primer video de la lista
        logger.info("[descargas.py] fichero=" + fichero)

        if fichero != "error" and fichero != ".DS_Store":
            # Descarga el vídeo
            try:
                # Lee el bookmark
                canal, titulo, thumbnail, plot, server, url, fulltitle = favoritos.readbookmark(
                    fichero, DOWNLOAD_LIST_PATH)
                logger.info("[descargas.py] url=" + url)

                # Averigua la URL del vídeo
                video_urls, puedes, motivo = servertools.resolve_video_urls_for_playing(
                    server, url, "", False)

                # La última es la de mayor calidad, lo mejor para la descarga
                mediaurl = video_urls[len(video_urls) - 1][1]
                logger.info("[descargas.py] mediaurl=" + mediaurl)

                # Genera el NFO
                nfofilepath = downloadtools.getfilefromtitle(
                    "sample.nfo", fulltitle)
                outfile = open(nfofilepath, "w")
                outfile.write("<movie>\n")
                outfile.write("<title>(" + fulltitle + ")</title>\n")
                outfile.write("<originaltitle></originaltitle>\n")
                outfile.write("<rating>0.000000</rating>\n")
                outfile.write("<year>2009</year>\n")
                outfile.write("<top250>0</top250>\n")
                outfile.write("<votes>0</votes>\n")
                outfile.write("<outline></outline>\n")
                outfile.write("<plot>" + plot + "</plot>\n")
                outfile.write("<tagline></tagline>\n")
                outfile.write("<runtime></runtime>\n")
                outfile.write("<thumb></thumb>\n")
                outfile.write("<mpaa>Not available</mpaa>\n")
                outfile.write("<playcount>0</playcount>\n")
                outfile.write("<watched>false</watched>\n")
                outfile.write("<id>tt0432337</id>\n")
                outfile.write("<filenameandpath></filenameandpath>\n")
                outfile.write("<trailer></trailer>\n")
                outfile.write("<genre></genre>\n")
                outfile.write("<credits></credits>\n")
                outfile.write("<director></director>\n")
                outfile.write("<actor>\n")
                outfile.write("<name></name>\n")
                outfile.write("<role></role>\n")
                outfile.write("</actor>\n")
                outfile.write("</movie>")
                outfile.flush()
                outfile.close()
                logger.info("[descargas.py] Creado fichero NFO")

                # Descarga el thumbnail
                if thumbnail != "":
                    logger.info("[descargas.py] thumbnail=" + thumbnail)
                    thumbnailfile = downloadtools.getfilefromtitle(
                        thumbnail, fulltitle)
                    thumbnailfile = thumbnailfile[:-4] + ".tbn"
                    logger.info("[descargas.py] thumbnailfile=" +
                                thumbnailfile)
                    try:
                        downloadtools.downloadfile(thumbnail, thumbnailfile)
                        logger.info("[descargas.py] Thumbnail descargado")
                    except:
                        logger.info(
                            "[descargas.py] error al descargar thumbnail")
                        for line in sys.exc_info():
                            logger.error("%s" % line)

                # Descarga el video
                #dev = downloadtools.downloadtitle(mediaurl,fulltitle)
                dev = downloadtools.downloadbest(video_urls, fulltitle)
                if dev == -1:
                    # El usuario ha cancelado la descarga
                    logger.info("[descargas.py] Descarga cancelada")
                    return
                elif dev == -2:
                    # Error en la descarga, lo mueve a ERROR y continua con el siguiente
                    logger.info("[descargas.py] ERROR EN DESCARGA DE " +
                                fichero)
                    if not usingsamba:
                        origen = os.path.join(DOWNLOAD_LIST_PATH, fichero)
                        destino = os.path.join(ERROR_PATH, fichero)
                        import shutil
                        shutil.move(origen, destino)
                    else:
                        favoritos.savebookmark(canal, titulo, url, thumbnail,
                                               server, plot, fulltitle,
                                               ERROR_PATH)
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                else:
                    logger.info("[descargas.py] Video descargado")
                    # Borra el bookmark e itera para obtener el siguiente video
                    filepath = os.path.join(DOWNLOAD_LIST_PATH, fichero)
                    if usingsamba:
                        os.remove(filepath)
                    else:
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                    logger.info("[descargas.py] " + fichero + " borrado")
            except:
                logger.info("[descargas.py] ERROR EN DESCARGA DE " + fichero)
                import sys
                for line in sys.exc_info():
                    logger.error("%s" % line)
                if not usingsamba:
                    origen = os.path.join(DOWNLOAD_LIST_PATH, fichero)
                    destino = os.path.join(ERROR_PATH, fichero)
                    import shutil
                    shutil.move(origen, destino)
                else:
                    favoritos.savebookmark(canal, titulo, url, thumbnail,
                                           server, plot, fulltitle, ERROR_PATH)
                    favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
Exemplo n.º 27
0
def downloadall(item):
    logger.info("core.descargas downloadall")

    # Lee la lista de ficheros
    if usingsamba:
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)

    logger.info("core.descargas numero de ficheros=%d" % len(ficheros))

    # La ordena
    ficheros.sort()
    
    # Crea un listado con las entradas de favoritos
    for fichero in ficheros:
        # El primer video de la lista
        logger.info("core.descargas fichero="+fichero)

        if fichero!="error" and fichero!=".DS_Store":
            # Descarga el vídeo
            try:
                # Lee el bookmark
                canal,titulo,thumbnail,plot,server,url,fulltitle = favoritos.readbookmark(fichero,DOWNLOAD_LIST_PATH)
                logger.info("core.descargas url="+url)

                # Averigua la URL del vídeo
                exec "from servers import "+server+" as server_connector"
                video_urls = server_connector.get_video_url( page_url=url , premium=(config.get_setting("megavideopremium")=="true") , user=config.get_setting("megavideouser") , password=config.get_setting("megavideopassword") )

                # La primera es la de mayor calidad, lo mejor para la descarga
                mediaurl = video_urls[0][1]
                logger.info("core.descargas mediaurl="+mediaurl)

                # Genera el NFO
                nfofilepath = downloadtools.getfilefromtitle("sample.nfo",fulltitle)
                outfile = open(nfofilepath,"w")
                outfile.write("<movie>\n")
                outfile.write("<title>("+fulltitle+")</title>\n")
                outfile.write("<originaltitle></originaltitle>\n")
                outfile.write("<rating>0.000000</rating>\n")
                outfile.write("<year>2009</year>\n")
                outfile.write("<top250>0</top250>\n")
                outfile.write("<votes>0</votes>\n")
                outfile.write("<outline></outline>\n")
                outfile.write("<plot>"+plot+"</plot>\n")
                outfile.write("<tagline></tagline>\n")
                outfile.write("<runtime></runtime>\n")
                outfile.write("<thumb></thumb>\n")
                outfile.write("<mpaa>Not available</mpaa>\n")
                outfile.write("<playcount>0</playcount>\n")
                outfile.write("<watched>false</watched>\n")
                outfile.write("<id>tt0432337</id>\n")
                outfile.write("<filenameandpath></filenameandpath>\n")
                outfile.write("<trailer></trailer>\n")
                outfile.write("<genre></genre>\n")
                outfile.write("<credits></credits>\n")
                outfile.write("<director></director>\n")
                outfile.write("<actor>\n")
                outfile.write("<name></name>\n")
                outfile.write("<role></role>\n")
                outfile.write("</actor>\n")
                outfile.write("</movie>")
                outfile.flush()
                outfile.close()
                logger.info("core.descargas Creado fichero NFO")
                
                # Descarga el thumbnail
                if thumbnail != "":
                   logger.info("core.descargas thumbnail="+thumbnail)
                   thumbnailfile = downloadtools.getfilefromtitle(thumbnail,fulltitle)
                   thumbnailfile = thumbnailfile[:-4] + ".tbn"
                   logger.info("core.descargas thumbnailfile="+thumbnailfile)
                   try:
                       downloadtools.downloadfile(thumbnail,thumbnailfile)
                       logger.info("core.descargas Thumbnail descargado")
                   except:
                       logger.info("core.descargas error al descargar thumbnail")
                       for line in sys.exc_info():
                           logger.error( "%s" % line )
                
                # Descarga el video
                dev = downloadtools.downloadtitle(mediaurl,fulltitle)
                if dev == -1:
                    # El usuario ha cancelado la descarga
                    logger.info("core.descargas Descarga cancelada")
                    return
                elif dev == -2:
                    # Error en la descarga, lo mueve a ERROR y continua con el siguiente
                    logger.info("core.descargas ERROR EN DESCARGA DE "+fichero)
                    if not usingsamba:
                        origen = os.path.join( DOWNLOAD_LIST_PATH , fichero )
                        destino = os.path.join( ERROR_PATH , fichero )
                        import shutil
                        shutil.move( origen , destino )
                    else:
                        favoritos.savebookmark(canal,titulo, url, thumbnail, server, plot, fulltitle, ERROR_PATH)
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                else:
                    logger.info("core.descargas Video descargado")
                    # Borra el bookmark e itera para obtener el siguiente video
                    filepath = os.path.join( DOWNLOAD_LIST_PATH , fichero )
                    if usingsamba:
                        os.remove(filepath)
                    else:
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                    logger.info("core.descargas "+fichero+" borrado")
            except:
                logger.info("core.descargas ERROR EN DESCARGA DE "+fichero)
                import sys
                for line in sys.exc_info():
                    logger.error( "%s" % line )
                if not usingsamba:
                    origen = os.path.join( DOWNLOAD_LIST_PATH , fichero )
                    destino = os.path.join( ERROR_PATH , fichero )
                    import shutil
                    shutil.move( origen , destino )
                else:
                    favoritos.savebookmark(canal,titulo, url, thumbnail, server, plot, fulltitle,ERROR_PATH)
                    favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)

    if config.is_xbmc():
        import xbmc
        xbmc.executebuiltin("XBMC.Container.Refresh()");    
Exemplo n.º 28
0
def downloadall(item):
    logger.info("core.descargas downloadall")

    # Lee la lista de ficheros
    if usingsamba:
        ficheros = samba.get_files(DOWNLOAD_LIST_PATH)
    else:
        ficheros = os.listdir(DOWNLOAD_LIST_PATH)

    logger.info("core.descargas numero de ficheros=%d" % len(ficheros))

    # La ordena
    ficheros.sort()

    # Crea un listado con las entradas de favoritos
    for fichero in ficheros:
        # El primer video de la lista
        logger.info("core.descargas fichero=" + fichero)

        if fichero != "error" and fichero != ".DS_Store":
            # Descarga el vídeo
            try:
                # Lee el bookmark
                canal, titulo, thumbnail, plot, server, url, fulltitle = favoritos.readbookmark(
                    fichero, DOWNLOAD_LIST_PATH)
                logger.info("core.descargas url=" + url)

                # Averigua la URL del vídeo
                exec "from servers import " + server + " as server_connector"
                video_urls = server_connector.get_video_url(
                    page_url=url,
                    premium=(config.get_setting("megavideopremium") == "true"),
                    user=config.get_setting("megavideouser"),
                    password=config.get_setting("megavideopassword"))

                # La primera es la de mayor calidad, lo mejor para la descarga
                mediaurl = video_urls[0][1]
                logger.info("core.descargas mediaurl=" + mediaurl)

                # Genera el NFO
                nfofilepath = downloadtools.getfilefromtitle(
                    "sample.nfo", fulltitle)
                outfile = open(nfofilepath, "w")
                outfile.write("<movie>\n")
                outfile.write("<title>(" + fulltitle + ")</title>\n")
                outfile.write("<originaltitle></originaltitle>\n")
                outfile.write("<rating>0.000000</rating>\n")
                outfile.write("<year>2009</year>\n")
                outfile.write("<top250>0</top250>\n")
                outfile.write("<votes>0</votes>\n")
                outfile.write("<outline></outline>\n")
                outfile.write("<plot>" + plot + "</plot>\n")
                outfile.write("<tagline></tagline>\n")
                outfile.write("<runtime></runtime>\n")
                outfile.write("<thumb></thumb>\n")
                outfile.write("<mpaa>Not available</mpaa>\n")
                outfile.write("<playcount>0</playcount>\n")
                outfile.write("<watched>false</watched>\n")
                outfile.write("<id>tt0432337</id>\n")
                outfile.write("<filenameandpath></filenameandpath>\n")
                outfile.write("<trailer></trailer>\n")
                outfile.write("<genre></genre>\n")
                outfile.write("<credits></credits>\n")
                outfile.write("<director></director>\n")
                outfile.write("<actor>\n")
                outfile.write("<name></name>\n")
                outfile.write("<role></role>\n")
                outfile.write("</actor>\n")
                outfile.write("</movie>")
                outfile.flush()
                outfile.close()
                logger.info("core.descargas Creado fichero NFO")

                # Descarga el thumbnail
                if thumbnail != "":
                    logger.info("core.descargas thumbnail=" + thumbnail)
                    thumbnailfile = downloadtools.getfilefromtitle(
                        thumbnail, fulltitle)
                    thumbnailfile = thumbnailfile[:-4] + ".tbn"
                    logger.info("core.descargas thumbnailfile=" +
                                thumbnailfile)
                    try:
                        downloadtools.downloadfile(thumbnail, thumbnailfile)
                        logger.info("core.descargas Thumbnail descargado")
                    except:
                        logger.info(
                            "core.descargas error al descargar thumbnail")
                        for line in sys.exc_info():
                            logger.error("%s" % line)

                # Descarga el video
                dev = downloadtools.downloadtitle(mediaurl, fulltitle)
                if dev == -1:
                    # El usuario ha cancelado la descarga
                    logger.info("core.descargas Descarga cancelada")
                    return
                elif dev == -2:
                    # Error en la descarga, lo mueve a ERROR y continua con el siguiente
                    logger.info("core.descargas ERROR EN DESCARGA DE " +
                                fichero)
                    if not usingsamba:
                        origen = os.path.join(DOWNLOAD_LIST_PATH, fichero)
                        destino = os.path.join(ERROR_PATH, fichero)
                        import shutil
                        shutil.move(origen, destino)
                    else:
                        favoritos.savebookmark(canal, titulo, url, thumbnail,
                                               server, plot, fulltitle,
                                               ERROR_PATH)
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                else:
                    logger.info("core.descargas Video descargado")
                    # Borra el bookmark e itera para obtener el siguiente video
                    filepath = os.path.join(DOWNLOAD_LIST_PATH, fichero)
                    if usingsamba:
                        os.remove(filepath)
                    else:
                        favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)
                    logger.info("core.descargas " + fichero + " borrado")
            except:
                logger.info("core.descargas ERROR EN DESCARGA DE " + fichero)
                import sys
                for line in sys.exc_info():
                    logger.error("%s" % line)
                if not usingsamba:
                    origen = os.path.join(DOWNLOAD_LIST_PATH, fichero)
                    destino = os.path.join(ERROR_PATH, fichero)
                    import shutil
                    shutil.move(origen, destino)
                else:
                    favoritos.savebookmark(canal, titulo, url, thumbnail,
                                           server, plot, fulltitle, ERROR_PATH)
                    favoritos.deletebookmark(fichero, DOWNLOAD_LIST_PATH)

    if config.is_xbmc():
        import xbmc
        xbmc.executebuiltin("XBMC.Container.Refresh()")