def savetorrent(uri,image,torr_folder,modo): import tools if uri.startswith("file://"): file = uri.replace("file://","") else: return False try: f = open(file , "rb+") torrent_data=f.read() f.close() except: return False import base64 import bencode import hashlib try: metadata = bencode.bdecode(torrent_data) except: pass try: title = metadata['info']['name'] except: title = "" modo = 2 pass title = title.replace(".avi","").replace(".mp4","").replace(".mkv","").replace("+"," ").replace(",","").replace("?","").replace("*","") try: title = unicode(title,'utf-8') title = tools.latin1_to_ascii(title) #title = tools.StripTags(title) except: pass if modo == 2: keyboard = xbmc.Keyboard(title) keyboard.doModal() if (keyboard.isConfirmed()): title = keyboard.getText() else: return False try: f = open(os.path.join( torr_folder , title + ".torrent") , "wb+") f.write(torrent_data) f.close() except: return False if image != "": image_data = "" if image.startswith("http"): image_data = url_get(image) else: try: f = open(image , "rb+") image_data=f.read() f.close() except: pass if image_data =="": return "nocarat"+title if ".png" in image.lower(): ext=".png" elif ".gif" in image.lower(): ext=".gif" elif ".jpg" in image.lower(): ext= ".jpg" else: ext = ".img" try: f = open(os.path.join( torr_folder , title + ext ) , "wb+") f.write(image_data) f.close() except: os.remove(os.path.join( torr_folder , title + ext )) return "nocarat"+title else: return "nocarat"+title return title
def guardar_magnet(uri,player,image,torr_folder,teclado=False): title ="" try: title = uri.rsplit("dn=")[1] title = title.rsplit("&")[0] title = urllib.unquote_plus(title) title = title.replace("+"," ").replace(",","").replace("¿","").replace("?","").replace("*","") title = unicode(title,'utf-8') title = tools.latin1_to_ascii(title) except: pass if title == "" or teclado: keyboard = xbmc.Keyboard(title) keyboard.doModal() if (keyboard.isConfirmed()): title = keyboard.getText() else: return if title == "": xbmcgui.Dialog().ok("Torrentin" , "Tienes que escribir un nombre para el magnet,","Repite el proceso y escribelo con el teclado.") if __addon__.getSetting('reopen') == "true": principal(uri,player,image) return try: f = open(os.path.join( torr_folder , title + ".magnet") , "wb+") f.write(uri) f.close() except: mensaje('ERROR al guardar el magnet, revisa el nombre.', 5000) guardar_magnet(uri,player,image,torr_folder,True) return # Guardamos la caratula if image != "": image_data = "" if image.startswith("http"): image_data = torrents.url_get(image) else: try: f = open(image, "rb+") image_data=f.read() f.close() except: pass if image_data =="": mensaje('ERROR al obtener la caratula.', 4000) try: f = open(os.path.join( __cwd__ ,"resources","images","magnetlogo.png") , "rb+") image_data=f.read() f.close() f = open(os.path.join( torr_folder , title + ".png" ) , "wb+") f.write(image_data) f.close() except: pass if __addon__.getSetting('reopen') == "true": principal(uri,player,image) return if ".png" in image.lower(): ext=".png" elif ".gif" in image.lower(): ext=".gif" elif ".jpg" in image.lower(): ext= ".jpg" else: ext = ".img" try: f = open(os.path.join( torr_folder , title + ext ) , "wb+") f.write(image_data) f.close() except: mensaje('ERROR al guardar la caratula.', 3000) if __addon__.getSetting('reopen') == "true": principal(uri,player,image) return else: try: f = open(os.path.join( __cwd__ ,"resources","images","magnetlogo.png") , "rb+") image_data=f.read() f.close() f = open(os.path.join( torr_folder , title + ".png" ) , "wb+") f.write(image_data) f.close() except: mensaje('ERROR al guardar la caratula.', 3000) if __addon__.getSetting('reopen') == "true": principal(uri,player,image) return show_Msg('Magnet y Caratula guardados:',title,5000) if __addon__.getSetting('reopen') == "true": principal(uri,player,image)