Search code examples
subprocesstypeerroryoutube-dl

TypeError in subprocess command for youtube-dl


I'm trying to write a very simple script which passes in a .csv file and runs youtube-dl (and specified args) for each link in the file- saving the files to a certain directory.

The format of the csv is Artist;Title;Link. And the script:

import pandas as pd
import subprocess

def get_music(csv):

df = pd.read_csv(csv, sep=";", skipinitialspace=True)

for _, row in df.iterrows():        
    subprocess.call(['youtube-dl', "x",
                    "--output ~/mydir/%(title)s.%(ext)s",
                    "--extract-audio", "--youtube-skip-dash-manifest",
                    "--prefer-ffmpeg", "--audio-format", "mp3"], row.Link)


get_music("CSV.csv")

When I run this however, I get the following error:

"raise TypeError("bufsize must be an integer") TypeError: bufsize must be an integer"

I'm afraid I don't understand how the bufsize is getting passed something other than an integer. Simply put, what am I doing wrong, and how should I fix it?


Solution

  • Currently, your second argument to subprocess.call, which specifies the bufsize, is row.Link, which seems to be the URL you want to download. Instead of "x", pass in the actual link. Also, there is no option "--output ~/mydir/%(title)s.%(ext)s", as option names do not contain spaces. Most likely, you want

    subprocess.call(['youtube-dl', row.Link,
                     "--output", "~/mydir/%(title)s.%(ext)s",
                     "--extract-audio", "--youtube-skip-dash-manifest",
                     "--prefer-ffmpeg", "--audio-format", "mp3"])