youtube-dl如何生成直接链接?
问题描述:
我想知道youtube-dl如何生成与视频的直接链接。我知道 与youtube-dl --get-url链接我可以得到这个,但我想知道这个过程如何。 (从下载html页面到获取链接)。有没有办法检查出来?
Youtube-dl是开源的,所以我想是的,但我只是不知道具体应该看哪里。
在此先感谢youtube-dl如何生成直接链接?
答
youtube-dl使用名为InfoExtractor
的类可以从不同站点下载视频。 YouTube视频的信息提取器位于/youtube_dl/extractor/youtube.py
。
这个类是相当复杂的,因为它在用户和不同类型的视频和频道等记录涉及我认为有关的部分是:
url = proto + '://www.youtube.com/watch?v=%s&gl=US&hl=en&has_verified=1&bpctr=9999999999' % video_id
凡video_id
由big regex提取:
_VALID_URL = r"""(?x)^
(
(?:https?://|//) # http(s):// or protocol-independent URL
(?:(?:(?:(?:\w+\.)?[yY][oO][uU][tT][uU][bB][eE](?:-nocookie)?\.com/|
(?:www\.)?deturl\.com/www\.youtube\.com/|
(?:www\.)?pwnyoutube\.com/|
(?:www\.)?yourepeat\.com/|
tube\.majestyc\.net/|
youtube\.googleapis\.com/) # the various hostnames, with wildcard subdomains
(?:.*?\#/)? # handle anchor (#/) redirect urls
(?: # the various things that can precede the ID:
(?:(?:v|embed|e)/(?!videoseries)) # v/ or embed/ or e/
|(?: # or the v= param in all its forms
(?:(?:watch|movie)(?:_popup)?(?:\.php)?/?)? # preceding watch(_popup|.php) or nothing (like /?v=xxxx)
(?:\?|\#!?) # the params delimiter ? or # or #!
(?:.*?&)? # any other preceding param (like /?s=tuff&v=xxxx)
v=
)
))
|youtu\.be/ # just youtu.be/xxxx
|(?:www\.)?cleanvideosearch\.com/media/action/yt/watch\?videoId=
)
)? # all until now is optional -> you can pass the naked ID
([0-9A-Za-z_-]{11}) # here is it! the YouTube video ID
(?!.*?&list=) # combined list/video URLs are handled by the playlist IE
(?(1).+)? # if we found the ID, everything can follow
$"""
幸运的是,它的评论...
这一切正则表达式确实是找到用户提供的URL YouTube的ID。该id的页面必须被解析以挖掘不同格式的直接媒体url(存储在一个javascript变量中),并且必须包含必须解密的签名。 'youtube-dl -g'的结果看起来像'https://r2---sn-nx5e6n76.googlevideo.com/videoplayback?key = yt6&mime = video%2Fmp4&...'它包含一个像'signature = CFC671E06803D382B6F7A403AFE1CB4AFFD3742F.01BF1F977DCF2018BE0318E4A0B6670C750A67D4' youtube.py'必须从'''javascript变量解密。 –
user1441998
参见'youtube.py'中的'_extract_signature_function' – user1441998
http://superuser.com/a/773998/276313描述解密 – user1441998