From aa4f352301995af9af504672298e324611225735 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 22 Jun 2021 17:21:24 +0200 Subject: [PATCH] prefer audio tags in audio files --- copyparty/mtag.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/copyparty/mtag.py b/copyparty/mtag.py index f76a17eb..aa8f6826 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -115,6 +115,19 @@ def parse_ffprobe(txt): ret = {} # processed md = {} # raw tags + is_audio = fmt.get("format_name") in ["mp3", "ogg", "flac", "wav"] + if fmt.get("filename", "").split(".")[-1].lower() in ["m4a", "aac"]: + is_audio = True + + # if audio file, ensure audio stream appears first + if ( + is_audio + and len(streams) > 2 + and streams[1].get("codec_type") != "audio" + and streams[2].get("codec_type") == "audio" + ): + streams = [fmt, streams[2], streams[1]] + streams[3:] + have = {} for strm in streams: typ = strm.get("codec_type") @@ -134,9 +147,7 @@ def parse_ffprobe(txt): ] if typ == "video": - if strm.get("DISPOSITION:attached_pic") == "1" or fmt.get( - "format_name" - ) in ["mp3", "ogg", "flac"]: + if strm.get("DISPOSITION:attached_pic") == "1" or is_audio: continue kvm = [ @@ -180,7 +191,7 @@ def parse_ffprobe(txt): k = k[4:].strip() v = v.strip() - if k and v: + if k and v and k not in md: md[k] = [v] for k in [".q", ".vq", ".aq"]: