Skip to content

Instantly share code, notes, and snippets.

@acheong08
Created July 20, 2023 07:41
Show Gist options
  • Save acheong08/61c34adf507e7e5cdcc5cae83d89c8d4 to your computer and use it in GitHub Desktop.
Save acheong08/61c34adf507e7e5cdcc5cae83d89c8d4 to your computer and use it in GitHub Desktop.
from yt_dlp import YoutubeDL
from mutagen.easymp4 import EasyMP4
import os
ydl = YoutubeDL()
# List files
files = os.listdir()
# Filter out non-m4a files
files = [f for f in files if f.endswith(".m4a")]
for file in files:
yt_id = file.split(".")[0]
# Get metadata
info = ydl.extract_info(yt_id, download=False)
m4a = EasyMP4(file)
m4a["title"] = info.get("title")
m4a["artist"] = (
info.get("uploader") or info.get("channel") or info.get("uploader_id")
)
m4a.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment