Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Python脚本下载YouTube视频_Python_Linux_Youtube_Youtube Dl - Fatal编程技术网

通过Python脚本下载YouTube视频

通过Python脚本下载YouTube视频,python,linux,youtube,youtube-dl,Python,Linux,Youtube,Youtube Dl,我正在尝试使用Python下载YouTube视频 目前我使用它如下 youtube-dl "http://www.youtube.com/watch?v=dvsdgyuv" 在他们写的文档中,我可以使用这些 id: The sequence will be replaced by the video identifier. url: The sequence will be replaced by the video URL. uploader: The sequence will be re

我正在尝试使用Python下载YouTube视频

目前我使用它如下

youtube-dl "http://www.youtube.com/watch?v=dvsdgyuv"
在他们写的文档中,我可以使用这些

id: The sequence will be replaced by the video identifier.
url: The sequence will be replaced by the video URL.
uploader: The sequence will be replaced by the nickname of the person who uploaded the video.
upload_date: The sequence will be replaced by the upload date in YYYYMMDD format.
title: The sequence will be replaced by the literal video title.
stitle: The sequence will be replaced by a simplified video title, restricted to alphanumeric characters and dashes.
ext: The sequence will be replaced by the appropriate extension (like flv or mp4).
epoch: The sequence will be replaced by the Unix epoch when creating the file.
autonumber: The sequence will be replaced by a five-digit number that will be increased with each download, starting at zero.`enter code here`
他们还没有写我怎么能用这个

如何使用与标题相同的视频文件名

他们告诉我使用这个,但我不知道如何在命令行上使用它

%(title)s-%(id)s.%(ext)s.

在文档的底部,它说明了如何:

-o选项允许用户 指示输出的模板 文件名。基本用法不是 在以下情况下设置任何模板参数: 下载单个文件,如 youtube dl-o搞笑视频.flv "http://some/video". 然而,它可能 包含将被删除的特殊序列 下载每个视频时替换。 特殊序列的格式为%(名称)s。澄清一下,这是 百分比符号,后跟中的名称 括号,后跟小写字母 允许的名称是:

您可以像这样运行命令以使用这些特殊的输出参数:

youtube-dl "http://www.youtube.com/watch?v=dvsdgyuv" -o "%(title)s-%(id)s.%(ext)s."
你最好的选择是。它摇滚,100%

使用Python脚本:

import youtube_dl

youtube_playlist_url = 'youtube_playlist_url'
destination_folder = './youtube_playlist/'

ydl_opts = {'outtmpl': destination_folder+'/%(title)s.%(ext)s'}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download([youtube_playlist_url])

来源:

谢谢,我以前没有在字符串中使用双引号。也可以在不同的文件夹中下载。我的意思是,首先将文件夹装入板条箱,然后在Linux中下载,您只需运行
mkdir foo
并将
-o
设置为
foo/%(title)…
实际上,我正在考虑制作脚本,自动从youtube收集播放列表并下载特定文件夹中的播放列表。我想我需要先调用mkdir,然后再调用播放列表的脚本