ucast/ucast/service/videoutil.py

28 lines
821 B
Python

from datetime import date
from pathlib import Path
from mutagen import id3
def tag_audio(
audio_path: Path,
title: str,
channel: str,
published: date,
description: str,
cover_path: Path,
):
title_text = f"{published.isoformat()} {title}"
tag = id3.ID3(audio_path)
tag["TPE1"] = id3.TPE1(encoding=3, text=channel) # Artist
tag["TALB"] = id3.TALB(encoding=3, text=channel) # Album
tag["TIT2"] = id3.TIT2(encoding=3, text=title_text) # Title
tag["TDRC"] = id3.TDRC(encoding=3, text=published.isoformat()) # Date
tag["COMM"] = id3.COMM(encoding=3, text=description) # Comment
with open(cover_path, "rb") as albumart:
tag["APIC"] = id3.APIC(
encoding=3, mime="image/png", type=3, desc="Cover", data=albumart.read()
)
tag.save()