From 07ea629ca5cc2ffc28349efab2cfd17a4011a0a2 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 30 May 2024 23:46:56 +0000 Subject: [PATCH] keep most tags during audio transcode metadata is no longer discarded when transcoding to opus or mp3; this was a good idea back when the transcodes were only used by the webplayer, but now that folders can be batch-downloaded with on-the-fly transcoding, it makes sense to keep most of the tags individual tags are discarded if its value exceeds 1023 letters this should mainly affect the following: * traktor beatmaps, size usually somewhere around 100 KiB * non-standard cover-art embeddings, size around 250 KiB * XMP (project data from adobe premiere), around 48 KiB --- copyparty/th_srv.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index c35010bb..3f49497d 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -673,8 +673,8 @@ class ThumbSrv(object): raise Exception("disabled in server config") self.wait4ram(0.2, tpath) - ret, _ = ffprobe(abspath, int(vn.flags["convt"] / 2)) - if "ac" not in ret: + tags, rawtags = ffprobe(abspath, int(vn.flags["convt"] / 2)) + if "ac" not in tags: raise Exception("not audio") if quality.endswith("k"): @@ -695,7 +695,7 @@ class ThumbSrv(object): b"-v", b"error", b"-hide_banner", b"-i", fsenc(abspath), - b"-map_metadata", b"-1", + ] + self.big_tags(rawtags) + [ b"-map", b"0:a:0", b"-ar", b"44100", b"-ac", b"2", @@ -711,16 +711,16 @@ class ThumbSrv(object): raise Exception("disabled in server config") self.wait4ram(0.2, tpath) - ret, _ = ffprobe(abspath, int(vn.flags["convt"] / 2)) - if "ac" not in ret: + tags, rawtags = ffprobe(abspath, int(vn.flags["convt"] / 2)) + if "ac" not in tags: raise Exception("not audio") try: - dur = ret[".dur"][1] + dur = tags[".dur"][1] except: dur = 0 - src_opus = abspath.lower().endswith(".opus") or ret["ac"][1] == "opus" + src_opus = abspath.lower().endswith(".opus") or tags["ac"][1] == "opus" want_caf = tpath.endswith(".caf") tmp_opus = tpath if want_caf: @@ -741,7 +741,7 @@ class ThumbSrv(object): b"-v", b"error", b"-hide_banner", b"-i", fsenc(abspath), - b"-map_metadata", b"-1", + ] + self.big_tags(rawtags) + [ b"-map", b"0:a:0", b"-c:a", b"libopus", b"-b:a", bq, @@ -798,6 +798,16 @@ class ThumbSrv(object): except: pass + def big_tags(self, raw_tags: dict[str, list[str]]) -> list[bytes]: + ret = [] + for k, vs in raw_tags.items(): + for v in vs: + if len(str(v)) >= 1024: + bv = (k + "=").encode("utf-8", "replace") + ret += [b"-metadata", bv] + break + return ret + def poke(self, tdir: str) -> None: if not self.poke_cd.poke(tdir): return