要在其中打开https://github.com/ytdl-org/youtube-dl/tree/master/youtube_dl/extractor
,bilibili.py
,我会得到bilibili.py
源代码,它无济于事。
对于像我这样的新手来说,一遍又一遍地浏览bilibili.py's source code
是没有用的。
我很难理解youtube-dl如何在bilibili上获取视频的真实网址?
bilibili.py
在bilibili上提取视频的真实网址的原理是什么?
bilibili.py's source code
中有421行,请将bilibili.py
简化为简短的单个函数,例如getUrlFromBilibili
。
url = "https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593"
real_url = getUrlFromBilibili(url)
print(real_url)
请执行getUrlFromBilibili
功能并在其中进行一些注释,以显示原理,以获取有关bilibili视频的真实网址。
def getUrlFromBilibili(url):
#make the function short as soon as possible
答案 0 :(得分:3)
好像您只想获取不带参数的url部分。可以像这样简单地实现。
url = "https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593"
real_url = url.split('?')[0]
//real_url = https://www.bilibili.com/video/av52135588
答案 1 :(得分:-1)
您已经说过需要为此使用函数,并且需要了解原理。 Bilibili网站就像一个youtube。那里有很多视频。您必须进行编程才能从您输入的任何视频网址中获取真实网址。我将展示如何做到这一点。
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))
输出-:
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
现在我将解释这段代码
#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.
重要
如果您只想从该网址获取真实网址-> https://www.bilibili.com/video/av52135588?from=search&seid=5625791913889140593
您可以使用此代码
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"))
输出-:
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