小白尝试在 Windows 用 you-get 批量下载 b 站下载有声小说的整个过程

2022-06-09 19:19:18 +08:00
 huntagain2008
https://www.v2ex.com/t/803406
小白一开始是 Win10-WSL-ubuntu 用 you-get 、BashShell 批量下载。太过重量级,网上搜的资料是

> https://blog.csdn.net/u010378992/article/details/105180742
使用 you-get 批量下载 B 站视频

文章分类在 Python 爬虫。第一步安装 you-get 遇到问题,在 Windows 各种报错,小白什么都不懂
> https://github.com/soimort/you-get/wiki/%E4%B8%AD%E6%96%87%E8%AF%B4%E6%98%8E
you-get 中文说明

> 选项 2: 使用预装包(仅供 Windows)
exe (单独文件) 或 7z (包括所有依赖) 可从 https://github.com/soimort/you-get/releases/latest 下载.

releases 没有 7z 或 exe , 在网上搜到 exe 文件,报 Http Error with code404, 是版本低了。看到 releases 有 you_get-0.4.1612-py3-none-any.whl ,可是我不认识它。 对其解压,看到了源代码,但是不知道如何使用。搜索 windows 安装 whl ,看到这个网页

> https://www.lfd.uci.edu/~gohlke/pythonlibs/
Unofficial Windows Binaries for Python Extension Packages

https://www.pypy.org/download.html
看上面的教程,尝试下载了 zip 文件 PyPy3.8 然后解压,在该目录 shift 右键菜单打开命令行

> https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels
py -m pip install SomePackage-1.0-py2.py3-none-any.whl

用 python3 -m pip install you_get-0.4.1612-py3-none-any.whl ,提示没有安装 pip ,用
python3 -m ensurepip 安装 pip 。再次 py -m pip install you_get-0.4.1612-py3-none-any.whl ,终于 you-get 装好了。

可是 you-get.exe 在哪里啊?我不知道,我只好写 python 脚本,然后 python3 zy_download.py 运行
```python
import sys
from you_get import common as you_get

directory = 'D:\MyVideos'
url = "https://www.bilibili.com/video/xxxx/xxxxx'
sys.argv = ['you-get', 'l', '-o', directory, url]

you_get.main()
```
下载速度只有 12kb/s 。添加 --format=dash-flv360 下载变快,但是视频分成两段,依赖 ffmpeg 合并视频。于是下载 ffmpeg 的 zip 文件并设置环境变量。
下载到 294 集忽然卡住了,被我终止了。最后在 PyPy3.8/Scripts/ 意外找到了 you-get.exe ,于是写批处理将剩下的 6 集也下载了
```msdos
@echo off
for /f "delims=," %%i in (url_list.txt) do (
you-get -o D:\MyVideos %%i
)
pause
```

最后用菲菲更名宝贝 FFRename Professional 批量重命名,用 ffmpeg 将 mp4 转为 aac 音轨,再通过 VLC 播放器的 WIFI 共享功能上传到手机。大功告成。
1791 次点击
所在节点    分享创造
12 条回复
linglin0924
2022-06-09 23:31:29 +08:00
有声小说的地址发一下,看看怎么样
jingfelix
2022-06-10 00:13:18 +08:00
你可能需要这个?
https://github.com/jingfelix/BiliFM
可以下载指定 up 主全部视频的音频为 mp3 ,不需要 ffmpeg 。
huntagain2008
2022-06-10 08:05:22 +08:00
@linglin0924 我只是把有声小说当听歌而已,完全是动漫流行什么我就听什么小说,《凡人修仙传》我听的大灰狼的,感觉韩立这个角色还是这个主播的声音比较合适,当然我没听过其他的主播。
huntagain2008
2022-06-10 09:13:02 +08:00
@jingfelix #2 在 kubuntu 用了 BilibiliAudioDownloader 下载正在听的一集,mp3 大小 5.3MB,aac 音频大小 5.6MB,aac 音频时长 21:44,mp3 时长 21:50 。批量下载多 P 视频结果只剩下一个视频。至于作者你的作品我还没试过,看了下代码好像没有有关视频中的某一 P 的音频下载。
twofox
2022-06-10 10:36:33 +08:00
you-get ?
twofox
2022-06-10 10:36:51 +08:00
和 youtube-dl 什么关系
huntagain2008
2022-06-10 10:40:07 +08:00
@twofox #6 应该没关系。以前听播客倒是听到过嘉宾提 起 youtube-dl 下载速度更快
jingfelix
2022-06-10 12:54:57 +08:00
@huntagain2008 嗯,确实没有考虑分 p 的问题,下周改一下。
刚刚看了看,https://github.com/yutto-dev/yutto 应该可以支持分 p 视频 + 只下载音频。
zhandouji
2022-06-12 07:27:41 +08:00
用 ubuntu 的 you-get 非常容易
huntagain2008
2022-06-24 09:03:34 +08:00
BilibiliAudioDownloader 分 P 下载音频 文件名是同一个,所以最后下载的音频都被覆盖了。我改了一下代码
BVList=['BV1t54y1r75y-1', 'BV1t54y1r75y-2', 'BV1t54y1r75y-3']
这个 list 首先知道要下载视频的 BV 号也就是 BV1t54y1r75y ,后面加 分 P 号,也就是-1 。因为我要下载 100 个 P 的音频,所以我总不能一个个输入-1 ,-2 ,-3 。先用 Python 生成列表
>>> l = []
>>> BVList = []
>>> for i in range(1, 201):
... BVList.append('BV1t54y1r75y-' + str(i))
...
>>> BVList
['BV1t54y1r75y-1', 'BV1t54y1r75y-2', 'BV1t54y1r75y-3', ...]

def getCidAndTitle(bvid,p=1):
url='https://api.bilibili.com/x/web-interface/view?bvid='+bvid
data=requests.get(url).json()['data']
title=data['title'] + str(p)
cid=data['pages'][p-1]['cid']
return str(cid),title

原代码 title=data['title']被我改为 title=data['title'] + str(p),加了分 P 。这样下载 100 个分 P 的视频就没问题了。
huntagain2008
2022-06-24 09:04:58 +08:00
@huntagain2008 改下 for i in range(1,101):
huntagain2008
2022-07-19 09:26:40 +08:00
@huntagain2008 #10 KDE 的 Konsole 打印的列表可以直接拷贝,但是在 Windows 的 cmd 命令行拷贝出来的列表有换行问题,代码会报错。可以用 > BVList 输出到文件再用记事本打开。而在 Python3 中的实现是

#!/usr/bin/env python3
# 根据 B 站 BV 号下载第 1501 到 1631 集,对应分 P 101 到 230 ,输出到文件 BV1501-1631.txt 。
# 输出的文件内容如:['BV18a4y1s7Jx-101','BV18a4y1s7Jx-102', ...]
#

BVList = []

for i in range(101, 231):
缩进 BVList.append("BV18a4y1s7Jx-" + str(i))

MyFile = open('BV1501-1631.txt', 'w')

print(BVList, file=MyFile)

MyFile.close()

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/858511

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX