-1

I am trying to download a youtube video using yt-dlp. The python file uses yt-dlp to download a youtube video by passing a URL of the video manually into python script using the subprocess.Open function.

import subprocess
from moviepy.editor import *
import os
import moviepy.editor as mp

# Download files through url and saves it in yt-vidoes dir
command = "yt-dlp "
URL = 'https://www.youtube.com/watch?v=C_rsdqKA6ok'
parameters = ' --output yt-videos/%(title)s'

def download_video():
   downloading =  subprocess.Popen(command + URL)
   downloading.wait()
   print(downloading.returncode)

download_video()

It is working fine on Windows but on Ubuntu I get this error:

Traceback (most recent call last):
  File "/home/purelogics/Arslan/shorts_bot/moveis/movies.py", line 17, in <module>
    download_video()
  File "/home/purelogics/Arslan/shorts_bot/moveis/movies.py", line 13, in download_video
    downloading =  subprocess.Popen(command + URL)
  File "/home/linuxbrew/.linuxbrew/Cellar/python@3.10/3.10.8/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/linuxbrew/.linuxbrew/Cellar/python@3.10/3.10.8/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'yt-dlp https://www.youtube.com/watch?v=C_rsdqKA6ok'
Robert
  • 7,394
  • 40
  • 45
  • 64

1 Answers1

1

From the docs:

An example of passing some arguments to an external program as a sequence is: Popen(["/usr/bin/git", "commit", "-m", "Fixes a bug."]) On POSIX, if args is a string, the string is interpreted as the name or path of the program to execute. However, this can only be done if not passing arguments to the program.

So, you want to pass a list to Popen where the first element of the list is the executable and the second is the parameter. As you have it now, it is trying to find a file to execute called yt-dlp https://www.youtube.com/watch?v=C_rsdqKA6ok

Cargo23
  • 3,064
  • 16
  • 25