From df64a62a03be94c9adae0b875b6d4b106c5cb77f Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 18 Sep 2022 15:09:41 +0200 Subject: [PATCH] patch popen on windows-python <3.8 --- README.md | 1 - copyparty/mtag.py | 11 +---------- copyparty/util.py | 11 +++++++++++ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 73e1a542..99a17780 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,6 @@ some improvement ideas # bugs -* Windows: python 3.7 and older cannot read tags with FFprobe, so use Mutagen or upgrade * Windows: python 2.7 cannot index non-ascii filenames with `-e2d` * Windows: python 2.7 cannot handle filenames with mojibake * `--th-ff-jpg` may fix video thumbnails on some FFmpeg versions (macos, some linux) diff --git a/copyparty/mtag.py b/copyparty/mtag.py index 7ca0ce5a..61176127 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -262,11 +262,7 @@ class MTag(object): self.usable = True self.prefer_mt = not args.no_mtag_ff self.backend = "ffprobe" if args.no_mutagen else "mutagen" - self.can_ffprobe = ( - HAVE_FFPROBE - and not args.no_mtag_ff - and (not WINDOWS or sys.version_info >= (3, 8)) - ) + self.can_ffprobe = HAVE_FFPROBE and not args.no_mtag_ff mappings = args.mtm or_ffprobe = " or FFprobe" @@ -290,11 +286,6 @@ class MTag(object): msg = "found FFprobe but it was disabled by --no-mtag-ff" self.log(msg, c=3) - elif WINDOWS and sys.version_info < (3, 8): - or_ffprobe = " or python >= 3.8" - msg = "found FFprobe but your python is too old; need 3.8 or newer" - self.log(msg, c=1) - if not self.usable: msg = "need Mutagen{} to read media tags so please run this:\n{}{} -m pip install --user mutagen\n" pybin = os.path.basename(sys.executable) diff --git a/copyparty/util.py b/copyparty/util.py index 02c5b4ae..01b15475 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -625,6 +625,17 @@ class HMaccas(object): return self.b(msg.encode("utf-8", "replace")) +if WINDOWS and sys.version_info < (3, 8): + _popen = sp.Popen + + def _spopen(c, *a, **ka): + enc = sys.getfilesystemencoding() + c = [x.decode(enc, "replace") if hasattr(x, "decode") else x for x in c] + return _popen(c, *a, **ka) + + sp.Popen = _spopen + + def uprint(msg: str) -> None: try: print(msg, end="")