logo
0
0
WeChat Login

GoFile Downloader CLI

基于 GoFileDownloader 重构的精简命令行版本,移除了 Rich 富文本依赖,新增 Cloudflare Workers 代理支持。

与原项目的区别

特性原项目本项目
依赖requests + rich仅 requests
UIRich 富文本实时面板简洁命令行输出
代理不支持--proxy 支持 Cloudflare Workers
文件结构多模块(8+ 文件)单包
批量下载URLs.txt 文件暂不支持
进度条Rich 复杂面板终端 █░ 进度条
安装方式克隆仓库pip install gofile-dl-proxy

安装

通过 pip 安装(推荐)

pip install gofile-dl-proxy

安装后即可全局使用 gofile-dl 命令:

gofile-dl https://gofile.io/d/xxxxx

通过 pipx 安装(隔离环境)

pipx install gofile-dl-proxy

从源码安装

git clone https://github.com/Lysagxra/GoFileDownloader.git
cd GoFileDownloader
pip install .

直接运行(无需安装)

apt install -y python3 python3-pip && pip install requests && python3 gofile_dl/cli.py https://gofile.io/d/xxxxx --proxy https://c.map987.dpdns.org/ -o ./output -w 16

或:

apt install -y python3 python3-pip && pip install requests && python -m gofile_dl https://gofile.io/d/xxxxx --proxy https://c.map987.dpdns.org/ -o ./output -w 16

Docker 使用

拉取并运行,参数与 pip 安装版完全一致,通过 -v 挂载目录保存文件:

docker pull docker.cnb.cool/kfc50/kemono-downloader-and-gofile-downloadef:latest && docker run --rm -v $(pwd)/output:/app/output docker.cnb.cool/kfc50/kemono-downloader-and-gofile-downloadef:latest https://gofile.io/d/xxxxx --proxy https://c.map987.dpdns.org/ -o /app/output -w 16

注意-v 将宿主机目录挂载到容器内,-o 参数需指向容器内的挂载路径(如 /app/output),下载的文件才会保存到宿主机。

构建并推送镜像(开发者)

docker build -t docker.cnb.cool/kfc50/kemono-downloader-and-gofile-downloadef:latest .
docker push docker.cnb.cool/kfc50/kemono-downloader-and-gofile-downloadef:latest

使用方法

gofile-dl https://gofile.io/d/xxxxx --proxy https://c.map987.dpdns.org/ -o ./output -w 16

全部参数

