鱼C论坛

 找回密码
 立即注册
查看: 4660|回复: 178

[技术交流] 【Python】爬取B站视频 GUI Edition

  [复制链接]
发表于 2021-2-6 22:35:09 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
本帖最后由 qiuyouzhi 于 2021-2-8 16:27 编辑

爬取B站视频 GUI Edition


使用的第三方库:

requests - 爬取 B 站 API 接口
easygui - 一些小功能,比如选择下载日志的保存位置等。
danmaku2ass - 把格式为 .xml 的弹幕文件转换为 .ass 字幕文件
链接:https://github.com/m13253/danmaku2ass

界面:

img.png
img.png
img.png

使用教程:

1,设置下载参数

运行main.py,点击 菜单 - 文件 - 下载选项设置

在第一栏中输入 BV 或者 AV 号,其他的都可以不输。

默认为不下载弹幕,若需要,请在对应栏输入 Y / y 。

最末一栏是下载位置,默认为代码所在目录的 Video 文件夹(若没有会自动进行创建)

设置完成后,点击左下方的 "完成" 按钮,完成设置。

2,正式下载视频

基本的参数已经设置好了,接下来只需要点击左下方的 "运行" 按钮运行程序即可。

左半部分的 Text 组件是日志,会显示下载进行程度。

右半部分则是视频和视频作者的信息。我认为需要显示的就这么多,如果有需要各位可以提下意见。

视频会保存到你指定的保存位置去。

3,播放带弹幕的视频

首先播放视频。

随后,将字幕文件(名称为 {视频名称}.ass)拖入播放器窗口,即可播放视频。

效果:

img.png

代码下载:

Update:
修复下载BUG,优化用户体验

游客,如果您要查看本帖隐藏内容请回复

评分

参与人数 9荣誉 +34 鱼币 +32 贡献 +26 收起 理由
帅哥小虾米 + 1 鱼C有你更精彩^_^
allearn_Python + 5 + 5 + 3 鱼C有你更精彩^_^
lp17863564 + 3
糖甜弯了嘴 + 3 + 3 + 3 感谢楼主无私奉献!
Daniel_Zhang + 5 + 5 + 3 楼主牛哇
aaron.yang + 4 + 3
昨非 + 5 + 5 + 3 鱼C有你更精彩^_^
不二如是 + 6 + 6 + 6 鱼C有你更精彩^_^
Twilight6 + 5 + 5 + 5 鱼C有你更精彩^_^

查看全部评分

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2021-2-7 09:15:59 | 显示全部楼层
@不二如是 申精~
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-7 11:09:40 | 显示全部楼层


赞~!

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-7 11:41:59 | 显示全部楼层
GUI 介意加一个作者署名吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2021-2-7 11:42:57 | 显示全部楼层
不二如是 发表于 2021-2-7 11:41
GUI 介意加一个作者署名吗

没问题鸭
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2021-2-7 11:49:54 | 显示全部楼层
不二如是 发表于 2021-2-7 11:41
GUI 介意加一个作者署名吗

加好了,您帮忙看一下对不对呗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-7 19:45:26 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-7 20:30:01 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-8 10:58:09 | 显示全部楼层
学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
头像被屏蔽
发表于 2021-2-8 11:18:19 | 显示全部楼层
1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-8 12:59:19 | 显示全部楼层
学习学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-9 12:07:21 | 显示全部楼层
好家伙
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-9 17:03:24 | 显示全部楼层
学习一下,谢谢up
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2021-2-9 17:08:00 | 显示全部楼层
GlacierGao 发表于 2021-2-9 17:03
学习一下,谢谢up

我不是up..
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-9 17:34:54 | 显示全部楼层
牛牛牛
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-9 19:59:39 | 显示全部楼层
输入BV号点运行没效果
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-9 20:00:38 | 显示全部楼层
报错:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-4:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-5:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-6:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-7:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
Exception in thread     Thread-8aid = self.DBV.BV_to_AV(BV):

Traceback (most recent call last):
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
        bv[8] *= 58self.run()

IndexError  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
:     list index out of rangeself._target(*self._args, **self._kwargs)

  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
Exception in thread   File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
Thread-9    :
bv[8] *= 58Traceback (most recent call last):

  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
IndexError    : self.run()list index out of range

  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-10:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-11:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-12:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-13:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
Exception in thread Thread-14:
Traceback (most recent call last):
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\lenovo\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lenovo\Desktop\B站视频下载器\main.py", line 74, in main
    aid = self.DBV.BV_to_AV(BV)
  File "C:\Users\lenovo\Desktop\B站视频下载器\get_video.py", line 38, in BV_to_AV
    bv[8] *= 58
IndexError: list index out of range
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2021-2-9 20:10:54 | 显示全部楼层
嘉岳呀 发表于 2021-2-9 19:59
输入BV号点运行没效果

是不是报错了?
截图看下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2021-2-9 20:27:26 | 显示全部楼层
qiuyouzhi 发表于 2021-2-9 20:10
是不是报错了?
截图看下

报错正在审核
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
 楼主| 发表于 2021-2-9 20:46:43 | 显示全部楼层

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1

GMT+8, 2021-8-3 15:06

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表