Inicial, descargar y conversion basicas
This commit is contained in:
90
gui/tab_youtube.py
Normal file
90
gui/tab_youtube.py
Normal file
@@ -0,0 +1,90 @@
|
||||
import os
|
||||
from PyQt6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout,QLabel, QLineEdit, QPushButton, QFileDialog, QMessageBox)
|
||||
from utils.downloader import VideoDownloader
|
||||
|
||||
class YoutubeTab(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.downloader_thread = None
|
||||
self.initUI()
|
||||
|
||||
def initUI(self):
|
||||
layout = QVBoxLayout()
|
||||
|
||||
# Input URL
|
||||
layout.addWidget(QLabel("URL del vídeo:"))
|
||||
self.url_input = QLineEdit()
|
||||
self.url_input.setPlaceholderText("https://www.youtube.com/watch?v=...")
|
||||
layout.addWidget(self.url_input)
|
||||
|
||||
# Input Ruta de destino
|
||||
layout.addWidget(QLabel("Ruta de destino:"))
|
||||
path_layout = QHBoxLayout()
|
||||
self.path_input = QLineEdit()
|
||||
# Carpeta por defecto: Descargas del usuario
|
||||
default_path = os.path.join(os.path.expanduser("~"), "Downloads")
|
||||
self.path_input.setText(default_path)
|
||||
path_layout.addWidget(self.path_input)
|
||||
|
||||
self.browse_btn = QPushButton("Examinar")
|
||||
self.browse_btn.clicked.connect(self.browse_folder)
|
||||
path_layout.addWidget(self.browse_btn)
|
||||
layout.addLayout(path_layout)
|
||||
|
||||
# Botón de Descarga
|
||||
self.download_btn = QPushButton("Descargar Vídeo MP4")
|
||||
self.download_btn.clicked.connect(self.start_download)
|
||||
layout.addWidget(self.download_btn)
|
||||
|
||||
# Label de Estado local
|
||||
self.status_label = QLabel("")
|
||||
layout.addWidget(self.status_label)
|
||||
|
||||
layout.addStretch()
|
||||
self.setLayout(layout)
|
||||
|
||||
def browse_folder(self):
|
||||
folder = QFileDialog.getExistingDirectory(self, "Seleccionar carpeta de destino")
|
||||
if folder:
|
||||
self.path_input.setText(folder)
|
||||
|
||||
def start_download(self):
|
||||
url = self.url_input.text().strip()
|
||||
save_path = self.path_input.text().strip()
|
||||
|
||||
if not url:
|
||||
QMessageBox.warning(self, "Atención", "Por favor, introduce una URL válida.")
|
||||
return
|
||||
|
||||
if not os.path.exists(save_path):
|
||||
QMessageBox.warning(self, "Atención", "La ruta de destino seleccionada no existe.")
|
||||
return
|
||||
|
||||
# Bloquear controles para evitar descargas simultáneas
|
||||
self.set_inputs_enabled(False)
|
||||
self.status_label.setText("Iniciando proceso...")
|
||||
|
||||
# Iniciar hilo en segundo plano
|
||||
self.downloader_thread = VideoDownloader(url, save_path)
|
||||
self.downloader_thread.progress_signal.connect(self.update_status)
|
||||
self.downloader_thread.finished_signal.connect(self.on_download_finished)
|
||||
self.downloader_thread.start()
|
||||
|
||||
def update_status(self, message):
|
||||
self.status_label.setText(message)
|
||||
|
||||
def on_download_finished(self, success, message):
|
||||
self.set_inputs_enabled(True)
|
||||
self.status_label.setText("")
|
||||
|
||||
if success:
|
||||
QMessageBox.information(self, "Éxito", message)
|
||||
self.url_input.clear()
|
||||
else:
|
||||
QMessageBox.critical(self, "Error", message)
|
||||
|
||||
def set_inputs_enabled(self, enabled: bool):
|
||||
self.url_input.setEnabled(enabled)
|
||||
self.path_input.setEnabled(enabled)
|
||||
self.browse_btn.setEnabled(enabled)
|
||||
self.download_btn.setEnabled(enabled)
|
||||
Reference in New Issue
Block a user