Added MP4 audio embeds for Discord in AudioEmbed.py

This commit is contained in:
sarah committed 2026-10-14 19:47:54 +02:00
1 parent 2d5ab15f52
commit d778be91cd
4 files changed
+174 -8

No files matched your search

+17 -8
View File
@@ -6,6 +6,7 @@ import re
from pathlib import Path
from urllib.parse import quote
import AudioEmbed
from Core import ResolvePath
from Explorer import ClassifyFile, GetDirectoryNoteInfo
from Groups import GuestGroupName
@@ -91,17 +92,25 @@ def BuildOgTags(RootName: str, RelativePath: str, IsDirectoryUrl: bool, BaseUrl:
Tags.append(_MetaTag("og:video:type", GetMimeType(EntryPath)))
Tags.append(_MetaTag("og:description", DefaultDescriptions["video"]))
elif FileType == "audio":
# og:audio is the standard tag, but Discord doesn't play it. Discord
# does play og:video in an HTML5 player, which handles audio-only
# files too, so the audio is offered as both.
Tags.append(_MetaTag("og:type", "video.other"))
# og:audio is the standard tag, but Discord ignores it (and an
# og:video pointing at audio). It does play an MP4, so the audio is
# also offered as one: a still picture with the track (AudioEmbed.py).
Tags.append(_MetaTag("og:audio", MediaUrl))
Tags.append(_MetaTag("og:audio:secure_url", MediaUrl))
Tags.append(_MetaTag("og:audio:type", GetMimeType(EntryPath)))
Tags.append(_MetaTag("og:video", MediaUrl))
Tags.append(_MetaTag("og:video:url", MediaUrl))
Tags.append(_MetaTag("og:video:secure_url", MediaUrl))
Tags.append(_MetaTag("og:video:type", GetMimeType(EntryPath)))
if AudioEmbed.IsAvailable():
AudioEmbed.PrepareInBackground(EntryPath)
VideoUrl = f"{BaseUrl}/public/embed/{quote(RootName)}/{EncodedPath}"
Tags.append(_MetaTag("og:type", "video.other"))
Tags.append(_MetaTag("og:video", VideoUrl))
Tags.append(_MetaTag("og:video:url", VideoUrl))
Tags.append(_MetaTag("og:video:secure_url", VideoUrl))
Tags.append(_MetaTag("og:video:type", "video/mp4"))
Tags.append(_MetaTag("og:video:width", str(AudioEmbed.FrameSize)))
Tags.append(_MetaTag("og:video:height", str(AudioEmbed.FrameSize)))
Tags.append(_MetaTag("og:image", f"{BaseUrl}/Icons/Icon.png"))
else:
Tags.append(_MetaTag("og:type", "music.song"))
Tags.append(_MetaTag("og:description", DefaultDescriptions["audio"]))
elif FileType == "image":
Tags.append(_MetaTag("og:type", "website"))