Add youtube info download

This commit is contained in:
Leonardo Segala 2025-08-01 21:21:24 +02:00
parent 3a81b332ba
commit a2ae91be13

View file

@ -21,9 +21,7 @@ def lastfm_search(query: str) -> tuple[str, str]:
return track_info["name"], track_info["artist"] return track_info["name"], track_info["artist"]
def lastfm_getinfo( def lastfm_getinfo(name: str, artist: str) -> tuple[str, str, str, str, list[str]]: # ( id, image_id, tags )
name: str, artist: str
) -> tuple[str, str, str, str, list[str]]: # ( id, image_id, tags )
response = requests.get( response = requests.get(
url="https://ws.audioscrobbler.com/2.0/?method=track.getInfo&format=json", url="https://ws.audioscrobbler.com/2.0/?method=track.getInfo&format=json",
params={ params={
@ -44,20 +42,23 @@ def lastfm_getinfo(
) )
print(yt_dlp, flush=True) def download_song_mp3(name: str, artist: str) -> tuple[str, str] | None: # ( id, audio )
ydl_opts = {
"format": "bestaudio",
"default_search": "ytsearch1",
"outtmpl": "%(title)s.%(ext)s",
"skip_download": True,
}
# # def get_yt_mp3link(name: str, artist: str) -> str: ... with yt_dlp.YoutubeDL(ydl_opts) as ydl:
# # os.popen("/yt-dlp ") info = ydl.extract_info(f"{name!r} - {artist!r}", download=False)
# # /yt-dlp/yt-dlp.sh "ytsearch1:Never gonna give you up" --get-url -f "ba" first_entry = info["entries"][0]
# import json video_id = first_entry["id"]
# print(json.dumps(lastfm_getinfo(*lastfm_search("money")), indent=2)) for fmt in first_entry["formats"]:
# exit(1) if "acodec" in fmt and fmt["acodec"] != "none":
return video_id, fmt["url"]
return None
# # def
# ## query ==> lastfm ==> list of songs ==> take first ==> request song info ==> get YT link ==> save in DB ==>