phyton virus when exporting exe with pyinstaller

31 views Asked by At

I am having problems when I want to export my code with pyinstaller since when creating the file I pass it through a total virus and 17 antiviruses mark it as a virus, what do I do?

import tkinter as tk
from tkinter import ttk, filedialog, messagebox
from pytube import YouTube
import os

descargando = False

def seleccionar_carpeta():
    ruta_seleccionada = filedialog.askdirectory()
    if ruta_seleccionada:
        entry_ruta.config(state='normal')
        entry_ruta.delete(0, tk.END)
        entry_ruta.insert(0, ruta_seleccionada)
        entry_ruta.config(state='readonly')

def descargar_video():
    global descargando
    descargando = True
    url = entry_url.get()
    ruta_guardado = entry_ruta.get()
    formato = formato_var.get()
    
    try:
        video = YouTube(url)
        if formato == "mp3":
            stream = video.streams.filter(only_audio=True).first()
        else:
            # Filtrar opciones de transmisión por formato, progresiva y resolución
            stream = video.streams.filter(file_extension=formato, progressive=True, resolution="1440p").first() or \
                     video.streams.filter(file_extension=formato, progressive=True, resolution="2160p").first() or \
                     video.streams.filter(file_extension=formato, progressive=True, resolution="1080p").first() or \
                     video.streams.filter(file_extension=formato, progressive=True, resolution="720p").first()
            if not stream:
                raise Exception("No se encontró una opción compatible para la descarga")
        if not ruta_guardado:
            ruta_guardado = filedialog.askdirectory()
            entry_ruta.config(state='normal')
            entry_ruta.delete(0, tk.END)
            entry_ruta.insert(0, ruta_guardado)
            entry_ruta.config(state='readonly')
        
        # Verificar si el archivo ya existe en la ruta de guardado y agregar sufijo numerado si es necesario
        nombre_archivo = video.title + "." + formato
        contador = 1
        while os.path.exists(os.path.join(ruta_guardado, nombre_archivo)):
            nombre_archivo = f"{video.title}({contador}).{formato}"
            contador += 1
        
        iniciar_descarga(stream, ruta_guardado, nombre_archivo)
    except Exception as e:
        status_label.config(text="Ocurrió un error: " + str(e))
        messagebox.showerror("Error", str(e))
        descargando = False

def iniciar_descarga(stream, ruta_guardado, nombre_archivo):
    global descargando
    try:
        label_espera.config(text="Espere...")
        entry_ruta.config(state='normal')
        button_descargar.config(state='disabled')

        stream.download(output_path=ruta_guardado, filename=nombre_archivo)
        status_label.config(text="Descarga completada!")
    except Exception as e:
        status_label.config(text="Ocurrió un error: " + str(e))
        messagebox.showerror("Error", str(e))
    finally:
        label_espera.config(text="")
        entry_ruta.config(state='readonly')
        button_descargar.config(state='normal')
        descargando = False

def on_closing():
    if descargando:
        messagebox.showinfo("Espere", "La descarga está en progreso. Por favor, espere a que termine.")
    else:
        root.destroy()

# Configuración de la ventana
root = tk.Tk()
root.title("Descargador de videos de YouTube")
root.geometry("600x200")
root.resizable(False, False)  # Evitar que el usuario cambie el tamaño de la ventana
root.protocol("WM_DELETE_WINDOW", on_closing)  # Configurar la acción de cierre de la ventana

# Estilo ttk
style = ttk.Style()
style.theme_use('clam')
style.configure('TButton', background='#008CBA', foreground='white')
style.configure('TLabel', background='#F0F0F0', foreground='#333333')
style.configure('TFrame', background='#F0F0F0')
style.configure('TEntry', foreground='#333333', relief='flat')

# Crear widgets
frame = ttk.Frame(root, padding="10", style='TFrame')
frame.grid(row=0, column=0, padx=10, pady=10)

label_url = ttk.Label(frame, text="URL del video:", style='TLabel')
label_url.grid(row=0, column=0, padx=5, pady=5, sticky="w")
entry_url = ttk.Entry(frame, width=50)
entry_url.grid(row=0, column=1, padx=5, pady=5)

label_ruta = ttk.Label(frame, text="Ruta de guardado:", style='TLabel')
label_ruta.grid(row=1, column=0, padx=5, pady=5, sticky="w")
entry_ruta = ttk.Entry(frame, width=50, state='readonly')
entry_ruta.grid(row=1, column=1, padx=5, pady=5)
button_ruta = ttk.Button(frame, text="Seleccionar carpeta", command=seleccionar_carpeta)
button_ruta.grid(row=1, column=2, padx=5, pady=5)

label_formato = ttk.Label(frame, text="Formato:", style='TLabel')
label_formato.grid(row=2, column=0, padx=5, pady=5, sticky="w")
formato_var = tk.StringVar(root)
formatos = ["mp4", "mp3"]
formato_dropdown = ttk.Combobox(frame, textvariable=formato_var, values=formatos)
formato_dropdown.set(formatos[0])  # formato por defecto
formato_dropdown.grid(row=2, column=1, padx=3, pady=3)

button_descargar = ttk.Button(frame, text="Descargar", command=descargar_video, style='TButton')
button_descargar.grid(row=3, column=0, columnspan=2, pady=10)

status_label = ttk.Label(frame, text="", style='TLabel')
status_label.grid(row=4, column=0, columnspan=2)

label_espera = ttk.Label(frame, text="", style='TLabel')
label_espera.grid(row=5, column=0, columnspan=2)

# Ejecutar la ventana
root.mainloop()

that is my code how can I solve my problem I am a beginner and I don't know much. Any help is appreciated. I have tried it only with py to install and when I want to encrypt it tells me an assii character error not supported. I don't know why.

0

There are 0 answers