Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_download_url报错-404,例子:BV1jEqKY1Ei4 #873

Open
tnnnnt opened this issue Jan 1, 2025 · 1 comment
Open

get_download_url报错-404,例子:BV1jEqKY1Ei4 #873

tnnnnt opened this issue Jan 1, 2025 · 1 comment
Labels
question 这啥呀这是,我不到啊

Comments

@tnnnnt
Copy link

tnnnnt commented Jan 1, 2025

import asyncio
from bilibili_api import video, Credential, HEADERS
import httpx
import os

SESSDATA = ""
BILI_JCT = ""
BUVID3 = ""
DedeUserID = ""

# FFMPEG 路径,查看:http://ffmpeg.org/
FFMPEG_PATH = '"E:/Program Files/ffmpeg/bin/ffmpeg.exe"'


async def download_url(url: str, out: str, info: str):
	# 下载函数
	async with httpx.AsyncClient(headers=HEADERS) as sess:
		resp = await sess.get(url)
		length = resp.headers.get('content-length')
		with open(out, 'wb') as f:
			process = 0
			for chunk in resp.iter_bytes(1024):
				if not chunk:
					break

				process += len(chunk)
				print(f'下载 {info} {process} / {length}')
				f.write(chunk)


async def main():
	if os.path.exists("video.mp4"):
		os.remove("video.mp4")
	# 实例化 Credential 类
	credential = Credential(sessdata=SESSDATA, bili_jct=BILI_JCT, buvid3=BUVID3, dedeuserid=DedeUserID)
	# 实例化 Video 类
	v = video.Video(bvid="BV1jEqKY1Ei4", credential=credential)
	# 获取视频下载链接
	download_url_data = await v.get_download_url(0)
	# 解析视频下载信息
	detecter = video.VideoDownloadURLDataDetecter(data=download_url_data)
	streams = detecter.detect_best_streams()
	# 有 MP4 流 / FLV 流两种可能
	if detecter.check_flv_stream():
		# FLV 流下载
		await download_url(streams[0].url, "flv_temp.flv", "FLV 音视频流")
		# 转换文件格式
		os.system(f'{FFMPEG_PATH} -i flv_temp.flv video.mp4')
		# 删除临时文件
		# os.remove("flv_temp.flv")
	else:
		# MP4 流下载
		await download_url(streams[0].url, "video_temp.m4s", "视频流")
		await download_url(streams[1].url, "audio_temp.m4s", "音频流")
		# 混流
		os.system(f'{FFMPEG_PATH} -i video_temp.m4s -i audio_temp.m4s -vcodec copy -acodec copy video.mp4')
		# 删除临时文件
		# os.remove("video_temp.m4s")
		# os.remove("audio_temp.m4s")

	print('已下载为:video.mp4')


if __name__ == '__main__':
	# 主入口
	asyncio.get_event_loop().run_until_complete(main())

报错如下:
E:\Projects\MediaMule\GetVideo.venv\Scripts\python.exe E:\Projects\MediaMule\GetVideo\test.py
E:\Projects\MediaMule\GetVideo\test.py:66: DeprecationWarning: There is no current event loop
asyncio.get_event_loop().run_until_complete(main())
Traceback (most recent call last):
File "E:\Projects\MediaMule\GetVideo\test.py", line 66, in
asyncio.get_event_loop().run_until_complete(main())
File "E:\Program Files\py\Lib\asyncio\base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "E:\Projects\MediaMule\GetVideo\test.py", line 39, in main
download_url_data = await v.get_download_url(0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Projects\MediaMule\GetVideo.venv\Lib\site-packages\bilibili_api\video.py", line 448, in get_download_url
await Api(**api, credential=self.credential).update_params(**params).result
File "E:\Projects\MediaMule\GetVideo.venv\Lib\site-packages\bilibili_api\utils\network.py", line 170, in result
self.__result = await self.request()
^^^^^^^^^^^^^^^^^^^^
File "E:\Projects\MediaMule\GetVideo.venv\Lib\site-packages\bilibili_api\utils\network.py", line 70, in inner
return await func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Projects\MediaMule\GetVideo.venv\Lib\site-packages\bilibili_api\utils\network.py", line 332, in request
raise ResponseCodeException(code, msg, resp_data)
bilibili_api.exceptions.ResponseCodeException.ResponseCodeException: 接口返回错误代码:-404,信息:啥都木有。
{'code': -404, 'message': '啥都木有', 'ttl': 1}

Process finished with exit code 1

@tnnnnt tnnnnt added the question 这啥呀这是,我不到啊 label Jan 1, 2025
@tnnnnt
Copy link
Author

tnnnnt commented Jan 8, 2025

有人解决这个问题了吗?

@tnnnnt tnnnnt changed the title 下载视频报错-404,例子:BV1jEqKY1Ei4 get_download_url报错-404,例子:BV1jEqKY1Ei4 Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question 这啥呀这是,我不到啊
Projects
None yet
Development

No branches or pull requests

1 participant