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 cid from bilibili #20555

Open
awei78 opened this issue Apr 4, 2019 · 2 comments
Open

Get cid from bilibili #20555

awei78 opened this issue Apr 4, 2019 · 2 comments

Comments

@awei78
Copy link

@awei78 awei78 commented Apr 4, 2019

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like this: [x])
  • Use the Preview tab to see what your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2019.04.01. If it's not, read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2019.04.01
  • Bug report (encountered problems with youtube-dl)

In the file bilibili.py, line 116, the code of get "cid" is:
cid = self._search_regex( r'\bcid(?:["\']:|=)(\d+)', webpage, 'cid', default=None ) or compat_parse_qs(self._search_regex( [r'EmbedPlayer\([^)]+,\s*"([^"]+)"\)', r'EmbedPlayer\([^)]+,\s*\\"([^"]+)\\"\)', r'<iframe[^>]+src="https://secure\.bilibili\.com/secure,([^"]+)"'], webpage, 'player parameters'))['cid'][0]

If there is only one video on the page, it works fine. However, if the video is part of the list, such as url: https://www.bilibili.com/video/av4050443/?p=86
It's cid is: 6534658. part of it's data is: {"cid":6534658,"page":86,"from":"vupload"...}

Use Regex pattern r'\bcid(?:["']:|=)(\d+)', it only get the cid of the first video in the list, it is wrong.
Then I found, if there is only one video on the page, it video data like this: {"cid":45915709,"page":1,"from":"vupload"...}, That is, it has a page number.

So, I think, can pattern be changed? add a page number limit, suck as:

page_number = xxx  #get from url or set it = 1
r'\bcid(?:["\']:|=)(\d+),page":%d' % page_number

In this way, the correct cid can be achieved, and the whole playlist can be downloaded.

I am looking forward to it.

@awei78
Copy link
Author

@awei78 awei78 commented May 30, 2019

@dstftw Can you modify it? thanks

        if 'anime/' not in url:
            page_number = int(self._search_regex(
                r'/\?p=(\d+)$', url, 'page_number', '0'))
            pattern = r'\bcid(?:["\']:|=)(\d+)' if page_number == 0 else r'\bcid(?:["\']:|=)(\d+),"page":%d' % page_number
            cid = self._search_regex(
                pattern, webpage, 'cid',
                default=None
            ) or compat_parse_qs(self._search_regex(
                [r'EmbedPlayer\([^)]+,\s*"([^"]+)"\)',
                 r'EmbedPlayer\([^)]+,\s*\\"([^"]+)\\"\)',
                 r'<iframe[^>]+src="https://secure\.bilibili\.com/secure,([^"]+)"'],
                webpage, 'player parameters'))['cid'][0]
        else:
@omega13a
Copy link

@omega13a omega13a commented Jul 5, 2019

@awei78 , I think it would be quicker if you go and edit the file in the code repository yourself which would automatically create a pull request that the maintainers can approve. We really need this bug fix applied.
Also, a little note about this bug fix, if you want to download more then one page of a multi-page video (IE https://www.bilibili.com/video/av4050443/?p=85 and https://www.bilibili.com/video/av4050443/?p=86), you need to do each separately and use the -o parameter to give them different titles so youtube-dl doesn't think you are trying to download the same video again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.