TGViewer
[PYTHON:TODAY] [PYTHON:TODAY] @python2day · 63.6K subscribers
Post #6166 16.4K
😱 Скачиваем аудио с YouTube с помощью Python!

Хватит искать конвертеры, Python сделает всё сам. С помощью pytube и moviepy можно вытянуть аудиодорожку из любого YouTube-видео и сохранить её в формате MP3.

Установка необходимых библиотек:

$ pip install pytube moviepy


💡 Код:

import os
import pytube
from moviepy.editor import AudioFileClip

def download_youtube_audio(youtube_url: str, output_folder: str = ".", output_filename: str = "audio.mp3") -> str:
"""
Скачивает аудио с YouTube и сохраняет в MP3.

:param youtube_url: Ссылка на YouTube-видео.
:param output_folder: Папка для сохранения MP3-файла.
:param output_filename: Имя MP3-файла.
:return: Путь к сохранённому файлу.
"""
print("🔄 Загружаем аудио с YouTube...")

# Получаем аудиопоток
yt = pytube.YouTube(youtube_url)
audio_stream = yt.streams.filter(only_audio=True).first()

# Скачиваем временный файл
temp_file = audio_stream.download(output_path=output_folder)

# Преобразуем в MP3
audio_clip = AudioFileClip(temp_file)
mp3_file = os.path.join(output_folder, output_filename)
audio_clip.write_audiofile(mp3_file)

# Удаляем временный файл
os.remove(temp_file)

print(f"✅ Аудио успешно сохранено: {mp3_file}")
return mp3_file

if name == "main":
youtube_url = input("Введите ссылку на YouTube-видео: ").strip()
output_folder = input("Введите папку для сохранения (Enter для текущей): ").strip() or "."
output_filename = input("Введите имя файла (Enter для 'audio.mp3'): ").strip() or "audio.mp3"

download_youtube_audio(youtube_url, output_folder, output_filename)


👨‍💻 Скачивай музыку, подкасты и лекции с YouTube проще простого!

📂 Сохраняй, пригодится!

#python #soft #code
  • 👍 109
  • 🔥 25
  • ❤ 12
  • 🫡 4
  • 🤯 3
More from @python2day
  1. Oct 16, 2026⌨️ Нейросеть теперь может работать за целый SMM-отдел — сохраняйте 17 готовых навыков для…
  2. Oct 16, 2026Хочешь листать мемы, а лид заставляет работать? Теперь можно не отвлекаться на глупые таск…
  3. Oct 16, 2026😄 И ведь пока даже не запустил ничего С добрым утром! 😎
  4. Oct 14, 2026⚡️ Нейросеть теперь сама рисует обучающие видео, озвучивает их и монтирует — достаточно од…
  5. Oct 14, 2026🫡 Сколько стоила крипта 10 лет назад
  6. Oct 14, 2026😎 Хз к чему этот чувак готовится, но он готов С добрым утром! 😎
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →