better-ffmpeg-progress icon indicating copy to clipboard operation
better-ffmpeg-progress copied to clipboard

_should_overwrite函数逻辑是不是有问题

Open wangxiaobo007 opened this issue 1 year ago • 2 comments

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

wangxiaobo007 avatar Nov 14 '23 02:11 wangxiaobo007

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外面

AIWizardrySass avatar Nov 28 '23 03:11 AIWizardrySass

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 就好

F-park avatar Dec 02 '23 12:12 F-park