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

bilibili: fix for geo verification error #9797

Closed
9 of 11 tasks
qhadron opened this issue Apr 26, 2024 · 1 comment · Fixed by #9817
Closed
9 of 11 tasks

bilibili: fix for geo verification error #9797

qhadron opened this issue Apr 26, 2024 · 1 comment · Fixed by #9817
Labels
geo-blocked Content is geo-blocked patch-available There is patch available that should fix this issue. Someone needs to make a PR with it site-bug Issue with a specific website

Comments

@qhadron
Copy link

qhadron commented Apr 26, 2024

DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

  • I understand that I will be blocked if I intentionally remove or skip any mandatory* field

Checklist

Region

China

Provide a description that is worded well enough to be understood

I am using --geo-verification-proxy with Unblock Youku's proxy for verification. This proxy doesn't allow downloading, so using --proxy is not an option.

I am getting the GeoRestrictedError on line 672:

webpage = self._download_webpage(url, episode_id)
if '您所在的地区无法观看本片' in webpage:
raise GeoRestrictedError('This video is restricted')
elif '正在观看预览,大会员免费看全片' in webpage:
self.raise_login_required('This video is for premium members only')
headers = {'Referer': url, **self.geo_verification_headers()}

However, if I enable the geo_verification_headers for the first request (self._download_webpage), then it works.
Here's a diff of the change:

@@ -666,14 +666,14 @@ class BiliBiliBangumiIE(BilibiliBaseIE):
 
     def _real_extract(self, url):
         episode_id = self._match_id(url)
-        webpage = self._download_webpage(url, episode_id)
+        headers = {'Referer': url, **self.geo_verification_headers()}
+        webpage = self._download_webpage(url, episode_id, headers=headers)
 
         if '您所在的地区无法观看本片' in webpage:
             raise GeoRestrictedError('This video is restricted')
         elif '正在观看预览,大会员免费看全片' in webpage:
             self.raise_login_required('This video is for premium members only')
 
