Reputation: 737
Have a csv file with a bunch of youtube links.
It's structured like video-name \t part \t youtube-url
i want to use youtube-dl with python to download each video and have it be saved as video-name_part.extension
- is it possible to do this or can I only do things like %(name)s that are included in youtube-dl?
Upvotes: 1
Views: 2338
Reputation: 46759
You can import the youtube_dl
module and then pass the parameters using a parameter dictionary. You would need to take a look at the documentation for finer control on what you can do, but outtmpl
allows you to control the output format in the way you suggested.
The following script shows you how you could go about reading your CSV file:
import csv, youtube_dl
with open("filelist.csv", "r") as f_filelist:
csv_filelist = csv.reader(f_filelist, delimiter="\t")
for cols in csv_filelist:
video_name = cols[0]
part = cols[1]
youtube_url = cols[2]
ydl_opts = {"outtmpl" : r"{}_{}.%(ext)s".format(video_name, part)}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([youtube_url])
Upvotes: 3