import { TypedEmitter } from "tiny-typed-emitter"; import { BaseRequest } from "../base/index.js"; import Auth from "../base/Auth.js"; import type { GenerateNumberRange } from "../types/utils.js"; import type { VideoId } from "../types/index.js"; import type { VideoDetailReturnType, PlayUrlReturnType, VideoQn, VideoCodec, PlayerInfoReturnType } from "../types/video.js"; interface ProgressEvent { event: "download" | "merge-start" | "merge-end"; progress?: { loaded: number; total: number; progress: number; }; } interface EmitterEvents { "download-completed": (response: string[]) => void; progress: (response: ProgressEvent) => void; error: (response: string) => void; completed: (response: string) => void; } export default class Video extends BaseRequest { aid?: number; noAuthUseCookie: boolean; constructor(auth?: Auth, noAuthUseCookie?: boolean, aid?: number); /** * 设置视频aid * @param aid 视频aid */ setAid(aid: number): void; /** * 获取视频信息 */ info(params: VideoId): Promise<{ [key: string]: any; }>; /** * 获取视频详细信息 */ detail(params: VideoId): Promise; /** * 获取视频播放信息 */ playerInfo(params: VideoId & { cid: number; }): Promise; /** * 获取视频简介 */ desc(params: VideoId): Promise<{ code: number; message: string; ttl: number; data: string; }>; /** *查询视频分P列表 (aid/bvid转cid) */ pagelist(params: VideoId): Promise<{ cid: number; page: number; from: string; part: string; duration: number; vid: string; weblink: string; dimension: { width: number; height: number; rotate: number; }; first_frame: string; }>; /** * 点赞 * @param aid 视频aid * @param like 点赞或取消点赞 */ like(params: { aid?: number; like: boolean; }): Promise<{}>; /** * 投币 * @param aid 视频aid * @param multiply 1: 1枚,2:2枚 */ coin(params: { aid?: number; multiply: "1" | "2"; }): Promise<{}>; /** * 列出收藏夹 * @param aid aid * @param type 收藏夹类型,默认2 */ listFavoriteBox(params?: { aid?: number; type: number; }): Promise<{ count: number; list: { id: number; fid: number; mid: number; attr: number; title: string; fav_state: number; media_count: number; }[]; season: any; }>; /** * 处理收藏夹内容 * @param aid aid * @param type 收藏夹类型,默认2 * @param add_media_ids 添加的视频id,英文逗号分隔 * @param del_media_ids 删除的视频id,英文逗号分隔 */ editFavoriteBox(params: { aid?: number; type: number; add_media_ids?: string; del_media_ids?: string; }): Promise<{ prompt: boolean; ga_data: any; total_msg: string; success_num: number; }>; /** * 增加分享次数 * @param aid 视频aid */ addShare(params?: { aid?: number; }): Promise<{}>; /** * 一键三连 * @param aid 视频aid */ likeCoinShare(params?: { aid?: number; }): Promise<{ like: boolean; coin: boolean; fav: boolean; multiply: number; id_risk: boolean; gaia_res_type: number; gaia_data: any; }>; /** * 获取视频信息 * 限制游客访问的视频需要登录 * @param aid 视频aid * @param bvid 视频bvid */ getInfo(params: VideoId): Promise<{ [key: string]: any; }>; /** * 获取视频信息 */ playurl(params: { aid?: number; bvid?: string; cid: number; qn?: number; fnval?: number; fourk?: 0 | 1; platform?: "pc" | "html5"; high_quality?: 0 | 1; }): Promise; /** * 获取视频弹幕,为protobuf格式 * @param cid 视频cid * @param aid 视频aid * @param segment_index 弹幕分片序号,6min一包,从0开始 * @param pull_mode 未知 * @param ps 未知 * @param pn 未知 */ getDm(params: { cid: number; aid?: number; segment_index: number; pull_mode?: number; ps?: number; pn?: number; }): Promise; /** * 获取视频所有弹幕,是否登录影响弹幕数量 * @param cid 视频cid * @param aid 视频aid */ getAllDm(params: { cid: number; aid?: number; bvid?: string; }): Promise; /** * 下载视频字幕,srt格式 * @param options * @param options.aid 视频 aid, 与 bvid 二选一 * @param options.bvid 视频 bvid, 与 aid 二选一 * @param options.cid 视频 cid * @param options.part 视频分 P,从0开始,如果传递 cid 则忽略 * @param options.subtitleId 字幕 id,优先使用 * @param options.lan 字幕语言,优先使用 * @param options.output 输出文件路径 * @param options.useV2 是否优先使用 subtitle_url_v2 */ downloadSubtitle(options: { cid: number; subtitleId?: number | string; lan?: string; output: string; useV2?: boolean; } & VideoId): Promise; private authAid; /** * 下载视频,如果不传递cid,会对视频详情接口进行一次请求。 * @param options * @param options.aid 视频aid, 与bvid二选一 * @param options.bvid 视频bvid,与aid二选一 * @param options.cid 视频cid,与part二选一 * @param options.part 视频分p,从0开始计算,如果有cid,则优先cid,如果二者皆为空,下载第一个 * @param options.output 输出文件路径 * @param options.ffmpegBinPath ffmpeg路径,用于合并视频和音频 * 如果不传递默认使用web模式,最高720p分辨率,且mediaOptions参数除qn不会生效 * 如果传递,则使用dash模式,分辨率和账户相关,如果想使用环境变量中的可以传递ffmpeg * @param options.cachePath 缓存路径,默认使用系统临时目录 * * @param mediaOptions * @param mediaOptions.resolution 分辨率宽度,默认为可选最高 @link https://socialsisteryi.github.io/bilibili-API-collect/docs/video/videostream_url.html#fnval%E8%A7%86%E9%A2%91%E6%B5%81%E6%A0%BC%E5%BC%8F%E6%A0%87%E8%AF%86 * @param mediaOptions.videoCodec 视频编码,默认为符合视频质量的第一个编码,7:H264,12:H265,13:AV1 * @param mediaOptions.audioQuality 音质,默认使用最高音质,30216:64k,30232:128k,30280:192k,30250:杜比全景声,30251:Hi-Res无损 * @param mediaOptions.qn 视频质量,默认使用64,会下载支持的最高质量,6: 240p, 16: 260p, 32: 480p,64:720p,80:1080p,112:1080p60,116:4k */ download(options: { cid?: number; part?: number; output: string; ffmpegBinPath?: string; cachePath?: string; } & VideoId, mediaOptions?: { videoCodec?: VideoCodec; audioQuality?: 30216 | 30232 | 30280 | 30250 | 30251; qn?: VideoQn; }, autoStart?: boolean): Promise<{ pause: () => void; start: () => void; cancel: () => void; on(event: "progress" | "completed" | "error", callback: (res: any) => void): void; emitter: TypedEmitter; }>; /** * dash下载视频 * @param options * @param options.aid 视频aid, 与bvid二选一 * @param options.bvid 视频bvid,与aid二选一 * @param options.cid 视频cid * @param options.output 输出文件路径 * @param options.ffmpegBinPath ffmpeg路径,用于合并视频和音频 * @param options.cachePath 缓存路径,默认使用系统临时目录 * @param options.disableVideo 禁止下载视频 * @param options.disableAudio 禁止下载音频 * @param mediaOptions * @param mediaOptions.qn 画质参数,默认为可选最高 @link https://socialsisteryi.github.io/bilibili-API-collect/docs/video/videostream_url.html#fnval%E8%A7%86%E9%A2%91%E6%B5%81%E6%A0%BC%E5%BC%8F%E6%A0%87%E8%AF%86 * @param mediaOptions.videoCodec 视频编码,默认为符合视频质量的第一个编码,7:H264,12:H265,13:AV1 * @param mediaOptions.audioQuality 音质,默认使用最高音质,30216:64k,30232:128k,30280:192k,30250:杜比全景声,30251:Hi-Res无损 */ dashDownload(options: { cid: number; output: string; ffmpegBinPath: string; cachePath?: string; disableVideo?: boolean; disableAudio?: boolean; } & VideoId, mediaOptions?: { videoCodec?: VideoCodec; audioQuality?: 30216 | 30232 | 30280 | 30250 | 30251; qn?: VideoQn; }, autoStart?: boolean): Promise<{ pause: () => void; start: () => void; cancel: () => void; on(event: "progress" | "completed" | "error", callback: (res: any) => void): void; emitter: TypedEmitter; }>; /** * mp4下载视频,无需ffmpeg进行合并 * @param options * @param options.aid 视频aid, 与bvid二选一 * @param options.bvid 视频bvid,与aid二选一 * @param options.cid 视频cid * @param options.output 输出文件路径 * * @param mediaOptions * @param mediaOptions.qn 视频质量,默认使用64,6: 240p, 16: 260p, 32: 480p,64:720p,80:1080p,112:1080p60,116:4k */ mp4Download(options: { cid: number; output: string; } & VideoId, mediaOptions?: { qn?: VideoQn; }, autoStart?: boolean): Promise<{ pause: () => void; start: () => void; cancel: () => void; on(event: "progress" | "completed" | "error", callback: (res: any) => void): void; emitter: TypedEmitter; }>; /** * 创建评论对象,操作评论的方法需要传递rpid * @param rpid 回复的评论id */ createReply(rpid?: number): { /** * 设置oid * @param oid 视频aid */ setOid: (oid: number) => void; /** * 评论列表 * @param ps 每页数量,默认20 * @param pn 页码,默认1 * @param sort 排序方式, 0: 按时间, 1: 按点赞, 2: 按回复 * @param nohot 是否显示热门评论, 0: 不显示, 1: 显示 */ list: (params?: { ps?: GenerateNumberRange<1, 20>; pn?: number; sort?: 0 | 1 | 2; nohot?: 0 | 1; }) => Promise<{ [key: string]: any; }>; /** * 评论个数 */ count: () => Promise<{ count: number; }>; /** * 添加评论 * @param root 根评论id * @param parent 父评论id * @param message 评论内容 * @param at_name_to_mid 用户信息 * @param pictures 图片地址 */ add: (params: { root?: number; parent?: number; message: string; at_name_to_mid?: string; pictures?: string; }) => Promise<{ rpid: number; }>; /** * 评论点赞 * @param rpid 评论id * @param action 1: 点赞, 0: 取消点赞 */ like: (params: { rpid?: number; action: 1 | 0; }) => Promise<{}>; /** * 评论点踩 * @param rpid 评论id * @param action 1: 点踩, 0: 取消点踩 */ hate: (params: { rpid?: number; action: 1 | 0; }) => Promise<{}>; /** * 评论删除 * @param rpid 评论id * @param action 1: 点踩, 0: 取消点踩 */ delete: (params?: { rpid?: number; }) => Promise<{}>; /** * 举报评论 * @param rpid 评论id * @param action 1: 点踩, 0: 取消点踩 */ report: (params: { rpid?: number; reason: number; }) => Promise<{}>; /** * 置顶评论 * @param rpid 评论id * @param action 1: 点踩, 0: 取消点踩 */ top: (params: { rpid?: number; action: 1 | 0; }) => Promise<{}>; }; } export {};