better-ffmpeg-progress
better-ffmpeg-progress copied to clipboard
_should_overwrite函数逻辑是不是有问题
def _should_overwrite(self):
dirname = os.path.dirname(self._output_filepath)
self._dir_files = (
[file for file in os.listdir(dirname)] if dirname else [file for file in os.listdir()]
)
if "-y" not in self._ffmpeg_args and self._output_filepath in self._dir_files:
choice = input(f"{self._output_filepath} already exists. Overwrite? [Y/N]: ").lower()
if choice != "y":
print(
"FFmpeg will not run as the output filename already exists, and you do not want it to be overwritten."
)
return False
self._ffmpeg_args.insert(1, "-y")
return True
以上是源码,有可能返回None
def _should_overwrite(self):
dirname = os.path.dirname(self._output_filepath)
self._dir_files = (
[file for file in os.listdir(dirname)] if dirname else [file for file in os.listdir()]
)
if "-y" not in self._ffmpeg_args and self._output_filepath in self._dir_files:
choice = input(f"{self._output_filepath} already exists. Overwrite? [Y/N]: ").lower()
if choice != "y":
print(
"FFmpeg will not run as the output filename already exists, and you do not want it to be overwritten."
)
return False
self._ffmpeg_args.insert(1, "-y")
return True
这个return Ture应该是在if外面
def _should_overwrite(self):
if "-y" not in self._ffmpeg_args and Path(self._output_filepath).exists():
choice = input(
f"{self._output_filepath} already exists. Overwrite? [Y/N]: "
)
if choice.lower() != "y":
print(
"FFmpeg will not run as the output filename already exists, and you do not want it to be overwritten."
)
return False
self._ffmpeg_args.insert(1, "-y")
return True
前面的判断可以简化,只有不选 Y 时返回 False,其他情况都返回 True 就好