mirror of
https://github.com/JefferyHcool/BiliNote.git
synced 2026-09-07 00:27:37 +08:00
Merge pull request #427 from pumpkinperson996/fix/youtube-format-not-available
fix(youtube): 修复 YouTube 笔记生成失败 "Requested format is not available"
This commit is contained in:
@@ -58,12 +58,15 @@ def apply_bilibili_dm_img_patch() -> bool:
|
||||
if getattr(original, '_bili_dm_patched', False):
|
||||
return True
|
||||
|
||||
def _patched_download_playinfo(self, bvid, cid, headers=None, query=None):
|
||||
def _patched_download_playinfo(self, bvid, cid, headers=None, query=None, **kwargs):
|
||||
# dm_* are merged into the query that the original method signs via
|
||||
# _sign_wbi; caller-supplied query params (e.g. try_look/qn) take
|
||||
# precedence over the injected dummies.
|
||||
# **kwargs stays open on purpose: yt-dlp keeps adding parameters to
|
||||
# _download_playinfo (2026.x added `fatal`), and a wrapper that pins the
|
||||
# signature turns every such addition into a TypeError at download time.
|
||||
merged_query = {**build_dm_img_params(), **(query or {})}
|
||||
return original(self, bvid, cid, headers=headers, query=merged_query)
|
||||
return original(self, bvid, cid, headers=headers, query=merged_query, **kwargs)
|
||||
|
||||
_patched_download_playinfo._bili_dm_patched = True
|
||||
BilibiliBaseIE._download_playinfo = _patched_download_playinfo
|
||||
|
||||
@@ -55,6 +55,10 @@ class YoutubeDownloader(Downloader, ABC):
|
||||
|
||||
if skip_download:
|
||||
ydl_opts['skip_download'] = True
|
||||
# 只取元信息时并不需要媒体流。yt-dlp 版本落后于 YouTube player 时,
|
||||
# nsig 解析失败会导致所有音视频格式被丢弃,此时格式选择会抛
|
||||
# "Requested format is not available",把一个已经拿到字幕的任务带崩。
|
||||
ydl_opts['ignore_no_formats_error'] = True
|
||||
|
||||
_apply_proxy(ydl_opts)
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||
@@ -63,7 +67,8 @@ class YoutubeDownloader(Downloader, ABC):
|
||||
title = info.get("title")
|
||||
duration = info.get("duration", 0)
|
||||
cover_url = info.get("thumbnail")
|
||||
ext = info.get("ext", "m4a")
|
||||
# skip_download 时 yt-dlp 返回 ext=None,默认值不会生效,避免拼出 "xxx.None"
|
||||
ext = info.get("ext") or "m4a"
|
||||
audio_path = os.path.join(output_dir, f"{video_id}.{ext}")
|
||||
|
||||
return AudioDownloadResult(
|
||||
|
||||
Reference in New Issue
Block a user