1
我想知道youtube-dl如何生成與視頻的直接鏈接。我知道 與youtube-dl --get-url鏈接我可以得到這個,但我想知道這個過程如何。 (從下載html頁面到獲取鏈接)。有沒有辦法檢查出來?
Youtube-dl是開源的,所以我想是的,但我只是不知道具體應該看哪裏。
在此先感謝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