diff --git a/build.sh b/build.sh index 947d233..40c10d9 100644 --- a/build.sh +++ b/build.sh @@ -5,7 +5,7 @@ rm -rf dist pip uninstall pyutube -y # Build a wheel distribution package using the 'setup.py' file -python setup.py sdist bdist_wheel +python3 setup.py sdist bdist_wheel # Install the wheel distribution package located in the 'dist' directory # pip3 install dist/* diff --git a/pyutube/services/DownloadService.py b/pyutube/services/DownloadService.py index b0b51bf..070ed5a 100644 --- a/pyutube/services/DownloadService.py +++ b/pyutube/services/DownloadService.py @@ -75,7 +75,6 @@ def download_video(self, video: YouTube, video_id: str, video_stream: YouTube, v video_filename = self.file_service.generate_filename(video_stream, video_id) # Prepend the title number and `__` to the filename if ordering is required - if self.make_playlist_in_order: video_base_name, video_extension = os.path.splitext(video_filename) video_filename = f"{title_number}__{video_base_name}{video_extension}" diff --git a/pyutube/services/FileService.py b/pyutube/services/FileService.py index 70bbfc8..6210a27 100644 --- a/pyutube/services/FileService.py +++ b/pyutube/services/FileService.py @@ -8,7 +8,6 @@ class FileService: - def save_file(self, video: YouTube, filename: str, path: str) -> None: """ Save the file to the specified path with the given filename. @@ -32,12 +31,10 @@ def generate_filename(self, video, video_id, is_audio=False, filename: str = "") """ file_type = 'audio' if is_audio else video.resolution - extension = 'mp3' if is_audio else video.mime_type.split('/')[1] - title = filename if filename != "" else video.default_filename.split('.')[0] title = safe_filename(title) - return f"{title} - {file_type}_-_{video_id}.{extension}" + return f"{title} - {file_type}_-_{video_id}" def handle_existing_file( self, video: YouTube, video_id: str, filename: str, path: str, is_audio: bool = False) -> None: diff --git a/pyutube/services/VideoService.py b/pyutube/services/VideoService.py index 9913d1d..a2cd98d 100644 --- a/pyutube/services/VideoService.py +++ b/pyutube/services/VideoService.py @@ -161,42 +161,67 @@ def merging(self, video_name: str, audio_name: str): Args: video_name: The name of the video file. audio_name: The name of the audio file. - video_id: The ID of the video. Returns: None """ - output_directory = os.path.join(self.path, "output") os.makedirs(output_directory, exist_ok=True) - output_file = os.path.join( - output_directory, os.path.basename(video_name)) + # Output file path + output_file = os.path.join(output_directory, os.path.basename( + video_name).replace(os.path.splitext(video_name)[1], '.mp4')) + + # Extract base names to match files + video_base_name = os.path.splitext(os.path.basename(video_name))[0] + audio_base_name = os.path.splitext(os.path.basename(audio_name))[0] - video_name = os.path.join(self.path, video_name) - audio_name = os.path.join(self.path, audio_name) + # Locate the video file + video_path = None + for file in os.listdir(self.path): + file_base, _ = os.path.splitext(file) + if file_base == video_base_name: + video_path = os.path.join(self.path, file) + break + + if video_path is None: + error_console.print(f"❗ Video file not found: {video_name}") + sys.exit() + + # Locate the audio file + audio_path = None + for file in os.listdir(self.path): + file_base, _ = os.path.splitext(file) + if file_base == audio_base_name: + audio_path = os.path.join(self.path, file) + break + + if audio_path is None: + error_console.print(f"❗ Audio file not found: {audio_name}") + sys.exit() + # Merge video and audio ffmpeg_merge_video_audio( - video_name, - audio_name, + video_path, + audio_path, output_file, vcodec='copy', acodec='copy', ffmpeg_output=False, - logger=None + logger=None, ) # Remove original files - os.remove(video_name) - os.remove(audio_name) + os.remove(video_path) + os.remove(audio_path) # Move the merged file to the current directory if os.path.exists(output_file): - os.replace(output_file, os.path.join(os.getcwd(), video_name)) + merged_file_name = os.path.basename(video_name) + os.replace(output_file, os.path.join(os.getcwd(), merged_file_name)) os.rmdir(output_directory) else: - error_console.print( - "Merged video file not found in the output directory.") + error_console.print("❗ Merged video file not found in the output directory.") @staticmethod def get_video_resolutions_sizes( diff --git a/pyutube/utils.py b/pyutube/utils.py index 63eeb07..4407ca7 100644 --- a/pyutube/utils.py +++ b/pyutube/utils.py @@ -16,7 +16,7 @@ from pytubefix import __version__ as pytubefix_version -__version__ = "1.3.39" +__version__ = "1.4.0" __app__ = "pyutube" ABORTED_PREFIX = "Aborted" CANCEL_PREFIX = "Cancel"