Füge die Möglichkeit hinzu, Downloads abzubrechen.
This commit is contained in:
67
main.py
67
main.py
@@ -72,6 +72,8 @@ class DownloadThread(QThread):
|
||||
self.cmd_args = cmd_args
|
||||
self.use_local_ytdlp = use_local_ytdlp
|
||||
self.output_filename = output_filename
|
||||
self.process = None
|
||||
self.abort = False
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
@@ -144,7 +146,7 @@ class DownloadThread(QThread):
|
||||
|
||||
# Unterdrücke das CMD-Fenster unter Windows
|
||||
creationflags = subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0
|
||||
process = subprocess.Popen(
|
||||
self.process = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
@@ -154,20 +156,35 @@ class DownloadThread(QThread):
|
||||
creationflags=creationflags
|
||||
)
|
||||
|
||||
for line in process.stdout:
|
||||
for line in self.process.stdout:
|
||||
if self.abort:
|
||||
self.process.terminate()
|
||||
self.update_signal.emit("Download abgebrochen.")
|
||||
self.finished_signal.emit(False, "Download wurde abgebrochen.")
|
||||
return
|
||||
self.update_signal.emit(line.strip())
|
||||
|
||||
process.wait()
|
||||
self.process.wait()
|
||||
|
||||
if process.returncode == 0:
|
||||
if self.abort:
|
||||
self.finished_signal.emit(False, "Download wurde abgebrochen.")
|
||||
elif self.process.returncode == 0:
|
||||
self.finished_signal.emit(True, "Download erfolgreich abgeschlossen!")
|
||||
else:
|
||||
self.finished_signal.emit(False, f"Download fehlgeschlagen mit Exitcode {process.returncode}")
|
||||
self.finished_signal.emit(False, f"Download fehlgeschlagen mit Exitcode {self.process.returncode}")
|
||||
|
||||
except Exception as e:
|
||||
self.update_signal.emit(f"Fehler: {str(e)}")
|
||||
self.finished_signal.emit(False, f"Fehler: {str(e)}")
|
||||
|
||||
def stop(self):
|
||||
self.abort = True
|
||||
if self.process:
|
||||
try:
|
||||
self.update_signal.emit("Versuche Download zu beenden...")
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class PresetDialog(QDialog):
|
||||
def __init__(self, parent=None, preset_data=None):
|
||||
@@ -974,6 +991,11 @@ class MainWindow(QMainWindow):
|
||||
self.cmd_preview.setText(" ".join(formatted_cmd))
|
||||
|
||||
def start_download(self):
|
||||
# Wenn bereits ein Download läuft und der Button als "Abbrechen" angezeigt wird
|
||||
if self.download_thread and self.download_thread.isRunning():
|
||||
self.abort_download()
|
||||
return
|
||||
|
||||
url = self.url_input.text()
|
||||
if not url:
|
||||
QMessageBox.warning(self, "Fehler", "Bitte geben Sie eine URL ein.")
|
||||
@@ -1043,9 +1065,37 @@ class MainWindow(QMainWindow):
|
||||
)
|
||||
self.download_thread.update_signal.connect(self.update_log)
|
||||
self.download_thread.finished_signal.connect(self.download_finished)
|
||||
self.download_btn.setEnabled(False)
|
||||
|
||||
# Ändere den Button-Text und deaktiviere UI-Elemente während des Downloads
|
||||
self.download_btn.setText("Download abbrechen")
|
||||
self.disable_ui_during_download(True)
|
||||
|
||||
self.download_thread.start()
|
||||
|
||||
def abort_download(self):
|
||||
"""Bricht den aktuellen Download ab."""
|
||||
if self.download_thread and self.download_thread.isRunning():
|
||||
self.log_output.append("Abbruch angefordert...")
|
||||
self.download_thread.stop()
|
||||
# Button wird in download_finished wieder auf "Download starten" gesetzt
|
||||
|
||||
def disable_ui_during_download(self, disable=True):
|
||||
"""Deaktiviert/aktiviert UI-Elemente während des Downloads."""
|
||||
self.url_input.setReadOnly(disable)
|
||||
self.preset_combo.setEnabled(not disable)
|
||||
self.add_preset_btn.setEnabled(not disable)
|
||||
self.edit_preset_btn.setEnabled(not disable)
|
||||
self.delete_preset_btn.setEnabled(not disable)
|
||||
self.optionen_btn.setEnabled(not disable)
|
||||
if hasattr(self, 'series_input'):
|
||||
self.series_input.setReadOnly(disable)
|
||||
if hasattr(self, 'season_input'):
|
||||
self.season_input.setReadOnly(disable)
|
||||
if hasattr(self, 'episode_input'):
|
||||
self.episode_input.setReadOnly(disable)
|
||||
if hasattr(self, 'custom_path_input'):
|
||||
self.custom_path_input.setReadOnly(disable)
|
||||
|
||||
def update_log(self, text):
|
||||
self.log_output.append(text)
|
||||
# Scroll zum Ende
|
||||
@@ -1053,7 +1103,10 @@ class MainWindow(QMainWindow):
|
||||
scrollbar.setValue(scrollbar.maximum())
|
||||
|
||||
def download_finished(self, success, message):
|
||||
self.download_btn.setEnabled(True)
|
||||
# UI-Elemente wieder aktivieren
|
||||
self.disable_ui_during_download(False)
|
||||
# Button-Text zurücksetzen
|
||||
self.download_btn.setText("Download starten")
|
||||
|
||||
if success:
|
||||
self.log_output.append(message)
|
||||
|
Reference in New Issue
Block a user