BILIBILI 字幕提取教程简略版

news/2024/11/17 7:44:43/文章来源:https://www.cnblogs.com/apachecn/p/18415093

首先是通过 F12 拿到 AID 和 CID(见其它文章),然后调用这个接口:

https://api.bilibili.com/x/player/wbi/v2?aid={av}&cid={cid}
{"code":0,"message":"0","ttl":1,"data":{"aid":1855215937,"bvid":"BV1Rs421u7C4","allow_bp":false,"no_share":false,"cid":1560156670,"max_limit":3000,"page_no":1,"has_next":false,"ip_info":{"ip":"124.64.124.137","zone_ip":" 10.66.22.34","zone_id":4243456,"country":"中国","province":"北京","city":""},"login_mid":9169694,"login_mid_hash":"c325f1d7","is_owner":false,"name":"绝不原创的飞龙","permission":"10000,1001","level_info":{"current_level":6,"current_min":28800,"current_exp":33049,"next_exp":-1,"level_up":1695833946},"vip":{"type":2,"status":1,"due_date":1730649600000,"vip_pay_type":1,"theme_type":0,"label":{"path":"","text":"年度大会员","label_theme":"annual_vip","text_color":"#FFFFFF","bg_style":1,"bg_color":"#FB7299","border_color":"","use_img_label":true,"img_label_uri_hans":"","img_label_uri_hant":"","img_label_uri_hans_static":"https://i0.hdslb.com/bfs/vip/8d4f8bfc713826a5412a0a27eaaac4d6b9ede1d9.png","img_label_uri_hant_static":"https://i0.hdslb.com/bfs/activity-plat/static/20220614/e369244d0b14644f5e1a06431e22a4d5/VEW8fCC0hg.png"},"avatar_subscript":1,"nickname_color":"#FB7299","role":3,"avatar_subscript_url":"","tv_vip_status":0,"tv_vip_pay_type":0,"tv_due_date":0,"avatar_icon":{"icon_type":1,"icon_resource":{}}},"answer_status":0,"block_time":0,"role":"0","last_play_time":-1000,"last_play_cid":1560156670,"now_time":1726370540,"online_count":1,"need_login_subtitle":false,"subtitle":{"allow_submit":false,"lan":"","lan_doc":"","subtitles":[{"id":1497922385058359296,"lan":"ai-zh","lan_doc":"中文(自动生成)","is_lock":false,"subtitle_url":"//aisubtitle.hdslb.com/bfs/ai_subtitle/prod/18552159371560156670a544e45bb1c1fcbc749444766bcfdce1?auth_key=1726370540-6200821378ad42a7a48c21fe4b226486-0-5b557de4cbb342c3e46e5f78c068b28f","type":1,"id_str":"1497922385058359296","ai_type":0,"ai_status":2}]},"view_points":[],"preview_toast":"为创作付费,购买观看完整视频|购买观看","options":{"is_360":false,"without_vip":false},"guide_attention":[{"type":1,"from":66,"to":71,"pos_x":333.5,"pos_y":243.75}],"jump_card":[],"operation_card":[],"online_switch":{"enable_gray_dash_playback":"500","new_broadcast":"1","realtime_dm":"1","subtitle_submit_switch":"1"},"fawkes":{"config_version":30787,"ff_version":21289},"show_switch":{"long_progress":false},"bgm_info":null,"toast_block":false,"is_upower_exclusive":false,"is_upower_play":false,"is_ugc_pay_preview":false,"elec_high_level":{"privilege_type":0,"title":"","sub_title":"","show_button":false,"button_text":"","jump_url":"","intro":"","new":false},"disable_show_up_info":false}}

它的data.subtitle.subtitles就是字幕链接,这个需要 COOKIE,否则为空。

		j = requests.get(url, headers=hdrs).json()subtitles = j['data']['subtitle']['subtitles']prefs = [s for s in subtitles if s['lan'] in ['ai-zh', 'zh']]if not prefs:print(f'{fname} 无可用字幕')returnurl = 'https:' + prefs[0]['subtitle_url']sub =  requests.get(url, headers=hdrs).json()

提取出来的 JSON 格式是这样:

{"font_size": 0.4,"font_color": "#FFFFFF","background_alpha": 0.5,"background_color": "#9C27B0","Stroke": "none","type": "AIsubtitle","lang": "zh","version": "v1.7.0.4","body": [{"from": 1.86,"to": 4.46,"sid": 1,"location": 2,"content": "那你们有没有背着露露","music": 0.0},{"from": 5.82,"to": 13.25,"sid": 2,"location": 2,"content": "偷偷的偷偷的看一些不该看的东西呢","music": 0.0},{"from": 15.759,"to": 17.999,"sid": 3,"location": 2,"content": "啊我猜一定有吧","music": 0.0},{"from": 19.319,"to": 23.999,"sid": 4,"location": 2,"content": "是不是有就没有背着我偷偷看些什么吗","music": 0.0},{"from": 32.0,"to": 35.0,"sid": 5,"location": 2,"content": "可是你们的房间","music": 0.0},<...>]
}

写个代码转 SRT:

def float2hhmmss(num):int_ = int(num)frac = int((num - int_) * 1000)hr, min_, sec = int_ // 3600, int_ % 3600 // 60, int_ % 60return f'{hr}:{min_:02d}:{sec:02d}.{frac:03d}'def bilisub2srt(j):subs = j['body']srts = []for i, sub in enumerate(subs, start=1):st = float2hhmmss(sub['from'])ed = float2hhmmss(sub['to'])txt = sub['content']srtpt = f'{i}\n{st} --> {ed}\n{txt}'srts.append(srtpt)srt = '\n\n'.join(srts)return srt

