提取B站视频教程详情
背景
B站这个视频列表是真的体验感太差了,有时候想把章节复制下来,再对应的章节下面做笔记,实在是太难搞了,于是就有了这篇文文章
效果图
根据关键字获取视频id
public Result videoList(@RequestBody VideoDto videoDto) {
String keyword = videoDto.getKeyword();
if (!StringUtils.hasText(keyword)) {
return R.error(500,"keyword 不能为空");
}
String cookie = videoDto.getCookie();
if (!StringUtils.hasText(cookie)) {
cookie = this.cookie;
}
String url = "https://api.bilibili.com/x/web-interface/wbi/search/all/v2?__refresh__=true&_extra=&context=&page=1&page_size=42&order=&duration=&from_source=&from_spmid=333.337&platform=pc&highlight=1&single_column=0&qv_id=f2n7O2fSac731PnjjNFHUAGTYrY8wN84&ad_resource=5646&source_tag=3&web_location=1430654&w_rid=8b093eac9dbe20f09fb6b7bf3a51a743&wts=1710225740&keyword=" + keyword;
HttpHeaders headers = new HttpHeaders();
headers.add("Cookie", cookie);
headers.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36");
HttpEntity<Object> entity = new HttpEntity<>(null, headers);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
String body = exchange.getBody();
JSONArray results = JSON.parseObject(body).getJSONObject("data").getJSONArray("result");
List<VideoVo> list = new ArrayList<>();
for (int i = 0; i < results.size(); i++) {
JSONObject result = results.getJSONObject(i);
if ("video".equals(result.getString("result_type"))) {
JSONArray array = result.getJSONArray("data");
for (int j = 0; j < array.size(); j++) {
JSONObject object = array.getJSONObject(j);
String id = object.getString("id");
String title = object.getString("title").replace("<em class=\"keyword\">", "").replace("</em>", "");
System.out.println(id + "\t" + title);
VideoVo videoVo = new VideoVo();
videoVo.setId(id);
videoVo.setTitle(title);
list.add(videoVo);
}
}
}
return R.ok(list);
}
418313932 【2022B站最好的OpenCV课程推荐】OpenCV从入门到实战 全套课程(附带课程课件资料+课件笔记)图像处理|深度学习人工智能计算机视觉python+AI
314395310 太厉害了 已跪!终于有人能把OpenCV图像处理讲的这么通俗易懂了,现在计算机视觉opencv全套分享给大家。
1615 OpenCV轻松入门(李立宗)
1201468793 太详细了!从OpenCV安装到图像处理操作实战,张老师是真的把计算机视觉给讲透了!整整一百集,拿走不谢!——人工智能/机器学习/深度学习/神经网络/目标检测
839144359 OpenCV4 C++ 快速入门视频30讲 - 系列合集
382304059 【不要再看那些过时的OpenCV老教程了】2022巨献,OpenCV零基础小白最新版全套教程(人工智能机器视觉教程)
373921350 黑马程序员人工智能教程_10小时学会图像处理OpenCV入门教程
815748375 计算机视觉入门到精通!公认讲的最好的【OpenCV计算机视觉教程】同济大佬12小时带你从入门到精通!图像处理|深度学习人工智能计算机视觉Python+AI
...
获取视频详情
@Test
public Result<String> videoDetails(@PathVariable String id) {
String url = "https://api.bilibili.com/x/web-interface/wbi/view/detail?aid=" + id;
HttpHeaders headers = new HttpHeaders();
headers.add("Cookie", cookie);
headers.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36");
HttpEntity<Object> entity = new HttpEntity<>(null, headers);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
String body = exchange.getBody();
System.out.println("body = " + body);
JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONObject("View").getJSONArray("pages");
StringBuilder builder = new StringBuilder();
for (int i = 0; i < jsonArray.size(); i++) {
String title = jsonArray.getJSONObject(i).getString("part");
System.out.println(title);
builder.append(title).append("\n");
}
return R.ok(builder.toString());
}
传入上一步获取到的视频id=314395310即可得到对应的视频详情
1-2 OpenCV导学
1-3 计算机视觉到底是什么
2-1 Mac下命令方式搭建OpenCV开发环境(加片头)
2-2 Windows下搭建OpenCV开发环境
2-3 Ubuntu下搭建OpenCV开发环境
2-4 Windows下源码方式编译OpenCV
2-5 Windows下C++使用OpenCV库
2-6 如何利用工具高效开发OpenCV
3-1 明晰课程项目
3-2 如何通过OpenCV创建显示窗口
3-3 如何通过OpenCV加载显示图片
3-4 两招解决OpenCV加载图片问题
3-5 如何通过OpenCV保存文件
3-6 如何利用OpenCV从摄像头采集视频
3-7 如何从多媒体文件中读取视频帧
3-8 如何将视频数据录制成多媒体文件
3-9 代码优化
3-10 OpenCV控制鼠标
3-11 OpenCV中的TrackBar控件
3-12 实战TrackBar的使用
4-1 RGB与BGR【OpenCV的色彩空间】
4-2 HSV与HSL【OpenCV的色彩空间】
4-3 实战OpenCV色彩空间转换
4-4 图像操作的基石Numpy【基础操作】
4-5 Numpy基本操作之矩阵的检索与赋值
4-6 Numpy基本操作三-ROI
4-8 OpenCV的重要结构体Mat
4-9 Mat的深拷贝与浅拷贝
4-11 图像的多种属性
4-12 通道的分割与合并
5-1 OpenCV绘制直线
5-2 OpenCV椭圆的绘制
5-3 OpenCV椭圆的绘制
5-4 OpenCV绘制多边形
5-5 OpenCV绘制文本
5-6 OpenCV大作业-实现鼠标绘制基本图形
5-7 OpenCV基本图形绘制小结
6-1 图像的加法运算
6-2 图像的减法运算
6-3 图像的溶合
6-4 OpenCV位运算-非操作
6-5 OpenCV位操作-与运算
6-6 OpenCV位操作-或与异或
6-7 大作业-为图像添加水印
7-1 图像的放大与缩小
7-2 图像的翻转
7-3 图像的旋转
7-4 仿射变换之图像平移
7-5 仿射变换之获取变换矩阵
7-6 仿射变换之变换矩阵之二
7-7 OpenCV透视变换
8-1 图像滤波
8-2 卷积相关概念
8-3 实战图像卷积
8-4 方盒滤波与均值滤波
8-5 高斯滤波
8-6 中值滤波
8-7 双边滤波
8-8 高通滤波-索贝尔算子
8-9 高通滤波-沙尔算子
8-10 高通滤波-拉普拉斯算子
8-11 边缘检测Canny
9-1 形态学概述
9-2 图像全局二值化
9-3 阈值类型
9-4 自适应阈值二值化
9-5 OpenCV腐蚀
9-6 获取形态学卷积核
9-7 OpenCV膨胀
9-8 开运算
9-9 闭运算
9-10 形态学梯度
9-11 顶帽运算
9-12 黑帽操作
10-1 什么是图像轮廓
10-2 查找轮廓
10-3 绘制轮廓
10-4 轮廓的面积与周长
10-5 多边形逼近与凸包
10-6 外接矩形
10-7 项目总览【车辆统计】
10-8 视频加载【车辆统计】
10-9 形态学处理【车辆统计】
10-10 去背景【车辆统计】
10-11 逻辑处理【车辆统计】
10-12 显示信息【车辆统计】
11-1 特征检测的基本概念
11-2 Harris角点检测
11-3 Shi-Tomasi角点检测
11-4 SIFT关键点检测
11-5 SIFT计算描述子
11-6 SURF特征检测
11-7 OBR特征检测
11-8 暴力特征匹配
11-9 FLANN特征匹配
11-10 实战flann特征匹配
11-11 图像查找
11-12 大作业-图像拼接基础知识
11-13 大作业-图像拼接(一)
完整Controller代码
package com.lxw.station.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lxw.station.core.R;
import com.lxw.station.core.Result;
import com.lxw.station.entity.VideoDto;
import com.lxw.station.entity.VideoVo;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
@RestController
public class VideoController {
private String cookie = "_uuid=9DF4F2F2-47B9-22B6-F59A-A8C10C658393265297infoc; enable_web_push=undefined; header_theme_version=undefined; buvid_fp=0f14aff6726a04789db0ba942ba1317c; buvid3=C4518348-C136-256A-F660-38EA96D4971D49657infoc; b_nut=1708214666; buvid4=1010A954-10E9-D08B-82EF-1278035AD2E749657-024021800-Da1Cmh2s4TKHhBvxWnSrMg%3D%3D; CURRENT_FNVAL=4048; rpdid=|(kYl|~u)R)J0J'u~|)kuRY~Y; PVID=1; DedeUserID=702211544; DedeUserID__ckMd5=165187cda1b9f075; CURRENT_QUALITY=80; FEED_LIVE_VERSION=undefined; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MTAzNzQxMjcsImlhdCI6MTcxMDExNDg2NywicGx0IjotMX0.YzPhgcDhiKBMZCQmvf9r_6shc7teaF2F6r4ZFgk4g9w; bili_ticket_expires=1710374067; SESSDATA=bc98694a%2C1725666928%2Cce14a%2A31CjCxI-6GYnUODm_8y4XiweKv272zq5odBHxEmsuMnRW9nTgEThHMdZmEZM-mZvcQowoSVlE2ZWItWmROUGtVcXFTZkVlYmhmdDdnbTktZF9scVZpb3c1UzNJNXlsZGZvN3U0cWtGYS1FSXU4N0VZN041UkJYWEhJNDJKQktFTzVBZTBXSEw0WERRIIEC; bili_jct=a23627e4e9d952ba26cfcc0209ce39e0; sid=7yv3ysp0; bp_video_offset_702211544=907118997271478357; home_feed_column=4; b_lsid=BF6A57A2_18E312A1978; browser_resolution=1275-1279";
private RestTemplate restTemplate = new RestTemplate();
@PostMapping("/videoList")
public Result videoList(@RequestBody VideoDto videoDto) {
String keyword = videoDto.getKeyword();
if (!StringUtils.hasText(keyword)) {
return R.error(500,"keyword 不能为空");
}
String cookie = videoDto.getCookie();
if (!StringUtils.hasText(cookie)) {
cookie = this.cookie;
}
String url = "https://api.bilibili.com/x/web-interface/wbi/search/all/v2?__refresh__=true&_extra=&context=&page=1&page_size=42&order=&duration=&from_source=&from_spmid=333.337&platform=pc&highlight=1&single_column=0&qv_id=f2n7O2fSac731PnjjNFHUAGTYrY8wN84&ad_resource=5646&source_tag=3&web_location=1430654&w_rid=8b093eac9dbe20f09fb6b7bf3a51a743&wts=1710225740&keyword=" + keyword;
HttpHeaders headers = new HttpHeaders();
headers.add("Cookie", cookie);
headers.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36");
HttpEntity<Object> entity = new HttpEntity<>(null, headers);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
String body = exchange.getBody();
JSONArray results = JSON.parseObject(body).getJSONObject("data").getJSONArray("result");
List<VideoVo> list = new ArrayList<>();
for (int i = 0; i < results.size(); i++) {
JSONObject result = results.getJSONObject(i);
if ("video".equals(result.getString("result_type"))) {
JSONArray array = result.getJSONArray("data");
for (int j = 0; j < array.size(); j++) {
JSONObject object = array.getJSONObject(j);
String id = object.getString("id");
String title = object.getString("title").replace("<em class=\"keyword\">", "").replace("</em>", "");
System.out.println(id + "\t" + title);
VideoVo videoVo = new VideoVo();
videoVo.setId(id);
videoVo.setTitle(title);
list.add(videoVo);
}
}
}
return R.ok(list);
}
@GetMapping("/videoDetails/{id}")
public Result<String> videoDetails(@PathVariable String id) {
String url = "https://api.bilibili.com/x/web-interface/wbi/view/detail?aid=" + id;
HttpHeaders headers = new HttpHeaders();
headers.add("Cookie", cookie);
headers.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36");
HttpEntity<Object> entity = new HttpEntity<>(null, headers);
ResponseEntity<String> exchange = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
String body = exchange.getBody();
System.out.println("body = " + body);
JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONObject("View").getJSONArray("pages");
StringBuilder builder = new StringBuilder();
for (int i = 0; i < jsonArray.size(); i++) {
String title = jsonArray.getJSONObject(i).getString("part");
System.out.println(title);
builder.append(title).append("\n");
}
return R.ok(builder.toString());
}
}
前端核心代码
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>首页</title>
<style>
/*找到html标签、body标签,和挂载的标签 都给他们统一设置样式*/
html, body, #app, .el-container {
/*设置内部填充为0,几个布局元素之间没有间距*/
padding: 0px;
/*外部间距也是如此设置*/
margin: 0px;
/*统一设置高度为100%*/
height: 100%;
}
.el-header {
background-color: #B3C0D1;
line-height: 25px;
}
el-aside {
background-color: #D3DCE6;
color: #333;
}
.el-main {
background-color: #E9EEF3;
color: #333;
}
.code-container {
position: relative;
}
.code {
background-color: #f4f4f4;
font-family: 'Microsoft YaHei', sans-serif;;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
}
.copy-button {
position: absolute;
top: 5px;
right: 5px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 3px;
padding: 5px 10px;
cursor: pointer;
}
</style>
<script src="/js/vue.js"></script>
<script src="/js/vue-router.js"></script>
<link rel="stylesheet" href="/css/el/index.css">
<script src="/js/el/index.js"></script>
<script type="text/javascript" src="/js/axios/index.js"></script>
<script type="text/javascript" src="/api/ajax.js"></script>
<script src="js/marked/marked.js"></script>
</head>
<body>
<div id="app">
<el-container height>
<el-header>
<el-row style="margin-top: 10px">
<el-col :span="3"><el-input v-model="params.keyword"><template slot="prepend">关键词</template></el-input></el-col>
<el-col :span="18"><el-input v-model="params.cookie"><template slot="prepend">Cookie</template></el-input></el-col>
<el-col :span="3"></el-col><el-button @click="videoList" :loading="generateLoading">获取视频列表</el-button></el-input></el-col>
</el-row>
</el-header>
<el-container>
<el-main>
<el-table :data="list" highlight-current-row @current-change="videoDetails" empty-text="暂无数据" style="width: 100%">
<el-table-column type="index" width="50"></el-table-column>
<el-table-column property="id" label="id" width="120"></el-table-column>
<el-table-column property="title" label="title"></el-table-column>
</el-table>
</el-main>
<el-aside width="600px">
<div class="code-container" v-show="details != null && details != ''">
<pre class="code" id="codeSnippet">
<code style="font-family: 'Microsoft YaHei', sans-serif">
{{details}}
</code>
</pre>
<button class="copy-button" @click="copyCode()">{{copyButtonText}}</button>
</div>
</el-aside>
</el-container>
</el-container>
</div>
</body>
</html>
<script>
new Vue({
el: '#app',
data: function () {
return {
generateLoading: false,
params: {
cookie: '',
keyword: 'opencv'
},
list: [],
details: "",
copyButtonText:"复制"
}
},
methods: {
videoList() {
this.generateLoading = true;
axios.post('/videoList', this.params).then(res => {
if(res.data.success){
this.list = res.data.data
}else {
this.$message.error(res.data.msg)
}
}).finally(() => {
this.generateLoading = false;
})
},
videoDetails(row) {
this.generateLoading = true;
axios.get('/videoDetails/'+row.id).then(res => {
this.details = res.data.data
}).cache(()=>{
this.$message.error("获取视频详情失败")
}).finally(() => {
this.generateLoading = false;
})
},
copyCode() {
var codeElement = document.getElementById('codeSnippet');
var range = document.createRange();
range.selectNode(codeElement);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
this.copyButtonText = "已复制";
setTimeout(() =>{
console.log("定时任务开始执行")
this.copyButtonText = "复制";
}, 2000);
}
},
})
</script>
完整代码码云地址
https://gitee.com/LessAndfaster/bstation.git
运行后访问http://localhost:8088/即可
获取cookie的方法
打开B站,F12调出开发者工具,随便找个请求都可以