开发者

Downloading YouTube videos via a Python script

开发者 https://www.devze.com 2023-03-09 05:08 出处:网络
I am trying to use this script to download YouTube videos using Python. Currently I use this as follows

I am trying to use this script to download YouTube videos using Python.

Currently I use this as follows

youtube-dl "http://www.youtube.com/watch?v=dvsdgyuv"

In the documentation they have writte开发者_高级运维n that I can use these

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`

They have not written how can I use that.

How can I use to have the video file name same as title?

They told to use this, but I don't know how to use this on the command line.

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


Your best bet is http://np1.github.io/pafy/. It rocks, 100%!


In the bottom of the documentation, it says how:

The -o option allows users to indicate a template for the output file names. The basic usage is not to set any template arguments when downloading a single file, like in youtube-dl -o funny_video.flv "http://some/video". However, it may contain special sequences that will be replaced when downloading each video. The special sequences have the format %(NAME)s. To clarify, that's a percent symbol followed by a name in parenthesis, followed by a lowercase S. Allowed names are: ...

You run the command like this to use those special output parameters:

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


With a Python script:

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消