结果:

1
0:00:01.860 --> 0:00:04.459
那你们有没有背着露露2
0:00:05.820 --> 0:00:13.250
偷偷的偷偷的看一些不该看的东西呢3
0:00:15.759 --> 0:00:17.998
啊我猜一定有吧4
0:00:19.318 --> 0:00:23.998
是不是有就没有背着我偷偷看些什么吗5
0:00:32.000 --> 0:00:35.000
可是你们的房间<...>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/797538.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

k8s Service 服务

目录一、为什么需要 Service二、Kubernetes 中的服务发现与负载均衡 -- Service三、用例解读1、Service 语法2、创建和查看 Service四、Headless Service五、集群内访问 Service六、向集群外暴露 Service七、操作示例1、获取集群状态信息2、创建 Service、Deployment3、创建客户…

获取动态页面html

AJAX AJAX(异步JavaScript和XML)是一种无需重新加载整个页面的情况下,与服务器交换数据,将增量信息局部更新在用户界面上的技术。AJAX具有异步性,AJAX请求不会阻塞用户界面,用户可以在请求处理的同时继续与页面交互,具有更强的交互性。AJAX能使网页从浏览器请求少量信息…

V-By-One协议详解

V-By-One协议详解 V-By-One协议简介 V-by-One是一种高速串行接口技术,由日本赛恩电子公司(THine Electronics)开发,主要用于平板显示器的信号传输。它旨在替代传统的LVDS(Low Voltage Differential Signaling)技术,提供更高的传输速率和更低的功耗。 V-By-One协议特点及…

(2)Proteus8.7添加STM32F103C6直接使用编译xxx.hex文件关键步骤

1)新建工程中选项 2)Protues8.7支持芯片如下:3)点击STM32选择 Keil编译生成的 xxx.hex文件 4)使用virtual terminal显示串口信息。仿真状态,点击Debug菜单项,按图操作。

AI 框架作用是什么?

AI 框架作用 深度学习范式主要是通过发现经验数据中,错综复杂的结构进行学习。通过构建包含多个处理层的计算模型(网络模型),深度学习可以创建多个级别的抽象层来表示数据。例如,卷积神经网络 CNN 可以使用大量图像进行训练,例如对猫狗分类去学习猫和狗图片的特征。这种类…

分布式学习:Raft算法以及具体实现

Raft算法 一致性算法的要求:安全性,网络延迟、分区、丢包、重复和乱序等错误需要保证正确 可用性:集群中只需要大多数机器即可运行 不依赖时序保证一致性三种状态:follower,candidate,leader 任期:逻辑时钟的作用,每一段任期从一次选举开始分票可能会导致一个任期没有l…

通过API接口获取下来的数据需要怎样应用?

在当今数字化时代,通过API接口获取数据已成为企业获取、处理和分析信息的重要手段。API接口不仅能够提高数据交互的效率,还能促进数据的安全性和灵活性。以下是如何将通过API接口获取的数据有效应用的一些方法和策略。数据整合与分析 企业可以通过API接口将不同来源的数据整合…

OpenCore Legacy Patcher 2.0.0 发布,83 款不受支持的 Mac 机型将能运行最新的 macOS Sequoia

OpenCore Legacy Patcher 2.0.0 发布,83 款不受支持的 Mac 机型将能运行最新的 macOS Sequoia在不受支持的 Mac 上安装 macOS Sequoia (OpenCore Legacy Patcher v2.0.0) Install macOS on unsupported Macs 请访问原文链接:https://sysin.org/blog/install-macos-on-unsuppo…

校园食堂明厨亮灶智能视频监控

校园食堂明厨亮灶智能视频监控对餐厅摄像头拍照视频监控画面进行实时分析,校园食堂明厨亮灶智能视频监控针对厨师不穿厨师服、不戴厨师帽口罩、陌生人员进入后厨、厨师工作时间玩手机打电话、后厨出现猫狗老鼠等异常行为现象,系统会自动识别抓拍报警,进而实现食品卫生安全日…

.NET 的 Native AOT 现在是什么样的?

今天要写的这篇文章源自昨天在朋友圈发的文章《UWP 通过 .NET 9 和Native AOT 的支持实现 UWP 应用的现代化》[1],一位小伙伴的对话让我想全面梳理下Native AOT的现在的进展。.NET 9 的 Native AOT(Ahead-of-Time Compilation)是微软在.NET 9版本中重点发展的一项技术,旨在提…

工地车辆未冲洗识别抓拍系统

工地车辆未冲洗识别抓拍系统主要是对施工工地的出入的车辆进行冲洗监管、冲洗识别、未冲洗告警。工地车辆未冲洗识别抓拍系统 由现场监控摄像头与后台系统构成。利用前端摄像头(不分品牌)正对施工工地进出口对来往车辆实时分析识别清洗情况,将违规未清洗车辆,抓拍报警,并上…

秸秆焚烧视频监控系统

秸秆焚烧视频监控系统借助现场已经安装的视频监控摄像头,运用边缘+Ai视觉、深度学习、视频ai分析技术,对监控地区的秸秆燃烧行为进行7*24小时不间断识别监控。秸秆焚烧视频监控系统自动识别现场出现烟火时,自动生成预警信息发送到监控后台中心提醒工作人员及时确认,并能够及…