Advertisement
nicuf

convert youtube to mp3 (BEST)

Oct 28th, 2023
800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. from pytube import YouTube
  2.  
  3. def progress(stream, chunk, bytes_remaining):
  4.     total_size = stream.filesize
  5.     bytes_downloaded = total_size - bytes_remaining
  6.     percentage_of_completion = bytes_downloaded / total_size * 100
  7.     print(f"Descărcare: {percentage_of_completion:.2f}% completă.")
  8.  
  9. def download_mp3(video_url, output_path):
  10.     yt = YouTube(video_url)
  11.     yt.register_on_progress_callback(progress)
  12.     audio_stream = yt.streams.filter(only_audio=True).first()
  13.     audio_stream.download(output_path)
  14.     print(f"Descărcarea melodiei '{yt.title}' este completă.")
  15.  
  16. video_url = "https://www.youtube.com/watch?v=YsmfWkE6FUg"
  17. output_path = "d://Downloads//uuu"
  18. download_mp3(video_url, output_path)
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement