youtube-dl如何生成直接链接?

时间:2015-07-21 11:25:20

标签: python youtube youtube-dl


我想知道youtube-dl如何生成直接链接到视频。我知道 使用 youtube-dl --get-url链接我可以得到这个,但我想知道这个过程是怎么回事。 (从下载html页面到获取链接)。有没有办法检查出来?
Youtube-dl是开源的,所以我猜它是,但我只是不知道具体到哪里。
提前致谢

1 个答案:

答案 0 :(得分:2)

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提取_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 $""" 的位置:

{{ currentPage * entryLimit - 1 }} - {{ currentPage * entryLimit }} of {{ totalLeadItems.length }}

幸运的是,它评论了......