/
op1x
/
MPPlus
Обзор
Документация
Войти
/
op1x
/
MPPlus
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
install_window.py
76 строк
3 KB
Op1x
second commit
10 ноя 2025, 00:05
10 ноя 2025, 00:05
cc1eabd
Код
Авторство
О чём код?
import sys import os from PyQt6 import uic from PyQt6.QtWidgets import QWidget, QApplication from PyQt6.QtCore import QTimer from yt_dlp import YoutubeDL class InstallWindow(QWidget): def __init__(self): super().__init__() self.current_dir = os.path.dirname(os.path.abspath(__file__)) ui_path = os.path.join(self.current_dir, "templates", "install_window.ui") uic.loadUi(ui_path, self) self.setWindowTitle("Скачать песню") self.start_button.clicked.connect(self.start_installation) self.ok_button.clicked.connect(self.close) self.status_label.setText("") self.status_label.setStyleSheet("font-weight: bold;") def start_installation(self): url = self.urlinput_line.text().strip() if not url: self.status_label.setText("Введите ссылку!") self.status_label.setStyleSheet("color: orange; font-weight: bold;") return self.status_label.setText("Песня скачивается, " "не закрывайте окно") self.status_label.setStyleSheet("color: white; font-weight: bold;") QApplication.processEvents() QTimer.singleShot(100, lambda: self.download_song(url)) def download_song(self, url): try: download_dir = os.path.join(self.current_dir, "playlists", "Downloaded") os.makedirs(download_dir, exist_ok=True) ydl_opts = { 'format': 'bestaudio/best', 'outtmpl': os.path.join(download_dir, '%(title)s.%(ext)s'), 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }], } with YoutubeDL(ydl_opts) as ydl: result = ydl.extract_info(url, download=True) if result is not None: self.status_label.setText("Успешно скачано!") self.status_label.setStyleSheet("color: green; font-weight: bold;") else: raise Exception("Empty result") except Exception as e: self.status_label.setText("Неправильная ссылка!") self.status_label.setStyleSheet("color: red; font-weight: bold;") print(f"[Ошибка yt_dlp]: {e}") if __name__ == "__main__": app = QApplication(sys.argv) window = InstallWindow() window.show() sys.exit(app.exec()) # https://youtu.be/rxNObTcYNUo?si=6dqwlakC_QLxJfey