EMBEDDING Youtube-DL in Python with Batch File

967 views Asked by At

Ok, I know that to get Mp3 files from Youtube-DL in a python program you use

from __future__ import unicode_literals
import youtube_dl


ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
    'key': 'FFmpegExtractAudio',
    'preferredcodec': 'mp3',
    'preferredquality': '192',
    }], 
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['http://www.youtube.com/watch?v=BaW_jenozKc'])

I have gotten that to work no problem. My problem is that i cannot get the -a or --batch file FILE to work with this I tried to set a Filesystem but that was just randomly guessing, and the information in the ReadMe is lacking for embedding.

Is there anyway to download youtube videos from a txt file using a Python program, or a resource online that explains embedding

1

There are 1 answers

0
masoud On

According to what I see, you can pass an array to ydl.download(), so why not reading the file into an array:

with open(filename) as f:
    urls = f.readlines()

and then, passing it to the download:

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(urls)