解决部分机器上直接调time.strtime会有中文报错的问题 (#272)

* 解决部分机器上直接调time.strtime会有中文报错的问题

* Update download.py
This commit is contained in:
haha114514 authored and GitHub committed 2023-02-02 04:15:02 +11:00
1 parent 9a401ed12f
commit e8cf76ca95
1 file changed
+5 -5
+5 -5
View File
@@ -70,10 +70,10 @@ class DownloadBase:
'-i', self.raw_stream_url, *self.default_output_args, *self.opt_args,
'-c', 'copy', '-f', self.suffix]
if config.get('segment_time'):
args += ['-f', 'segment', f'{time.strftime(filename)} part-%03d.{self.suffix}']
args += ['-f', 'segment', f'{(time.strftime(filename).encode("unicode-escape").decode()).encode().decode("unicode-escape")} part-%03d.{self.suffix}']
else:
args += [f'{time.strftime(filename)}.{self.suffix}.part']
args += [f'{(time.strftime(filename).encode("unicode-escape").decode()).encode().decode("unicode-escape")}.{self.suffix}']
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
try:
with proc.stdout as stdout:
@@ -178,8 +178,8 @@ def get_valid_filename(name):
>>> get_valid_filename("{self.fname}%Y-%m-%dT%H_%M_%S")
'{self.fname}%Y-%m-%dT%H_%M_%S'
"""
#s = str(name).strip().replace(" ", "_") #因为有些人会在主播名中间加入空格,为了避免和录播完毕自动改名冲突,所以注销掉
s = re.sub(r"(?u)[^-\w.%{}\[\]【】「」]", "", s)
#s = str(name).strip().replace(" ", "_") #因为有些人会在主播名中间加入空格,为了避免和录播完毕自动改名冲突,所以注释掉
s = re.sub(r"(?u)[^-\w.%{}\[\]【】「」\s]", "", str(name))
if s in {"", ".", ".."}:
raise RuntimeError("Could not derive file name from '%s'" % name)
return s