通过Python脚本下载YouTube视频

时间:2011-05-29 05:22:47

标签: python linux youtube youtube-dl

我正在尝试使用this script使用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.

3 个答案:

答案 0 :(得分:4)

你最好的选择是http://np1.github.io/pafy/。摇滚,100%!

答案 1 :(得分:3)

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

  

-o选项允许用户访问   表示输出的模板   文件名。基本用法不是   在何时设置任何模板参数   下载单个文件,例如   youtube-dl -o funny_video.flv   “HTTP://一些/视频”。但是,它可能   包含将要的特殊序列   下载每个视频时替换。   特殊序列的格式为%(NAME)s 。澄清,那是   一个百分号后跟一个名字   括号,后跟小写   S.允许的名字是:......

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

youtube-dl "http://www.youtube.com/watch?v=dvsdgyuv" -o "%(title)s-%(id)s.%(ext)s."

答案 2 :(得分:0)

使用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])

来源:https://www.youtube.com/watch?v=Mn0zj8Ql7Fs