positional arguments:
  url                     GoFile URL (e.g. https://gofile.io/d/xxxxx)

options:
  -h, --help              show help message and exit
  --password PASSWORD, -p PASSWORD
                          密码保护的相册密码
  --output OUTPUT, -o OUTPUT
                          保存目录 (默认: ./Downloads)
  --proxy PROXY           Cloudflare Workers 代理 URL 前缀
  --workers WORKERS, -w WORKERS
                          并发下载线程数 (默认: 3)
  --sequential            顺序下载(默认并发下载)
  --version, -V           显示版本号

代理使用说明

GoFile 在国内时常无法连接,可通过 Cloudflare Workers 反代解决。

--proxy 参数会将代理 URL 前缀拼接到所有 GoFile 请求前:

原始请求:  https://api.gofile.io/accounts
代理请求:  https://c.map987.dpdns.org/https://api.gofile.io/accounts

代理会应用于所有三个阶段的请求(见下方下载流程)。

断点续传

如果下载中断,再次运行相同命令即可自动续传。脚本会:

  • 检测已下载的部分文件大小
  • 使用 HTTP Range 请求从断点继续下载
  • 如果下载链接过期,自动刷新后重试
  • 最多重试 20 次

下载流程

本项目全程走 GoFile API,无 HTML 页面抓取。流程如下:

第1步:创建访客账户

POST https://api.gofile.io/accounts
→ 获取 accountToken

无需注册,GoFile 会自动创建一个临时访客账户,返回的 token 用于后续所有请求的认证。

第2步:生成 X-Website-Token

基于 accountToken + 当前时间窗口,通过 SHA-256 计算生成
→ 获取 X-Website-Token(动态校验令牌)

这是 GoFile 的反爬机制,每 4 小时(14400 秒)变化一次。

第3步:获取文件列表

GET https://api.gofile.io/contents/{contentId}?cache=true&sortField=createTime&sortDirection=1
Headers:
  Authorization: Bearer {accountToken}
  X-Website-Token: {websiteToken}
  Cookie: accountToken={accountToken}
→ 获取文件名、下载链接、文件夹结构
  • contentId 从 URL 中提取,如 https://gofile.io/d/5tkZZi5tkZZi
  • 支持递归遍历子文件夹
  • 密码保护的相册需传入 SHA-256 哈希后的密码

第4步:下载文件

GET {download_link}(如 https://store1.gofile.io/download/...)
Headers:
  Cookie: accountToken={accountToken}
  Referer: {下载链接的源站}
→ 流式写入本地文件
  • 默认 3 线程并发下载(可通过 -w 调整)
  • 已存在的完整文件自动跳过
  • 支持断点续传(HTTP Range)
  • 连接失败自动刷新下载链接并重试

代理在流程中的应用

当使用 --proxy https://c.map987.dpdns.org/ 时:

步骤原始 URL代理后 URL
创建账户https://api.gofile.io/accountshttps://c.map987.dpdns.org/https://api.gofile.io/accounts
获取文件列表https://api.gofile.io/contents/xxxhttps://c.map987.dpdns.org/https://api.gofile.io/contents/xxx
下载文件https://store1.gofile.io/download/...https://c.map987.dpdns.org/https://store1.gofile.io/download/...

开发与发布流程

本项目使用双远程仓库策略:CNB(主仓库,含大文件)和 GitHub(发布仓库,仅源码)。主分支开发完成后,同步指定文件到 GitHub 发布分支,通过 GitHub Actions 自动发布到 PyPI。

仓库结构

远程地址分支用途
origin (CNB)https://cnb.cool/kfc50/kemono-downloader-and-gofile-downloadef.gitmain主开发仓库,含大文件
githubhttps://github.com/Map9876/gofile-downloader-with-proxy.gitgithub-publish-clean发布仓库,仅源码

一次性配置

CNB 环境重启后只有 CNB 远程仓库,每次需要重新添加 GitHub remote:

# 1. 添加 GitHub 远程(从 PYPI_CREDENTIALS.md 获取 token)
git remote add github https://Map9876:<GITHUB_TOKEN>@github.com/Map9876/gofile-downloader-with-proxy.git

# 2. 拉取 GitHub 发布分支
git fetch github github-publish-clean

# 3. 切换到发布分支(首次用 orphan 方式,后续直接 checkout)
git checkout github-publish-clean

日常开发流程

1. 在 main 分支开发

git checkout main
# 正常开发、提交...
git add .
git commit -m "feat: xxx"
git push origin main

2. 同步到 GitHub 发布分支

只同步指定文件(避免泄露大文件、密钥、真实代理 URL 等):

# 切换到发布分支
git checkout github-publish-clean

# 从 main 分支检出需要同步的文件(按需选择)
git checkout main -- gofile_dl/ pyproject.toml README.md requirements.txt

# 注意:以下文件不要从 main 同步!
# - gofile_dl.py(旧版单文件,发布分支不需要)
# - PYPI_CREDENTIALS.md(密钥)
# - 5tkZZi/ 等大文件目录
# - 包含真实代理 URL 的文件(发布分支使用占位符 https://your-worker.example.com/)

3. 提交到发布分支(隐藏真实身份)

发布分支的 commit 必须使用 GitHub noreply 邮箱,避免暴露 CNB 账号信息:

GIT_AUTHOR_NAME="Map9876" \
GIT_AUTHOR_EMAIL="Map9876@users.noreply.github.com" \
GIT_COMMITTER_NAME="Map9876" \
GIT_COMMITTER_EMAIL="Map9876@users.noreply.github.com" \
git -c commit.gpgsign=false add .
GIT_AUTHOR_NAME="Map9876" \
GIT_AUTHOR_EMAIL="Map9876@users.noreply.github.com" \
GIT_COMMITTER_NAME="Map9876" \
GIT_COMMITTER_EMAIL="Map9876@users.noreply.github.com" \
git -c commit.gpgsign=false commit -m "v1.0.2"

# 推送到 GitHub
git push github github-publish-clean

4. 打 tag 并创建 Release 触发发布

# 打 tag(同样用 noreply 身份)
GIT_AUTHOR_NAME="Map9876" \
GIT_AUTHOR_EMAIL="Map9876@users.noreply.github.com" \
GIT_COMMITTER_NAME="Map9876" \
GIT_COMMITTER_EMAIL="Map9876@users.noreply.github.com" \
git -c commit.gpgsign=false tag v1.0.2

git push github v1.0.2

# 通过 GitHub API 创建 Release(触发 Actions)
curl -X POST \
  -H "Authorization: token <GITHUB_TOKEN>" \
  -H "Accept: application/vnd.github+json" \
  https://api.github.com/repos/Map9876/gofile-downloader-with-proxy/releases \
  -d '{"tag_name":"v1.0.2","target_commitish":"github-publish-clean","name":"v1.0.2","body":"Release v1.0.2","draft":false,"prerelease":false}'

也可以在 GitHub 网页上手动创建 Release。

5. 切回 main 继续开发

git checkout main

发布分支的文件规则

包含gofile_dl/pyproject.tomlREADME.mdrequirements.txt.github/.gitignore.gitattributes

排除

  • 5tkZZi/ 等大文件目录
  • PYPI_CREDENTIALS.md(含密钥)
  • gofile_dl.py(旧版单文件)
  • dist/__pycache__/*.egg-info/*.log
  • 真实代理 URL(使用 https://your-worker.example.com/ 替代)

GitHub Secrets 配置

在仓库 Settings → Secrets and variables → Actions 中添加:

  • PYPI_API_TOKEN:PyPI API Token(以 pypi- 开头)

手动发布(不用 GitHub Actions)

pip install build twine
python -m build
twine upload dist/*
# 用户名: __token__
# 密码: PyPI API Token

CNB 重启后的恢复步骤

CNB 环境重启后,只有 origin (CNB) 远程,需要重新配置:

# 1. 添加 GitHub remote
git remote add github https://Map9876:<GITHUB_TOKEN>@github.com/Map9876/gofile-downloader-with-proxy.git

# 2. 拉取 GitHub 分支
git fetch github

# 3. 恢复本地发布分支
git checkout -b github-publish-clean github/github-publish-clean

致谢

About

https://github.com/KarlcxChina/KemonoDownloader https://github.com/Lysagxra/GoFileDownloader

Language
Vue38.2%
JavaScript37.4%
Kotlin9.3%
Python7.8%
Others7.3%