Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]base_downloader会将报错未下载完成的tmp文件依然改名为mp4 无法完整播放 #271

Open
dueuege opened this issue Feb 11, 2025 · 2 comments
Labels
故障(bug) 代码问题导致的错误(Bugs caused by code problems)

Comments

@dueuege
Copy link

dueuege commented Feb 11, 2025

详细描述错误
在运行douyin下载时 由于人在国外网络不好 经常下载报错 但是tmp文件依然会被改名为mp4
导致打开无法完整播放

系统平台
win11
Q:你在哪个平台(Win/Linux/Mac)上运行?你使用的是什么浏览器?你使用的是什么终端软件?你使用的F2是什么版本?
F2 0.0.1.7 pip公共版本和自己编译版本都会发生

我自己fork了之后通过仅修改base_downloader.py可以规避 但是解决的很粗糙

@dueuege dueuege added the 故障(bug) 代码问题导致的错误(Bugs caused by code problems) label Feb 11, 2025
Copy link

dosubot bot commented Feb 11, 2025

@dueuege 你好!我是一个能够帮助你解决 bug、回答问题并成为贡献者的机器人。很高兴能够在等待人类维护者的时候帮助到你。

To prevent the renaming of incomplete .tmp files to .mp4, you can modify the base_downloader.py to ensure that the file size is checked before renaming. The logic should verify that the actual size of the downloaded file matches the expected content length. If they do not match, the file should not be renamed. Here's a code snippet that demonstrates this approach:

# Check if the file size matches
actual_size = tmp_path.stat().st_size
if actual_size != content_length:
    logger.warning(
        _("文件大小不匹配 - 预期: {0} 字节, 实际: {1} 字节").format(
            content_length, actual_size
        )
    )
    await self.progress.update(
        task_id,
        description=_("[yellow][  警告  ]:[/yellow]"),
        filename=trim_filename(full_path.name, 45),
        state="warning",
    )
    continue  # 保留.tmp后缀,尝试下一个链接

This code ensures that only fully downloaded files are renamed, preventing incomplete downloads from being mistakenly treated as complete [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dueuege
Copy link
Author

dueuege commented Feb 16, 2025

#271 (comment)

dosubot comment 是 0.0.1.7 之后 0.0.1.8 增加的 尽管continue了没下完的tmp还是会被改名

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
故障(bug) 代码问题导致的错误(Bugs caused by code problems)
Projects
None yet
Development

No branches or pull requests

1 participant