我是python编程的新手。我想在下载之前提取视频/音频大小(任何youtube视频)??
答案 0 :(得分:2)
>>> from youtube_dl import YoutubeDL
>>> url = 'https://www.youtube.com/watch?v=PSYxT9GM0fQ'
>>> ytdl = YoutubeDL()
>>> info = ytdl.extract_info(url, download=False)
[youtube] PSYxT9GM0fQ: Downloading webpage
[youtube] PSYxT9GM0fQ: Downloading video info webpage
[youtube] PSYxT9GM0fQ: Extracting video information
[youtube] PSYxT9GM0fQ: Downloading DASH manifest
>>> formats = info['formats']
格式是字典列表,选择您要查找的格式
>>> format = formats[0]
>>> format['filesize']
2594621
一般
>>> info.keys()
dict_keys(['extractor_key', 'upload_date', 'thumbnail', 'playlist_index', 'format_id', 'width', 'display_id', 'is_live', 'dislike_count', 'thumbnails', 'annotations', 'age_limit', 'formats', 'id', 'playlist', 'subtitles', 'average_rating', 'player_url', 'height', 'requested_subtitles', 'like_count', 'extractor', 'uploader_id', 'ext', 'automatic_captions', 'format', 'webpage_url', 'end_time', 'uploader', 'webpage_url_basename', 'duration', 'start_time', 'view_count', 'title', 'http_headers', 'description', 'url', 'tags', 'categories'])
是可用于获取有关youtube链接的信息的不同键