-        headers = {'Referer': url, **self.geo_verification_headers()}
         play_info = self._download_json(
             'https://api.bilibili.com/pgc/player/web/v2/playurl', episode_id,
             'Extracting episode', query={'fnval': '4048', 'ep_id': episode_id},

Provide verbose output that clearly demonstrates the problem

  • Run your yt-dlp command with -vU flag added (yt-dlp -vU <your command line>)
  • If using API, add 'verbose': True to YoutubeDL params instead
  • Copy the WHOLE output (starting with [debug] Command-line config) and insert it below

Complete Verbose Output

[debug] Command-line config: ['-vU', '--geo-verification-proxy', 'http://secure.unblockpro.app:8080/', 'https://www.bilibili.com/bangumi/
play/ep173286']
[debug] Encodings: locale cp936, fs utf-8, pref cp936, out utf-8, error utf-8, screen utf-8 
[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp [ff0779267] (win_exe)
[debug] Lazy loading extractors is disabled
[debug] Python 3.12.3 (CPython AMD64 64bit) - Windows-11-10.0.22631-SP0 (OpenSSL 3.0.13 30 Jan 2024) 
[debug] exe versions: none
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.02.02, mutagen-1.47.0, requests-2.31.0, sqlite3-3.45.1, urllib3
-2.2.1, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Plugin directories: ['C:\\Users\\jackl\\AppData\\Roaming\\yt-dlp\\plugins\\yt-dlp-ChromeCookieUnlock\\yt_dlp_plugins']
[debug] Loaded 1810 extractors 
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: [email protected] from yt-dlp/yt-dlp 
yt-dlp is up to date ([email protected] from yt-dlp/yt-dlp)
[BiliBiliBangumi] Extracting URL: https://www.bilibili.com/bangumi/play/ep173286 
[BiliBiliBangumi] 173286: Downloading webpage
ERROR: [BiliBiliBangumi] 173286: This video is restricted 
You might want to use a VPN or a proxy server (with --proxy) to workaround.
Traceback (most recent call last):
  File "yt_dlp\YoutubeDL.py", line 1606, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "yt_dlp\YoutubeDL.py", line 1741, in __extract_info
    ie_result = ie.extract(url)
                ^^^^^^^^^^^^^^^
  File "yt_dlp\extractor\common.py", line 735, in extract
    ie_result = self._real_extract(url)
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "yt_dlp\extractor\bilibili.py", line 672, in _real_extract
    raise GeoRestrictedError('This video is restricted')
yt_dlp.utils.GeoRestrictedError: [BiliBiliBangumi] 173286: This video is restricted
@qhadron qhadron added site-bug Issue with a specific website triage Untriaged issue labels Apr 26, 2024
@qhadron
Copy link
Author

qhadron commented Apr 26, 2024

After the patch, the download works fine:

[debug] Command-line config: ['-vU', '--geo-verification-proxy', 'http://secure.unblockpro.app:8080/', 'https://www.bilibili.com/bangumi/
play/ep173286']
[debug] Encodings: locale cp936, fs utf-8, pref cp936, out utf-8, error utf-8, screen utf-8 
[debug] yt-dlp version [email protected] from yt-dlp/yt-dlp [ff0779267] (win_exe)
[debug] Lazy loading extractors is disabled
[debug] Python 3.12.3 (CPython AMD64 64bit) - Windows-11-10.0.22631-SP0 (OpenSSL 3.0.13 30 Jan 2024) 
[debug] exe versions: none
[debug] Optional libraries: Cryptodome-3.20.0, brotli-1.1.0, certifi-2024.02.02, mutagen-1.47.0, requests-2.31.0, sqlite3-3.45.1, urllib3
-2.2.1, websockets-12.0
[debug] Proxy map: {}
[debug] Request Handlers: urllib, requests, websockets
[debug] Plugin directories: ['C:\\Users\\jackl\\AppData\\Roaming\\yt-dlp\\plugins\\yt-dlp-ChromeCookieUnlock\\yt_dlp_plugins']
[debug] Loaded 1810 extractors 
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Latest version: [email protected] from yt-dlp/yt-dlp 
yt-dlp is up to date ([email protected] from yt-dlp/yt-dlp)
[BiliBiliBangumi] Extracting URL: https://www.bilibili.com/bangumi/play/ep173286 
[BiliBiliBangumi] 173286: Downloading webpage
[BiliBiliBangumi] 173286: Extracting episode 
[BiliBiliBangumi] Format(s) 1080P 高码率, 1080P 高清, 720P 高清, 4K 超清 are missing; you have to login or become premium member to downl
oad them. Use --cookies-from-browser or --cookies for the authentication. See  https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-co
okies-to-yt-dlp  for how to manually pass cookies
[BiliBiliBangumi] 173286: Get episode details
[debug] Formats sorted by: hasvid, ie_pref, lang, quality, res, fps, hdr:12(7), vcodec:vp9.2(10), channels, acodec, size, br, asr, proto,
 vext, aext, hasaud, source, id
[debug] Default format spec: best/bestvideo+bestaudio
[info] 173286: Downloading 1 format(s): 100023+30280
WARNING: You have requested merging of multiple formats but ffmpeg is not installed. The formats won't be merged
[debug] Invoking http downloader on "https://upos-sz-mirrorali.bilivideo.com/upgcxcode/87/20/29662087/29662087_p1-1-100023.m4s?e=ig8euxZM
2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BT
rNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1714176250&gen=playurlv2&os=alibv&oi=2014891429&trid=c6e1e3a82c8a41
c0a5395adf58a2dc28p&mid=0&platform=pc&upsig=6aca74d2d5ed5b9b34446089354335ee&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&bvc=
vod&nettype=0&orderid=0,3&buvid=FCD7BDC5-F4EB-BB19-4C56-CEC0BC22E4AE48957infoc&build=0&f=p_0_0&agrr=1&bw=31891&logo=80000000"
[download] Got error: ('Unable to connect to proxy', OSError('Tunnel connection failed: 403 Forbidden')). Retrying (1/10)... 
[debug] File locking is not supported. Proceeding without locking 
[download] Destination: 1 「爱」与自动手记人偶 [173286].f100023.mp4
[download] 100% of   43.77MiB in 00:01:48 at 412.55KiB/s
[debug] Invoking http downloader on "https://upos-sz-mirrorcoso1.bilivideo.com/upgcxcode/87/20/29662087/29662087_p1-1-30280.m4s?e=ig8euxZ
M2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8B
TrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1714176250&gen=playurlv2&os=coso1bv&oi=2014891429&trid=c6e1e3a82c8
a41c0a5395adf58a2dc28p&mid=0&platform=pc&upsig=f6aa54b3f865e84f5839f5a3b921ac0a&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&b
vc=vod&nettype=0&orderid=0,3&buvid=FCD7BDC5-F4EB-BB19-4C56-CEC0BC22E4AE48957infoc&build=0&f=p_0_0&agrr=1&bw=24215&logo=80000000"
[download] Got error: ('Unable to connect to proxy', OSError('Tunnel connection failed: 403 Forbidden')). Retrying (1/10)... 
[download] Destination: 1 「爱」与自动手记人偶 [173286].f30280.m4a 
[download] 100% of   33.26MiB in 00:00:09 at 3.58MiB/s

@qhadron qhadron changed the title bilibili: geo verification error bilibili: fix for geo verification error Apr 26, 2024
@bashonly bashonly added geo-blocked Content is geo-blocked patch-available There is patch available that should fix this issue. Someone needs to make a PR with it and removed triage Untriaged issue labels Apr 26, 2024
bashonly pushed a commit that referenced this issue May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
geo-blocked Content is geo-blocked patch-available There is patch available that should fix this issue. Someone needs to make a PR with it site-bug Issue with a specific website
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants