If you want to save in .mp3 just pass the mp3=True parameter (MPEG-4 AAC audio codec):
frompytubefiximportYouTubefrompytubefix.cliimporton_progressurl="url"yt=YouTube(url, on_progress_callback=on_progress)
print(yt.title)
ys=yt.streams.get_audio_only()
ys.download(mp3=True) # pass the parameter mp3=True to save in .mp3
if you want to download complete playlists:
frompytubefiximportPlaylistfrompytubefix.cliimporton_progressurl="url"pl=Playlist(url)
forvideoinpl.videos:
ys=video.streams.get_audio_only()
ys.download(mp3=True) # pass the parameter mp3=True to save in .mp3
if you want to add authentication
frompytubefiximportYouTubefrompytubefix.cliimporton_progressurl="url"yt=YouTube(url, use_oauth=True, allow_oauth_cache=True, on_progress_callback=on_progress)
ys=yt.streams.get_audio_only()
ys.download(mp3=True) # you will only get the request to authenticate once you download
The Tidelift Subscription provides access to a continuously curated stream of human-researched and maintainer-verified data on open source packages and their licenses, releases, vulnerabilities, and development practices.