Skip to main content

acfunsdk - UNOFFICEICAL



acfunsdk是 非官方的 AcFun弹幕视频网 Python库。

声明:acfunsdk是python的学习工具,并未破解任何acfun相关内容。代码完全公开,仅用于交流学习。 如涉及版权等相关问题,请遵守acfun相关协议及法律法规。如有bug或其他疑问,欢迎发布issues


Python : Python>=3.10, 本体请自行下载安装

从PyPI安装

python -m pip install acfunsdk

从源码开发(uv

uv sync --all-groups
uv run pytest
uv build

根目录 .python-version 固定为 3.10uv 会按此创建/同步 .venv(可用 uv python install 3.10 安装解释器)。

测试(依赖外网;访客用例中的 URL 与 examples/acer_demo.py 对齐,列表仅在 tests/demo_urls.py 供 parametrize 使用):

# 仅访客 / 公开 URL(适合 CI)
uv run pytest -m "not requires_cookies"
# 全量(需已配置登录 Cookie,见下)
uv run pytest

AcSource 地址探测tests/test_source_urls.py,标记 integration + source_urls):对 acfunsdk/source.pyAcSourceroutes / apis / app_apis / domains、静态资源 URL 及 websocket_links 做可达性检查(HTTP 优先 HEAD、必要时 GET;WSS 做 TLS 握手)。需稳定外网;部分 CDN 在简单探测下会返回 502,用例会记为 xfail 而不导致套件失败。

# 只跑 AcSource 探测(约 200+ 条 HTTP + 若干 WSS)
uv run pytest tests/test_source_urls.py -m integration
# 或按 pytest 标记筛选
uv run pytest -m source_urls

# 查看通过 / xfail 等摘要(含 xfail 原因)
uv run pytest tests/test_source_urls.py -m integration -ra --tb=no -q

# 无网络 CI:跳过本文件全部用例
set ACFUNSDK_SKIP_SOURCE_URLS=1
uv run pytest tests/test_source_urls.py -m integration
# (Linux / macOS)export ACFUNSDK_SKIP_SOURCE_URLS=1

# 单次请求超时(秒,默认 20)
set ACFUNSDK_SOURCE_URL_TIMEOUT=30
uv run pytest tests/test_source_urls.py -m integration

登录相关用例需环境变量 ACFUNSDK_TEST_LOADING(与 Acer(loading=...) 一致,且对应文件名 <该字符串>.cookies)。默认在 tests/ 目录下查找 Cookie,可通过 ACFUNSDK_TEST_COOKIE_DIR 指定目录。

示例脚本(仓库根目录执行):

python examples/acer_demo.py

相关组件


使用方法

实例化获取对象

from acfunsdk import Acer
# 实例化一个Acer
acer = Acer()
# 登录用户(成功登录后会自动保存 '<用户名>.cookies')
# 请注意保存,防止被盗
acer.login(username='you@email.com', password='balalabalala')
# 读取用户(读取成功登录后保存的 '<用户名>.cookies')
acer.loading(username='13800138000')
# 每日签到,领香蕉🍌
acer.signin()
# 通过链接直接获取内容对象
# 目前支持 9种内容类型:
# 视  频: https://www.acfun.cn/v/ac4741185
demo_video = acer.get("https://www.acfun.cn/v/ac4741185")
print(demo_video)
# 文  章: https://www.acfun.cn/a/ac37416587
demo_article = acer.get("https://www.acfun.cn/a/ac37416587")
print(demo_article)
# 合  集: https://www.acfun.cn/a/aa6001205
demo_album = acer.get("https://www.acfun.cn/a/aa6001205")
print(demo_album)
# 番  剧: https://www.acfun.cn/bangumi/aa5023295
demo_bangumi = acer.get("https://www.acfun.cn/bangumi/aa5023295")
print(demo_bangumi)
# 个人页: https://www.acfun.cn/u/39088
demo_up = acer.get("https://www.acfun.cn/u/39088")
print(demo_up)
# 动  态: https://www.acfun.cn/moment/am2797962
demo_moment = acer.get("https://www.acfun.cn/moment/am2797962")
print(demo_moment)
# 直  播: https://live.acfun.cn/live/378269
demo_live = acer.get("https://live.acfun.cn/live/378269")
print(demo_live)
# 分  享: https://m.acfun.cn/v/?ac=37086357
demo_share = acer.get("https://m.acfun.cn/v/?ac=37086357")
print(demo_share)
# 涂鸦(单页): https://hd.acfun.cn/doodle/knNWmnco.html
demo_doodle = acer.get("https://hd.acfun.cn/doodle/knNWmnco.html")
print(demo_doodle)

异步使用

import asyncio
from acfunsdk import Acer

async def main():
    acer = Acer()
    # 异步获取内容对象
    demo_video = await acer.get_async("https://www.acfun.cn/v/ac4741185")
    print(demo_video)

asyncio.run(main())

依赖库

依赖: 以 pyproject.toml 为准requirements.txt 为 pip 兼容的简要列表)


参考 & 鸣谢

Special Thanks:

JetBrains Licenses for Open Source Development - Community Support


About Me

ac彩娘-阿部高和 ♂ 整点大香蕉🍌 AcFunCard


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

acfunsdk-0.9.8.tar.gz (86.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

acfunsdk-0.9.8-py3-none-any.whl (69.7 kB view details)

Uploaded Python 3

File details

Details for the file acfunsdk-0.9.8.tar.gz.

File metadata

  • Download URL: acfunsdk-0.9.8.tar.gz
  • Upload date:
  • Size: 86.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for acfunsdk-0.9.8.tar.gz
Algorithm Hash digest
SHA256 4279c7861b4febb63d9b44b9ee06d2a0c516ed7b7aeebc5174b709a2a81badf5
MD5 40bdb69e7cacf7d190810b4c877a6b31
BLAKE2b-256 27c2cbfd77a2c7eabfb583e697147de223b8182d502eba0df6f94189108da47c

See more details on using hashes here.

File details

Details for the file acfunsdk-0.9.8-py3-none-any.whl.

File metadata

  • Download URL: acfunsdk-0.9.8-py3-none-any.whl
  • Upload date:
  • Size: 69.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for acfunsdk-0.9.8-py3-none-any.whl
Algorithm Hash digest
SHA256 cd251374d815e95798628633f96ef541e32067bf56a1dd18f760c78e45720654
MD5 d3cd1c4a470e1ced3a9b87720ebdd81c
BLAKE2b-256 924964a32ed40c791852d932f653bd330a542b92bf4a2e64da7c62a0184d709f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.9.8 This release

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.11

2 files

0.8.10

2 files

0.8.4

2 files

0.8.3

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page