mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
warn people when they're gonna have a bad time
This commit is contained in:
parent
9cde2352f3
commit
bb5169710a
|
@ -69,7 +69,9 @@ summary: it works! you can use it! (but technically not even close to beta)
|
||||||
|
|
||||||
# bugs
|
# bugs
|
||||||
|
|
||||||
* probably, pls let me know
|
* 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`
|
||||||
|
* probably more, pls let me know
|
||||||
|
|
||||||
|
|
||||||
# searching
|
# searching
|
||||||
|
|
|
@ -18,7 +18,7 @@ import locale
|
||||||
import argparse
|
import argparse
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
|
||||||
from .__init__ import E, WINDOWS, VT100
|
from .__init__ import E, WINDOWS, VT100, PY2
|
||||||
from .__version__ import S_VERSION, S_BUILD_DT, CODENAME
|
from .__version__ import S_VERSION, S_BUILD_DT, CODENAME
|
||||||
from .svchub import SvcHub
|
from .svchub import SvcHub
|
||||||
from .util import py_desc, align_tab
|
from .util import py_desc, align_tab
|
||||||
|
@ -53,6 +53,10 @@ class RiceFormatter(argparse.HelpFormatter):
|
||||||
return "".join(indent + line + "\n" for line in text.splitlines())
|
return "".join(indent + line + "\n" for line in text.splitlines())
|
||||||
|
|
||||||
|
|
||||||
|
def warn(msg):
|
||||||
|
print("\033[1mwarning:\033[0;33m {}\033[0m\n".format(msg))
|
||||||
|
|
||||||
|
|
||||||
def ensure_locale():
|
def ensure_locale():
|
||||||
for x in [
|
for x in [
|
||||||
"en_US.UTF-8",
|
"en_US.UTF-8",
|
||||||
|
@ -300,7 +304,13 @@ def main():
|
||||||
if al.ciphers:
|
if al.ciphers:
|
||||||
configure_ssl_ciphers(al)
|
configure_ssl_ciphers(al)
|
||||||
else:
|
else:
|
||||||
print("\033[33m ssl module does not exist; cannot enable https\033[0m\n")
|
warn("ssl module does not exist; cannot enable https")
|
||||||
|
|
||||||
|
if PY2 and WINDOWS and al.e2d:
|
||||||
|
warn(
|
||||||
|
"windows py2 cannot do unicode filenames with -e2d\n"
|
||||||
|
+ " (if you crash with codec errors then that is why)"
|
||||||
|
)
|
||||||
|
|
||||||
SvcHub(al).run()
|
SvcHub(al).run()
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ import subprocess as sp
|
||||||
from .__init__ import PY2, WINDOWS
|
from .__init__ import PY2, WINDOWS
|
||||||
from .util import fsenc, fsdec
|
from .util import fsenc, fsdec
|
||||||
|
|
||||||
|
if not PY2:
|
||||||
|
unicode = str
|
||||||
|
|
||||||
|
|
||||||
class MTag(object):
|
class MTag(object):
|
||||||
def __init__(self, log_func, args):
|
def __init__(self, log_func, args):
|
||||||
|
@ -18,6 +21,7 @@ class MTag(object):
|
||||||
self.prefer_mt = False
|
self.prefer_mt = False
|
||||||
mappings = args.mtm
|
mappings = args.mtm
|
||||||
self.backend = "ffprobe" if args.no_mutagen else "mutagen"
|
self.backend = "ffprobe" if args.no_mutagen else "mutagen"
|
||||||
|
or_ffprobe = " or ffprobe"
|
||||||
|
|
||||||
if self.backend == "mutagen":
|
if self.backend == "mutagen":
|
||||||
self.get = self.get_mutagen
|
self.get = self.get_mutagen
|
||||||
|
@ -32,7 +36,7 @@ class MTag(object):
|
||||||
self.prefer_mt = True
|
self.prefer_mt = True
|
||||||
# about 20x slower
|
# about 20x slower
|
||||||
if PY2:
|
if PY2:
|
||||||
cmd = ["ffprobe", "-version"]
|
cmd = [b"ffprobe", b"-version"]
|
||||||
try:
|
try:
|
||||||
sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
||||||
except:
|
except:
|
||||||
|
@ -41,9 +45,15 @@ class MTag(object):
|
||||||
if not shutil.which("ffprobe"):
|
if not shutil.which("ffprobe"):
|
||||||
self.usable = False
|
self.usable = False
|
||||||
|
|
||||||
|
if self.usable and WINDOWS and sys.version_info < (3, 8):
|
||||||
|
self.usable = False
|
||||||
|
or_ffprobe = " or python >= 3.8"
|
||||||
|
msg = "\033[31mfound ffprobe but your python is too old; need 3.8 or newer"
|
||||||
|
self.log(msg)
|
||||||
|
|
||||||
if not self.usable:
|
if not self.usable:
|
||||||
msg = "\033[31mneed mutagen or ffprobe to read media tags so please run this:\n {} -m pip install --user mutagen \033[0m"
|
msg = "\033[31mneed mutagen{} to read media tags so please run this:\n {} -m pip install --user mutagen \033[0m"
|
||||||
self.log(msg.format(os.path.basename(sys.executable)))
|
self.log(msg.format(or_ffprobe, os.path.basename(sys.executable)))
|
||||||
return
|
return
|
||||||
|
|
||||||
# https://picard-docs.musicbrainz.org/downloads/MusicBrainz_Picard_Tag_Map.html
|
# https://picard-docs.musicbrainz.org/downloads/MusicBrainz_Picard_Tag_Map.html
|
||||||
|
@ -206,7 +216,7 @@ class MTag(object):
|
||||||
return self.normalize_tags(ret, md)
|
return self.normalize_tags(ret, md)
|
||||||
|
|
||||||
def get_ffprobe(self, abspath):
|
def get_ffprobe(self, abspath):
|
||||||
cmd = ["ffprobe", "-hide_banner", "--", fsenc(abspath)]
|
cmd = [b"ffprobe", b"-hide_banner", b"--", fsenc(abspath)]
|
||||||
p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
|
||||||
r = p.communicate()
|
r = p.communicate()
|
||||||
txt = r[1].decode("utf-8", "replace")
|
txt = r[1].decode("utf-8", "replace")
|
||||||
|
|
|
@ -64,7 +64,6 @@ class Up2k(object):
|
||||||
self.flags = {}
|
self.flags = {}
|
||||||
self.cur = {}
|
self.cur = {}
|
||||||
self.mtag = None
|
self.mtag = None
|
||||||
self.n_mtag_thr_alive = 0
|
|
||||||
self.n_mtag_tags_added = 0
|
self.n_mtag_tags_added = 0
|
||||||
|
|
||||||
self.mem_cur = None
|
self.mem_cur = None
|
||||||
|
@ -432,12 +431,8 @@ class Up2k(object):
|
||||||
if self.mtag.prefer_mt and not self.args.no_mtag_mt:
|
if self.mtag.prefer_mt and not self.args.no_mtag_mt:
|
||||||
# mp.pool.ThreadPool and concurrent.futures.ThreadPoolExecutor
|
# mp.pool.ThreadPool and concurrent.futures.ThreadPoolExecutor
|
||||||
# both do crazy runahead so lets reinvent another wheel
|
# both do crazy runahead so lets reinvent another wheel
|
||||||
nw = os.cpu_count()
|
nw = os.cpu_count() if hasattr(os, "cpu_count") else 4
|
||||||
if not self.n_mtag_thr_alive:
|
self.log("using {}x {}".format(nw, self.mtag.backend))
|
||||||
msg = 'using {} cores for tag reader "{}"'
|
|
||||||
self.log(msg.format(nw, self.mtag.backend))
|
|
||||||
|
|
||||||
self.n_mtag_thr_alive = nw
|
|
||||||
mpool = Queue(nw)
|
mpool = Queue(nw)
|
||||||
for _ in range(nw):
|
for _ in range(nw):
|
||||||
thr = threading.Thread(target=self._tag_thr, args=(mpool,))
|
thr = threading.Thread(target=self._tag_thr, args=(mpool,))
|
||||||
|
@ -474,11 +469,12 @@ class Up2k(object):
|
||||||
last_write = time.time()
|
last_write = time.time()
|
||||||
n_buf = 0
|
n_buf = 0
|
||||||
|
|
||||||
if self.n_mtag_thr_alive:
|
if mpool:
|
||||||
mpool.join()
|
for _ in range(mpool.maxsize):
|
||||||
for _ in range(self.n_mtag_thr_alive):
|
|
||||||
mpool.put(None)
|
mpool.put(None)
|
||||||
|
|
||||||
|
mpool.join()
|
||||||
|
|
||||||
c3.close()
|
c3.close()
|
||||||
c2.close()
|
c2.close()
|
||||||
|
|
||||||
|
@ -488,7 +484,8 @@ class Up2k(object):
|
||||||
while True:
|
while True:
|
||||||
task = q.get()
|
task = q.get()
|
||||||
if not task:
|
if not task:
|
||||||
break
|
q.task_done()
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
write_cur, entags, wark, abspath = task
|
write_cur, entags, wark, abspath = task
|
||||||
|
@ -497,11 +494,10 @@ class Up2k(object):
|
||||||
n = self._tag_file(write_cur, entags, wark, abspath, tags)
|
n = self._tag_file(write_cur, entags, wark, abspath, tags)
|
||||||
self.n_mtag_tags_added += n
|
self.n_mtag_tags_added += n
|
||||||
except:
|
except:
|
||||||
with self.mutex:
|
msg = "\033[33m{} failed to read tags from {}:\n{}"
|
||||||
self.n_mtag_thr_alive -= 1
|
self.log(msg.format(self.mtag.backend, abspath, traceback.format_exc()))
|
||||||
raise
|
|
||||||
finally:
|
q.task_done()
|
||||||
q.task_done()
|
|
||||||
|
|
||||||
def _tag_file(self, write_cur, entags, wark, abspath, tags=None):
|
def _tag_file(self, write_cur, entags, wark, abspath, tags=None):
|
||||||
tags = tags or self.mtag.get(abspath)
|
tags = tags or self.mtag.get(abspath)
|
||||||
|
@ -919,7 +915,7 @@ class Up2k(object):
|
||||||
ret = []
|
ret = []
|
||||||
with open(path, "rb", 512 * 1024) as f:
|
with open(path, "rb", 512 * 1024) as f:
|
||||||
while fsz > 0:
|
while fsz > 0:
|
||||||
self.pp.msg = "{} MB".format(int(fsz / 1024 / 1024))
|
self.pp.msg = "{} MB, {}".format(int(fsz / 1024 / 1024), path)
|
||||||
hashobj = hashlib.sha512()
|
hashobj = hashlib.sha512()
|
||||||
rem = min(csz, fsz)
|
rem = min(csz, fsz)
|
||||||
fsz -= rem
|
fsz -= rem
|
||||||
|
|
Loading…
Reference in a new issue