-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp3BszV2.py
57 lines (50 loc) · 1.65 KB
/
mp3BszV2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import yt_dlp
from pydub import AudioSegment
def print_banner():
banner = """
Mp3BszV3 / @AvaStrOficial
▶︎ •၊၊||၊|။||||။၊|• 11:11
/ Descarga Musica De Un Solo Url
/ Escribe salir si ya no deceas usar la herramienta
"""
print(banner)
def download_video_from_youtube(link, output_path="downloads"):
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': os.path.join(output_path, '%(title)s.%(ext)s'),
'noplaylist': True,
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
result = ydl.extract_info(link, download=True)
filename = ydl.prepare_filename(result)
print(f"Downloaded video: {filename}")
return filename
except Exception as e:
print(f"Failed to download {link}: {e}")
return None
def convert_to_mp3(file_path):
try:
base, ext = os.path.splitext(file_path)
new_file = base + '.mp3'
audio = AudioSegment.from_file(file_path)
audio.export(new_file, format="mp3")
os.remove(file_path)
print(f"Converted to MP3: {new_file}")
except Exception as e:
print(f"Failed to convert {file_path}: {e}")
def main():
print_banner()
output_path = "downloads"
if not os.path.exists(output_path):
os.makedirs(output_path)
while True:
link = input("Ingrese la URL de la música de YouTube : ")
if link.lower() == 'salir':
break
mp4_file = download_video_from_youtube(link, output_path)
if mp4_file:
convert_to_mp3(mp4_file)
if __name__ == "__main__":
main()