yt-dlp / yt-dlp

A feature-rich command-line audio/video downloader
https://discord.gg/H5MNcFW63r
The Unlicense
85.45k stars 6.66k forks source link

[BiliIntl] HTTPError 412: 'Precondition Failed' #4359

Closed korongmambu closed 2 years ago

korongmambu commented 2 years ago

Checklist

Region

No response

Provide a description that is worded well enough to be understood

Unable to download because HTTPError 412

Provide verbose output that clearly demonstrates the problem

Complete Verbose Output

[debug] Command-line config: ['-vU', '--cookies-from-browser', 'firefox:~/.librewolf/0xvobvkd.al', '-F', 'https://www.bilibili.tv/en/play/37976/11411189']
[debug] Encodings: locale UTF-8, fs utf-8, pref UTF-8, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version 2022.06.29 [9d339c4]
[debug] Python 3.10.5 (CPython 64bit) - Linux-5.18.11-arch1-1-x86_64-with-glibc2.35 (glibc 2.35)
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 5.0.1 (setts), ffprobe 5.0.1, rtmpdump 2.4
[debug] Optional libraries: Cryptodome-3.12.0, certifi-2022.06.15, mutagen-1.45.1, sqlite3-2.6.0, websockets-10.3
[Cookies] Extracting cookies from firefox
[debug] Extracting cookies from: "/home/al/.librewolf/0xvobvkd.al/cookies.sqlite"
[Cookies] Extracted 13 cookies from firefox
[debug] Proxy map: {}
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
[debug] Downloading _update_spec from https://github.com/yt-dlp/yt-dlp/releases/download/2022.06.29/_update_spec
Latest version: 2022.06.29, Current version: 2022.06.29
yt-dlp is up to date (2022.06.29)
[debug] [BiliIntl] Extracting URL: https://www.bilibili.tv/en/play/37976/11411189
[BiliIntl] 11411189: Downloading webpage
WARNING: [BiliIntl] 11411189: Failed to parse JSON: Expecting ',' delimiter: line 1 column 1005 (char 1004)
[BiliIntl] 11411189: Downloading JSON metadata
[BiliIntl] 11411189: Downloading video formats
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), acodec, filesize, fs_approx, tbr, vbr, abr, asr, proto, vext, aext, hasaud, source, id
[BiliIntl] 11411189: Downloading subtitles list
ERROR: [BiliIntl] Unable to download subtitles list: HTTP Error 412: Precondition Failed (caused by <HTTPError 412: 'Precondition Failed'>); please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 640, in extract
    ie_result = self._real_extract(url)
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/bilibili.py", line 968, in _real_extract
    return self._extract_video_info(video_data or {}, ep_id=ep_id, aid=aid)
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/bilibili.py", line 869, in _extract_video_info
    'subtitles': self._get_subtitles(ep_id=ep_id, aid=aid),
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/bilibili.py", line 797, in _get_subtitles
    sub_json = self._call_api(
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/bilibili.py", line 772, in _call_api
    json = self._download_json(self._API_URL + endpoint, *args, **kwargs)
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 1002, in download_content
    res = getattr(self, download_handle.__name__)(url_or_request, video_id, **kwargs)
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 966, in download_handle
    res = self._download_webpage_handle(
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 834, in _download_webpage_handle
    urlh = self._request_webpage(url_or_request, video_id, note, errnote, fatal, data=data, headers=headers, query=query, expected_status=expected_status)
  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 791, in _request_webpage
    raise ExtractorError(errmsg, cause=err)

  File "/usr/lib/python3.10/site-packages/yt_dlp/extractor/common.py", line 773, in _request_webpage
    return self._downloader.urlopen(self._create_request(url_or_request, data, headers, query))
  File "/usr/lib/python3.10/site-packages/yt_dlp/YoutubeDL.py", line 3596, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/lib/python3.10/urllib/request.py", line 525, in open
    response = meth(req, response)
  File "/usr/lib/python3.10/urllib/request.py", line 634, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.10/urllib/request.py", line 563, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.10/urllib/request.py", line 643, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 412: Precondition Failed
MinePlayersPE commented 2 years ago

s_locale seems to be a required param, taken from the bstar-web-lang cookie and then turned to a full lang_REGION code via a map note though that it doesn't have to match the cookies nor is it even being checked right now, so a simple way to fix is to

    def _get_subtitles(self, *, ep_id=None, aid=None):
        sub_json = self._call_api(
            '/web/v2/subtitle', ep_id or aid, note='Downloading subtitles list',
            errnote='Unable to download subtitles list', query=filter_dict({
+                's_locale': 'en_US',
                'platform': 'web',
                'episode_id': ep_id,
                'aid': aid,
            }))
korongmambu commented 2 years ago

@MinePlayersPE It worked!

MinePlayersPE commented 2 years ago

@lynxnexy new issue pls