Skip to content

Commit

Permalink
#14 added FLAC audio output
Browse files Browse the repository at this point in the history
  • Loading branch information
rohankishore authored Jun 24, 2024
1 parent cafc915 commit 0f8994d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions youtility/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ def get_gif():
youtube_client.streams.filter(file_extension='mp4') # Use your specific extension
stream = youtube_client.streams.filter(only_audio=True).first()
self.file_size = stream.filesize # Set the file size
stream.download(output_path=self.save_path, filename=self.filename + ".mp4")
stream.download(output_path=self.save_path, filename=self.filename + ".mp3")

# Conversion to FLAC using ffmpeg
if self.audio_format == "FLAC":
input_file = os.path.join(self.save_path, self.filename + ".mp4").replace("\\", "/")
input_file = os.path.join(self.save_path, self.filename + ".mp3").replace("\\", "/")
output_file = os.path.join(self.save_path, self.filename + ".flac").replace("\\", "/")

# Run the ffmpeg command to convert mp4 to flac
ffmpeg_command = f'ffmpeg -i "{input_file}" "{output_file}"'
try:
subprocess.run(ffmpeg_command, shell=True, check=True)
os.remove(input_file)
except subprocess.CalledProcessError as e:
print(f"Error during conversion: {e}")
self.list_item.setText((title + " - Download failed during conversion"))
Expand Down

0 comments on commit 0f8994d

Please sign in to comment.