From c3499d99a20a4e2404472b38dd6248b6b02007e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20de=20Chalendar?= Date: Thu, 22 Aug 2024 23:00:17 +0200 Subject: [PATCH] Works on windows installed locally --- pyproject.toml | 5 +++-- requirements.txt | 3 ++- src/worker.py | 9 +++++---- src/yaas.py | 4 ++-- src/yturl2mp3/helpers.py | 12 +++++++----- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5c7a9bf..2a040ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,8 +31,9 @@ dependencies = [ "torch >= 2.1.0", "torchaudio >= 2.1.0", "openunmix >= 1.3.0", - "pytubefix >= 6.1.2", - "moviepy >= 1.0.3" + "pytubefix >= 6.13.0", + "moviepy >= 1.0.3", + "PySoundFile >= 0.9.0.post1", ] keywords = ["audio", "video", "track", "split", "gui", "qt"] diff --git a/requirements.txt b/requirements.txt index 2aaf468..4877476 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,10 +2,11 @@ PySide6 openunmix torch -pytubefix==6.1.2 +pytubefix==6.13.0 moviepy==1.0.3 pydub ffmpeg +PySoundFile # setup requirements setuptools>=54.0.0 diff --git a/src/worker.py b/src/worker.py index 2f3b58b..16908cf 100644 --- a/src/worker.py +++ b/src/worker.py @@ -20,8 +20,9 @@ class Worker(QThread): extraction_done = Signal() extraction_failed = Signal(str) - def __init__(self, url, out): + def __init__(self, url, yaas): super().__init__() + self.update_status.connect(yaas.update_status) # Get the writable location for application data self.app_data_path = QStandardPaths.writableLocation( QStandardPaths.AppDataLocation) @@ -32,7 +33,7 @@ def __init__(self, url, out): print(f'Created app_data_path {self.app_data_path}', file=sys.stderr) self.url = url - self.out = out + self.out = yaas.args.out QDir().mkpath(self.out) def run(self): @@ -53,7 +54,7 @@ def run(self): os.remove(flac_path) def download_audio(self, url): - self.update_status.emit(f"Downloading audio from {url}...") + self.update_status.emit(f"Downloading audio from {url} ...") filename = "" try: if is_valid_video_url(url): @@ -63,7 +64,7 @@ def download_audio(self, url): video = YouTube(url) config = Config(out_dir=self.app_data_path, timeout=5000, max_retries=3) - self.update_status.emit(f"Downloading audio to {self.app_data_path}...") + self.update_status.emit(f"Downloading audio to {self.app_data_path} ...") path = download_mp3(video, config) self.update_status.emit(f'Converting video {path} to MP3 File...') diff --git a/src/yaas.py b/src/yaas.py index 7c5985c..e8645b8 100644 --- a/src/yaas.py +++ b/src/yaas.py @@ -74,8 +74,7 @@ def start_process(self): url = self.browser.url().url() if url: self.update_status(f"Splitting sound track of {url}") - self.worker = Worker(url, self.args.out) - self.worker.update_status.connect(self.update_status) + self.worker = Worker(url, self) self.worker.ex_exit.connect(self.ex_exit) # Change the cursor to busy QApplication.setOverrideCursor(Qt.WaitCursor) @@ -124,6 +123,7 @@ def extraction_failed(self, message: str): def main(): + os.environ["QTWEBENGINE_DISABLE_SANDBOX"] = "1" app = QApplication(sys.argv) main_window = MainWindow() diff --git a/src/yturl2mp3/helpers.py b/src/yturl2mp3/helpers.py index 346c1d4..e5b4ee1 100644 --- a/src/yturl2mp3/helpers.py +++ b/src/yturl2mp3/helpers.py @@ -22,11 +22,13 @@ def download_mp3(video: YouTube, config: Config) -> str: """ # returns the mp4 only containing audio stream = video.streams.get_lowest_resolution() - stream.download(output_path=config.out_dir, timeout=config.timeout, - max_retries=config.max_retries, - skip_existing=True) + path_to_saved = stream.download( + output_path=config.out_dir, timeout=config.timeout, + max_retries=config.max_retries, + skip_existing=True) + path_to_saved = os.path.realpath(path_to_saved) mp4_path = Path(config.out_dir) / stream.default_filename - return str(mp4_path) + return path_to_saved def convert_mp4_to_mp3(path: str, delete_after: bool = True) -> str: @@ -41,7 +43,7 @@ def convert_mp4_to_mp3(path: str, delete_after: bool = True) -> str: mp4 = editor.VideoFileClip(path) mp3 = mp4.audio - mp3.write_audiofile(mp3_path, verbose=False, logger=None) + mp3.write_audiofile(mp3_path, verbose=True, logger=None) mp3.close() mp4.close()