### Run example script Source: https://github.com/dolacmeo/acfunsdk/blob/main/README.md Execute the provided demo script from the repository root. ```shell python examples/acer_demo.py ``` -------------------------------- ### Install acfunsdk via PyPI Source: https://github.com/dolacmeo/acfunsdk/blob/main/README.md Standard installation command for the library. ```shell python -m pip install acfunsdk ``` -------------------------------- ### Retrieve Content via URL Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Use the get() method to automatically identify and fetch various AcFun content types including videos, articles, and live streams. ```python from acfunsdk import Acer acer = Acer() # 获取视频 video = acer.get("https://www.acfun.cn/v/ac4741185") print(video) # 输出: AcVideo([ac4741185]视频标题 @UP主名) print(video.title) # 视频标题 print(video.cover) # 封面图 URL print(video.video_list) # 分P列表 # 获取文章 article = acer.get("https://www.acfun.cn/a/ac37416587") print(article) # 输出: AcArticle([ac37416587]文章标题 @作者名) print(article.contents) # 文章内容分段 # 获取番剧 bangumi = acer.get("https://www.acfun.cn/bangumi/aa5023295") print(bangumi) # 输出: AcBangumi([aa5023295]番剧名称) print(bangumi.episode_data) # 剧集列表 # 获取用户主页 user = acer.get("https://www.acfun.cn/u/39088") print(user) # 输出: Acer([#39088] @用户名) # 获取直播间 live = acer.get("https://live.acfun.cn/live/378269") print(live) # 输出: AcLive(#378269 直播标题 @主播名) # 获取动态 moment = acer.get("https://www.acfun.cn/moment/am2797962") print(moment) # 输出: AcMoment 对象 # 获取合集 album = acer.get("https://www.acfun.cn/a/aa6001205") print(album) # 输出: AcAlbum 对象 # 获取涂鸦页面 doodle = acer.get("https://hd.acfun.cn/doodle/knNWmnco.html") print(doodle) # 输出: AcDoodle 对象 # 支持移动端分享链接 share = acer.get("https://m.acfun.cn/v/?ac=37086357") print(share) # 自动转换为对应内容对象 ``` -------------------------------- ### Manage Live Streams Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Interact with live streams, including listing rooms, getting stream URLs, and sending interactions. ```python from acfunsdk import Acer acer = Acer() # 获取直播首页 live_index = acer.acfun.AcLive() print(live_index) # 输出: AcLive(直播 - AcFun弹幕视频网) # 获取正在直播的列表 live_list = live_index.list(obj=True) # 返回 AcLiveUp 对象列表 for l in live_list[:5]: print(f"直播: {l.title} - @{l.username}") # 获取指定直播间 live_room = acer.acfun.AcLiveUp(378269) print(f"直播标题: {live_room.title}") print(f"封面: {live_room.cover}") print(f"开播时间: {live_room.live.start_time if live_room.live else '未开播'}") # 获取直播流地址(需直播中) if live_room.live and live_room.live.is_open: m3u8_url = live_room.live.m3u8_url(quality=-1) # -1 为默认画质 print(f"直播流: {m3u8_url}") # 获取所有画质 for i, q in enumerate(live_room.live.representation): print(f"画质{i}: {q['name']} - {q['url']}") # 发送直播弹幕(需登录且直播中) # live_room.push_danmaku("测试弹幕") # 点赞直播 # live_room.like(times=5) # 查看礼物列表 # gifts = live_room.gift_list() # 送礼物 # live_room.send_gift(gift_id=1, size=1, times=1) # 获取主播关联视频 contents = live_room.contents(obj=True) for v in contents[:3]: print(f"关联视频: {v.title}") ``` -------------------------------- ### Get Video Channel Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Retrieve the channel information associated with a video object. ```python channel = video.AcChannel() print(channel) ``` -------------------------------- ### Contribution Management API Source: https://context7.com/dolacmeo/acfunsdk/llms.txt APIs for managing creator contributions, including viewing submitted videos and articles, accessing data center statistics, and getting live streaming configurations. Requires login. ```APIDOC ## Contribution Management API ### Description APIs for managing creator contributions, including viewing submitted videos and articles, accessing data center statistics, and getting live streaming configurations. Requires login. ### Methods - `acer.contribute.my_videos(page, status, sortby, keyword)`: Get your video contributions. `status` can be 'all', 'passed', 'posting', 'returned'. `sortby` can be 'recently', 'viwed', 'banana'. - `acer.contribute.my_articles(page)`: Get your article contributions. - `acer.contribute.data_center(days)`: Get an overview of data center statistics for a specified number of `days`. - `acer.contribute.data_center_detail(rtype, days, sortby)`: Get detailed data center statistics. `rtype` can be 'video', 'article', 'live'. `sortby` can be 'viewCount', 'commentCount', 'stowCount', 'shareCount', 'bananaCount'. - `acer.contribute.get_live_config()`: Get live streaming push configuration. ### Request Example ```python # Get my video contributions my_videos = acer.contribute.my_videos( page=1, status='all', # all/passed/posting/returned sortby='recently', # recently/viwed/banana keyword=None # search keyword ) for v in my_videos: print(f"Video: {v['title']} - Status: {v['status']}") # Get my article contributions my_articles = acer.contribute.my_articles(page=1) # Data center overview overview = acer.contribute.data_center(days=7) print(f"7-day data: {overview}") # Detailed data video_data = acer.contribute.data_center_detail( rtype='video', # video/article/live days=7, sortby='viewCount' # viewCount/commentCount/stowCount/shareCount/bananaCount ) print(f"Video data: {video_data}") # Get live streaming push configuration live_config = acer.contribute.get_live_config() print(f"Push URL: {live_config}") ``` ### Response Example ```json // Response examples vary based on the method called. // For my_videos, it might return a list of video objects: // [ // {"title": "My Video", "status": "passed"} // ] // For data_center, it might return a dictionary of statistics: // {"totalViews": 1000, "totalComments": 50} // For get_live_config, it might return a dictionary with stream details: // {"pushUrl": "rtmp://..."} ``` ``` -------------------------------- ### Fans Club/Medal Management API Source: https://context7.com/dolacmeo/acfunsdk/llms.txt APIs for managing fan clubs and medals, including listing medals, getting medal information for a specific UP主, and wearing/unwearing medals. Requires login. ```APIDOC ## Fans Club/Medal Management API ### Description APIs for managing fan clubs and medals, including listing medals, getting medal information for a specific UP主, and wearing/unwearing medals. Requires login. ### Methods - `acer.fansclub.medal_list()`: Get a list of your medals. - `acer.fansclub.medal_info(uid)`: Get medal information for a specific UP主 (user ID). - `acer.fansclub.medal_wear(uid, on_off)`: Wear or unwear a medal for a specific UP主. `on_off` is a boolean. ### Request Example ```python # Get my medal list medals = acer.fansclub.medal_list() for m in medals: print(f"Medal: {m['clubName']} - Level: {m['level']}") # Get medal info for a specific UP主 medal_info = acer.fansclub.medal_info(uid=39088) print(f"Medal Details: {medal_info}") # Wear a medal acer.fansclub.medal_wear(uid=39088, on_off=True) # Unwear a medal acer.fansclub.medal_wear(uid=39088, on_off=False) ``` ### Response Example ```json // Response examples vary based on the method called. // For medal_list, it might return a list of medal objects: // [ // {"clubName": "UP主 Fan Club", "level": 5} // ] // For medal_info, it might return a dictionary with medal details: // {"clubName": "UP主 Fan Club", "level": 5, "isWearing": true} ``` ``` -------------------------------- ### Develop from source using uv Source: https://github.com/dolacmeo/acfunsdk/blob/main/README.md Commands for setting up the development environment and running tests. ```shell uv sync --all-groups uv run pytest uv build ``` -------------------------------- ### Initialize Acer Client Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Create an instance of the Acer client using guest mode, credentials, or saved cookies. You can also configure the save path for session data. ```python from acfunsdk import Acer # 访客模式(无需登录) acer = Acer() # 使用用户名密码登录(成功后自动保存 '<用户名>.cookies' 文件) acer = Acer(username='you@email.com', password='your_password') # 加载已保存的登录 Cookie acer = Acer(loading='13800138000') # 配置 acsaver 保存路径(需安装 acsaver>=0.1.3) acer = Acer(acsaver_path=r"D:\AcSaver") # 检查登录状态和用户信息 print(f"登录状态: {acer.is_logined}") # 输出: True 或 False print(f"用户ID: {acer.uid}") # 输出: 12345678 print(f"用户名: {acer.username}") # 输出: 你的用户名 ``` -------------------------------- ### Synchronous usage of Acer Source: https://github.com/dolacmeo/acfunsdk/blob/main/README.md Demonstrates how to instantiate the Acer client, handle authentication, and retrieve various content types. ```python 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) ``` -------------------------------- ### Asynchronous usage of Acer Source: https://github.com/dolacmeo/acfunsdk/blob/main/README.md Demonstrates how to use the asynchronous interface for content retrieval. ```python 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()) ``` -------------------------------- ### Manage Contributions Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Manage video and article contributions, and access data center analytics. ```python from acfunsdk import Acer acer = Acer(loading='13800138000') # 获取我的视频投稿 my_videos = acer.contribute.my_videos( page=1, status='all', # all/passed/posting/returned sortby='recently', # recently/viwed/banana keyword=None # 搜索关键词 ) for v in my_videos: print(f"视频: {v['title']} - 状态: {v['status']}") # 获取我的文章投稿 my_articles = acer.contribute.my_articles(page=1) # 数据中心概览 overview = acer.contribute.data_center(days=7) print(f"7天数据: {overview}") # 详细数据 video_data = acer.contribute.data_center_detail( rtype='video', # video/article/live days=7, sortby='viewCount' # viewCount/commentCount/stowCount/shareCount/bananaCount ) print(f"视频数据: {video_data}") # 获取直播推流配置 live_config = acer.contribute.get_live_config() print(f"推流地址: {live_config}") ``` -------------------------------- ### Acer Class Initialization Source: https://context7.com/dolacmeo/acfunsdk/llms.txt The Acer class is the primary entry point for the SDK, supporting guest mode, password authentication, and cookie-based sessions. ```APIDOC ## Initialization ### Description Creates an AcFun client instance. Supports guest mode, password login, and loading existing cookies. ### Parameters - **username** (str) - Optional - Email or username for login - **password** (str) - Optional - Password for login - **loading** (str) - Optional - Username to load saved cookies - **acsaver_path** (str) - Optional - Path for saving session data ### Request Example ```python from acfunsdk import Acer # Guest mode acer = Acer() # Login acer = Acer(username='user', password='password') ``` ``` -------------------------------- ### Run tests Source: https://github.com/dolacmeo/acfunsdk/blob/main/README.md Commands for executing test suites, including filtering by markers and environment variables. ```shell # 仅访客 / 公开 URL(适合 CI) uv run pytest -m "not requires_cookies" # 全量(需已配置登录 Cookie,见下) uv run pytest ``` ```shell # 只跑 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 ``` -------------------------------- ### Perform Daily Sign-in Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Execute the daily sign-in process to claim rewards and check AC coin balance. ```python from acfunsdk import Acer acer = Acer(loading='13800138000') # 执行签到 result = acer.signin() if result: print("签到成功,领取香蕉奖励!") else: print("今日已签到") # 查询 AC币余额 acoin = acer.acoin() print(f"AC币余额: {acoin}") # 输出: {'acoinBalance': 100, ...} ``` -------------------------------- ### Manage Albums Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Create and manage personal content albums. Requires login. ```python from acfunsdk import Acer acer = Acer(loading='13800138000') # 获取我的合集列表 my_albums = acer.album.list(page=1, size=10) for a in my_albums.get('albumList', []): print(f"合集: {a['title']} (ID: {a['arubamuId']})") # 创建新合集 album_id = acer.album.add( title="我的精选合集", rtype=2, # 2视频 3文章 cover="https://example.com/cover.jpg", intro="这是合集简介", status=1 # 1公开 2私密 ) print(f"创建成功,合集ID: {album_id}") # 更新合集信息 acer.album.update( album_id=album_id, title="新标题", rtype=2, cover="https://example.com/new_cover.jpg", intro="新简介", status=1 ) # 向合集添加内容 acer.album.contents_add(album_id=album_id, rtype=2, rids=["4741185", "4741186"]) # 获取合集内容 contents = acer.album.get_contents(album_id=album_id, page=1, size=10) for c in contents.get('contentList', []): print(f"内容: {c['title']}") # 从合集移除内容 acer.album.contents_del(album_id=album_id, rids=["content_id_1", "content_id_2"]) # 删除合集 acer.album.remove(album_id=album_id) ``` -------------------------------- ### 商城操作与物品管理 Source: https://context7.com/dolacmeo/acfunsdk/llms.txt 获取商城商品列表、查询个人物品以及使用或取消使用物品。 ```python shop = acer.bananamall.shop_list( page=1, size=30, stype=1, # 排序类型 asc=False # 升序/降序 ) for item in shop.get('productList', []): print(f"商品: {item['productName']} - 价格: {item['price']}香蕉") # 获取我的物品 my_items = acer.bananamall.my_items(page=1, size=30) for item in my_items.get('itemList', []): print(f"物品: {item['productName']}") # 使用物品 acer.bananamall.set_item(pid=123456, on_off=True) # 取消使用 acer.bananamall.set_item(pid=123456, on_off=False) ``` -------------------------------- ### 投蕉与点赞互动 Source: https://context7.com/dolacmeo/acfunsdk/llms.txt 实现对视频、文章或番剧的投香蕉和点赞操作,需登录状态。 ```python from acfunsdk import Acer acer = Acer(loading='13800138000') # 投香蕉(rtype: 1番剧 2视频 3文章) success = acer.throw_banana(rtype=2, rid=4741185, count=1) # count: 1-5 if success: print("投蕉成功!") # 点赞 acer.like_add(otype=2, oid=4741185) # 取消点赞 acer.like_delete(otype=2, oid=4741185) ``` -------------------------------- ### 异常处理机制 Source: https://context7.com/dolacmeo/acfunsdk/llms.txt 使用自定义异常类处理网络错误、未登录、资源不存在及 API 变更等情况。 ```python from acfunsdk import Acer from acfunsdk.exceptions import ( AcExploded, # 网络连接错误(A站服务异常) NotInCar, # 未登录错误 ShuiNi, # 404资源不存在 TingBuDong, # API响应格式变更 LuanJiangHua, # 401请求被拒绝 NiShuiA # 非本人无权操作 ) acer = Acer() try: # 尝试获取不存在的视频 video = acer.get("https://www.acfun.cn/v/ac9999999999") if video.is_404: print("视频不存在") except ShuiNi as e: print(f"资源不存在: {e}") try: # 尝试执行需要登录的操作 acer.signin() except NotInCar as e: print(f"需要登录: {e}") # 输出: 需要登录: 先登录啊! try: # 网络请求 video = acer.get("https://www.acfun.cn/v/ac4741185") except AcExploded as e: print(f"A站炸了: {e}, URL: {e.url}, 状态码: {e.status_code}") except TingBuDong as e: print(f"API格式变更: {e}") ``` -------------------------------- ### Content Retrieval (acer.get) Source: https://context7.com/dolacmeo/acfunsdk/llms.txt A unified interface to fetch various AcFun content types (videos, articles, live streams, etc.) by providing the URL. ```APIDOC ## GET /content ### Description Automatically identifies and retrieves content objects based on the provided AcFun URL. ### Parameters - **url** (str) - Required - The AcFun URL (video, article, bangumi, user, live, etc.) ### Request Example ```python video = acer.get("https://www.acfun.cn/v/ac4741185") ``` ### Response - **Object** (Instance) - Returns a specific content object (e.g., AcVideo, AcArticle, AcLive) ``` -------------------------------- ### Manage Articles Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Access article content, tags, and recommendations using the AcArticle class. ```python from acfunsdk import Acer acer = Acer() # 获取文章对象 article = acer.acfun.AcArticle("ac37416587") # 基本信息 print(f"标题: {article.title}") print(f"封面: {article.cover}") print(f"标签: {article.tags}") # 文章内容分段 for part in article.contents: print(part) # 获取相关推荐文章 recommends = article.recommends(obj=True) for a in recommends: print(f"推荐: {a.title}") ``` -------------------------------- ### Manage User Authentication Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Handle login, logout, and cookie persistence for authenticated sessions. ```python from acfunsdk import Acer acer = Acer() # 用户名密码登录 success = acer.login(username='you@email.com', password='your_password') if success: print(f"登录成功! 用户ID: {acer.uid}") # Cookie 自动保存到 'you@email.com.cookies' 文件 else: print("登录失败") # 加载已保存的 Cookie acer.loading(username='you@email.com') print(f"已加载用户: {acer.username}") # 退出登录 acer.logout() print(f"登录状态: {acer.is_logined}") # 输出: False ``` -------------------------------- ### User Authentication and Actions Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Methods for managing user sessions, including login, logout, and daily check-ins for rewards. ```APIDOC ## POST /auth/login ### Description Authenticates a user and saves session cookies. ### Request Body - **username** (str) - Required - **password** (str) - Required ## POST /user/signin ### Description Performs daily check-in to claim rewards. ### Response - **result** (bool) - Success status of the check-in ``` -------------------------------- ### Manage Follows Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Manage user follows, groups, and fan lists. Requires login. ```python from acfunsdk import Acer acer = Acer(loading='13800138000') # 获取关注分组 groups = acer.follow.groups() for g in groups: print(f"分组: {g['groupName']} (ID: {g['groupId']})") # 创建关注分组 acer.follow.group_add(name="我喜欢的UP主") # 重命名分组 acer.follow.group_rename(gid=123456, name="新分组名") # 删除分组 acer.follow.group_remove(gid=123456) # 关注用户 acer.follow.add(uid=39088) # 特别关注 acer.follow.add(uid=39088, attention=True) # 取消特别关注(保持关注) acer.follow.add(uid=39088, attention=False) # 取消关注 acer.follow.remove(uid=39088) # 获取我的粉丝列表 fans = acer.follow.my_fans(page=1, limit=10, obj=True) # obj=True 返回 AcUp 对象 for f in fans: print(f"粉丝: {f.name}") ``` -------------------------------- ### Manage Bangumi Content Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Access bangumi details, episode lists, and related seasons using the AcBangumi class. ```python from acfunsdk import Acer acer = Acer() # 获取番剧对象 bangumi = acer.acfun.AcBangumi("aa5023295") # 基本信息 print(f"番剧名: {bangumi.title}") print(f"封面(横版): {bangumi.cover_image('h')}") print(f"封面(竖版): {bangumi.cover_image('v')}") # 剧集列表 episodes = bangumi.episode_data for ep in episodes: print(f"第{ep.get('sort')}集: {ep.get('episodeName')}") # 获取指定集数的播放信息 video = bangumi.video(index=0) # 第一集 print(video) # 获取系列关联番剧 seasons = bangumi.season(obj=True) # 返回 AcBangumi 对象列表 for s in seasons: print(f"关联季: {s.title}") ``` -------------------------------- ### Manage Favorites Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Operations for managing video, article, and bangumi favorites. Requires an active Acer instance. ```python folders = acer.favourite.video_groups() for f in folders: print(f"收藏夹: {f['folderName']} (ID: {f['folderId']})") # 创建新收藏夹 acer.favourite.video_group_add(name="我的新收藏夹") # 重命名收藏夹 acer.favourite.video_group_rename(fid=123456, name="新名称") # 删除收藏夹 acer.favourite.video_group_remove(fid=123456) # 收藏视频(rtype: 2视频 3文章 1番剧) acer.favourite.add(rtype=2, rid="4741185", fids="123456") # fids 为收藏夹ID # 取消收藏 acer.favourite.cancel(rtype=2, rid="4741185", fids="123456") # 获取收藏夹内视频列表 videos = acer.favourite.video_list(fid=123456, page=1, limit=10) for v in videos: print(f"收藏: {v['title']}") # 获取收藏的文章/番剧/合集 articles = acer.favourite.article_list(page=1, limit=10) bangumis = acer.favourite.bangumi_list(page=1, limit=10) albums = acer.favourite.album_list(page=1, limit=10) ``` -------------------------------- ### Manage User Profiles Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Access user information, statistics, posts, and social interactions like following. ```python from acfunsdk import Acer acer = Acer() # 获取用户对象 user = acer.acfun.AcUp(39088) # 基本信息 print(f"用户名: {user.name}") print(f"头像: {user.avatar}") print(f"主页: {user.referer}") # 加载详细统计信息 user.loading() print(f"视频数: {user.video_count}") print(f"文章数: {user.article_count}") print(f"关注数: {user.following_count}") print(f"粉丝数: {user.followed_count}") # 获取用户投稿 videos = user.video(page=1, limit=10, orderby='newest') # newest/hotest for v in videos: print(f"视频: {v.title}") articles = user.article(page=1, limit=10) for a in articles: print(f"文章: {a.title}") # 获取用户关注/粉丝 following = user.following(page=1, limit=10) followers = user.followed(page=1, limit=10) # 关注/取消关注用户(需登录) user.follow_add(attention=True) # 特别关注 user.follow_remove() ``` -------------------------------- ### Interact with Video Objects Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Access detailed video information, playback lists, and recommendations using the AcVideo class. ```python from acfunsdk import Acer acer = Acer() # 获取视频对象 video = acer.acfun.AcVideo("ac4741185") # 或 acer.get("https://www.acfun.cn/v/ac4741185") # 基本信息 print(f"标题: {video.title}") print(f"封面: {video.cover}") print(f"移动端链接: {video.mobile_url}") print(f"二维码链接: {video.mobile_qrcode}") # 分P视频列表 for i, p in enumerate(video.video_list): print(f"P{i+1}: {p['title']} - 时长: {p.get('durationMillis', 0)//1000}秒") # 获取指定分P的播放信息 video_info = video.video(index=0) # 第一P print(video_info) # 获取相关推荐视频 recommends = video.recommends(obj=True) # obj=True 返回 AcVideo 对象列表 for v in recommends[:5]: print(f"推荐: {v.title}") ``` -------------------------------- ### 获取排行榜数据 Source: https://context7.com/dolacmeo/acfunsdk/llms.txt 通过频道 ID 或直接使用 URL 获取 AcFun 站内排行榜。 ```python from acfunsdk import Acer acer = Acer() # 获取排行榜 rank = acer.acfun.AcRank( cid=None, # 频道ID,None为全站 sub_cid=None, # 子频道ID limit=50, # 获取数量 date_range='DAY' # DAY/THREE_DAYS/WEEK ) # 通过 URL 获取 rank = acer.get("https://www.acfun.cn/rank/list/?pcid=1&cid=-1&range=DAY") print(rank) ``` -------------------------------- ### Favorite Management API Source: https://context7.com/dolacmeo/acfunsdk/llms.txt APIs for managing user favorite lists, including creating, renaming, deleting folders, and adding/removing videos, articles, or bangumis. ```APIDOC ## Favorite Management API ### Description APIs for managing user favorite lists, including creating, renaming, deleting folders, and adding/removing videos, articles, or bangumis. ### Methods - `acer.favourite.video_groups()`: Get favorite folders. - `acer.favourite.video_group_add(name)`: Create a new favorite folder. - `acer.favourite.video_group_rename(fid, name)`: Rename an existing favorite folder. - `acer.favourite.video_group_remove(fid)`: Delete a favorite folder. - `acer.favourite.add(rtype, rid, fids)`: Add content to favorites. `rtype` can be 2 (video), 3 (article), 1 (bangumi). `fids` is the folder ID. - `acer.favourite.cancel(rtype, rid, fids)`: Remove content from favorites. - `acer.favourite.video_list(fid, page, limit)`: Get videos in a favorite folder. - `acer.favourite.article_list(page, limit)`: Get articles in favorites. - `acer.favourite.bangumi_list(page, limit)`: Get bangumis in favorites. - `acer.favourite.album_list(page, limit)`: Get albums in favorites. ### Request Example ```python # Get favorite folders folders = acer.favourite.video_groups() for f in folders: print(f"Favorite Folder: {f['folderName']} (ID: {f['folderId']})") # Create a new favorite folder acer.favourite.video_group_add(name="My New Folder") # Rename a favorite folder acer.favourite.video_group_rename(fid=123456, name="New Name") # Delete a favorite folder acer.favourite.video_group_remove(fid=123456) # Favorite a video (rtype: 2 video, 3 article, 1 bangumi) acer.favourite.add(rtype=2, rid="4741185", fids="123456") # fids is the folder ID # Unfavorite acer.favourite.cancel(rtype=2, rid="4741185", fids="123456") # Get list of videos in a favorite folder videos = acer.favourite.video_list(fid=123456, page=1, limit=10) for v in videos: print(f"Favorite: {v['title']}") # Get favorite articles/bangumis/albums articles = acer.favourite.article_list(page=1, limit=10) bangumis = acer.favourite.bangumi_list(page=1, limit=10) albums = acer.favourite.album_list(page=1, limit=10) ``` ### Response Example ```json // Response examples vary based on the method called. // For video_groups, it might return a list of folder objects: // [ // {"folderName": "Favorites", "folderId": 123456} // ] // For video_list, it might return a list of video objects: // [ // {"title": "Example Video Title", "videoId": "4741185"} // ] ``` ``` -------------------------------- ### Manage Favorites Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Manage personal collections and favorites. Requires authentication. ```python from acfunsdk import Acer acer = Acer(loading='13800138000') ``` -------------------------------- ### Album Management API Source: https://context7.com/dolacmeo/acfunsdk/llms.txt APIs for managing personal albums, including creating, editing, and managing content within albums. Requires login. ```APIDOC ## Album Management API ### Description APIs for managing personal albums, including creating, editing, and managing content within albums. Requires login. ### Methods - `acer.album.list(page, size)`: Get a list of your albums. - `acer.album.add(title, rtype, cover, intro, status)`: Create a new album. `rtype` can be 2 (video) or 3 (article). `status` can be 1 (public) or 2 (private). - `acer.album.update(album_id, title, rtype, cover, intro, status)`: Update an existing album. - `acer.album.contents_add(album_id, rtype, rids)`: Add content to an album. `rids` is a list of content IDs. - `acer.album.get_contents(album_id, page, size)`: Get the contents of an album. - `acer.album.contents_del(album_id, rids)`: Remove content from an album. - `acer.album.remove(album_id)`: Delete an album. ### Request Example ```python # Get my album list my_albums = acer.album.list(page=1, size=10) for a in my_albums.get('albumList', []): print(f"Album: {a['title']} (ID: {a['arubamuId']})") # Create a new album album_id = acer.album.add( title="My Featured Album", rtype=2, # 2 video, 3 article cover="https://example.com/cover.jpg", intro="This is the album introduction.", status=1 # 1 public, 2 private ) print(f"Album created successfully, ID: {album_id}") # Update album information acer.album.update( album_id=album_id, title="New Title", rtype=2, cover="https://example.com/new_cover.jpg", intro="New introduction.", status=1 ) # Add content to an album acer.album.contents_add(album_id=album_id, rtype=2, rids=["4741185", "4741186"]) # Get album contents contents = acer.album.get_contents(album_id=album_id, page=1, size=10) for c in contents.get('contentList', []): print(f"Content: {c['title']}") # Remove content from an album acer.album.contents_del(album_id=album_id, rids=["content_id_1", "content_id_2"]) # Delete an album acer.album.remove(album_id=album_id) ``` ### Response Example ```json // Response examples vary based on the method called. // For list, it might return an object with albumList: // { // "albumList": [ // {"title": "My Album", "arubamuId": "album123"} // ] // } // For add, it returns the new album ID: // "album123" // For get_contents, it might return an object with contentList: // { // "contentList": [ // {"title": "Content Title", "contentId": "content456"} // ] // } ``` ``` -------------------------------- ### AcComment API Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Endpoints for managing comments, including retrieval, posting, and interaction. ```APIDOC ## GET /acfun/AcComment ### Description Retrieves comments for a specific resource (video, article, etc.) and supports interaction like liking or replying. ### Method GET/POST ### Parameters #### Query Parameters - **rtype** (integer) - Required - Resource type (1: Bangumi, 2: Video, 3: Article, 10: Dynamic). - **rid** (integer) - Required - Resource ID. ### Response #### Success Response (200) - **list** (list) - List of comment objects. - **hot** (list) - List of top-rated comments. ``` -------------------------------- ### Manage Danmaku Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Search, protect, and delete danmaku on your videos, and manage forbidden words. ```python from acfunsdk import Acer acer = Acer(loading='13800138000') # 获取高级弹幕设置 config = acer.danmaku.advance_config() print(f"当前设置: {config}") # 设置高级弹幕权限 # 1任何人 2仅限粉丝 3仅限互相关注 4关闭高级弹幕 acer.danmaku.advance_setup(n=1) # 获取屏蔽词列表 forbidden = acer.danmaku.forbidden_words() print(f"屏蔽词: {forbidden}") # 添加屏蔽词 acer.danmaku.forbidden_add(words="屏蔽词1,屏蔽词2") # 删除屏蔽词 acer.danmaku.forbidden_del(words="屏蔽词1") # 搜索弹幕 result = acer.danmaku.danmaku_list( page=1, ac_num=4741185, # 视频AC号 search="关键词" # 搜索内容 ) for d in result.get('danmakuList', []): print(f"弹幕: {d['content']} - {d['userName']}") # 保护弹幕(防止被自动清理) acer.danmaku.danmaku_protect(ac_num=4741185, danmaku_id=123456, on_off=True) # 删除弹幕 acer.danmaku.danmaku_del(danmaku_ids="123456,123457") ``` -------------------------------- ### 浏览历史管理 Source: https://context7.com/dolacmeo/acfunsdk/llms.txt 查看、转换历史记录对象以及清空不同类型的浏览历史,需在登录状态下使用。 ```python from acfunsdk import Acer acer = Acer(loading='13800138000') # 获取浏览历史 history = acer.history(page=1, limit=10, obj=False) for h in history.get('histories', []): print(f"历史: {h['title']} - 类型: {h['resourceType']}") # 获取历史并转换为对象 history_objs = acer.history(page=1, limit=10, obj=True) for item in history_objs.get('histories', []): print(item) # 清空浏览历史 acer.history_del_all() # 清空全部 acer.history_del_all(rtype="1,2") # 仅清空视频 acer.history_del_all(rtype="3") # 仅清空文章 ``` -------------------------------- ### Follow Management API Source: https://context7.com/dolacmeo/acfunsdk/llms.txt APIs for managing user follows, including following/unfollowing users, managing groups, and retrieving fan lists. Requires login. ```APIDOC ## Follow Management API ### Description APIs for managing user follows, including following/unfollowing users, managing groups, and retrieving fan lists. Requires login. ### Methods - `acer.follow.groups()`: Get follow groups. - `acer.follow.group_add(name)`: Create a new follow group. - `acer.follow.group_rename(gid, name)`: Rename a follow group. - `acer.follow.group_remove(gid)`: Delete a follow group. - `acer.follow.add(uid, attention)`: Follow a user. `attention=True` for special follow. - `acer.follow.remove(uid)`: Unfollow a user. - `acer.follow.my_fans(page, limit, obj)`: Get your fan list. `obj=True` returns AcUp objects. ### Request Example ```python # Get follow groups groups = acer.follow.groups() for g in groups: print(f"Group: {g['groupName']} (ID: {g['groupId']})") # Create a new follow group acer.follow.group_add(name="My Favorite UP主s") # Rename a group acer.follow.group_rename(gid=123456, name="New Group Name") # Delete a group acer.follow.group_remove(gid=123456) # Follow a user acer.follow.add(uid=39088) # Special follow acer.follow.add(uid=39088, attention=True) # Unfollow (keep following) acer.follow.add(uid=39088, attention=False) # Unfollow acer.follow.remove(uid=39088) # Get my fan list fans = acer.follow.my_fans(page=1, limit=10, obj=True) # obj=True returns AcUp objects for f in fans: print(f"Fan: {f.name}") ``` ### Response Example ```json // Response examples vary based on the method called. // For groups, it might return a list of group objects: // [ // {"groupName": "Default Group", "groupId": 101} // ] // For my_fans, it might return a list of fan objects: // [ // {"userId": 39088, "userName": "ExampleFan"} // ] ``` ``` -------------------------------- ### List Bangumi Source: https://context7.com/dolacmeo/acfunsdk/llms.txt Retrieve and filter the list of available bangumi on AcFun. ```python from acfunsdk import Acer acer = Acer() # 获取番剧列表对象 bangumi_list = acer.acfun.AcBangumiList() # 查看可用筛选条件 for menu in bangumi_list.menu_filter: print(f"{menu['title']}: {list(menu['item'].values())}") # 获取番剧列表(使用默认筛选) result = bangumi_list.page(page=1, obj=True) print(f"总数: {result['total_count']}, 当前页: {result['page_now']}/{result['page_total']}") for b in result['items'][:5]: print(f"番剧: {b.title}") ```