-8

To open https://github.com/ytdl-org/youtube-dl/tree/master/youtube_dl/extractor ,bilibili.py in it,i get bilibili.py source code,it help nothing.
It is no use for a newbie like me to look over and over at bilibili.py's source code.
It is difficult for me to understand how youtube-dl get video's real url on bilibili?
What is the principle for bilibili.py to extract video's real url on bilibili?
There are 421 lines in bilibili.py's source code,please simplify bilibili.py as a short single function such as getUrlFromBilibili.

url = "https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593"
real_url = getUrlFromBilibili(url)
print(real_url)

Please fulfil the getUrlFromBilibili function and give some comments in it to show principle to get video's real url on bilibili.

def  getUrlFromBilibili(url):
    #make the function short as soon as possible
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • The lib is downloading the webpage and searching with regexes for the video url. – Simon Dec 10 '19 at 20:46
  • 1
    How the lib get the real url?Please show me the principle. –  Dec 11 '19 at 06:30
  • Before bounty period you have asked question and all answers are fit to the question. In grace period You edited your question and it is totally difference from previous question. Then all answers which are given to this question is not are answers. Please don't do that again. It will lead to lot of down votes on answers. more than 1500+ reputation users can see what was happen in here – Kalana Dec 17 '19 at 06:54

2 Answers2

4

Looks like you want to get only the url part without parameters. This can be achieved simply like this.

url = "https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593"
real_url = url.split('?')[0]

//real_url = https://www.bilibili.com/video/av52135588
DinushaNT
  • 1,137
  • 6
  • 17
  • I believe the author wants the real VIDEO FILE url from the website url. – Alexandr Shurigin Dec 13 '19 at 12:41
  • 3
    There is no single real video file. It consists of multiple small video files that are streamed dynamically. – DinushaNT Dec 13 '19 at 12:44
  • What is the output for `wget https://www.bilibili.com/video/av52135588`? –  Dec 16 '19 at 17:17
  • @scrapy It will just download the page containing that video. If you need to download the actual video file, it's a complex process which cannot be simplified into a single function. Whole purpose of the youtube-dl library is to download such files. – DinushaNT Dec 17 '19 at 11:12
0

You have said you need to use functions for that and need know principles. Bilibili site is like a youtube. There are lot videos in there. There for You have to program to get real url from any video url that you enter. I will show how to do that.

def  getUrlFromBilibili(url):
    real_url = url[:url.find('?')]
    return real_url;

URL = input("Copy and Paste your Bilibili url = ")
#https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593
print("Real url is = ", getUrlFromBilibili(URL))

output -:

Copy and Paste your Bilibili url = https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593

Real url is = https://www.bilibili.com/video/av52135588

Now I am going to explain this code

#Start of the function

def  getUrlFromBilibili(url):      #This the function which we use to store our url
    real_url = url[:url.find('?')] #In here we remove all characters after '?' in your url including '?'
    return real_url;               #After that we return our shorten url 

#End of the function


URL = input("Copy and Paste your Bilibili url")  #In here You can Enter any video url from Bilibili.com

print("Real url is = ", getUrlFromBilibili(URL))         #After all actions shorten url is displaying in here.


Importent

If you want to get real url from this url only -> https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593 You can use this code

def  getUrlFromBilibili(url):
    real_url = url[:url.find('?')]
    return real_url;

print("Real url is = ", getUrlFromBilibili("https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593"))

output -:

Copy and Paste your Bilibili url = https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593

Real url is = https://www.bilibili.com/video/av52135588
Kalana
  • 5,631
  • 7
  • 30
  • 51
  • What is the output for `wget https://www.bilibili.com/video/av52135588`? –  Dec 16 '19 at 17:18
  • Does this answer to your question -> https://stackoverflow.com/questions/34692009/download-image-from-url-using-python-urllib-but-receiving-http-error-403-forbid – Kalana Dec 16 '19 at 19:24