0

I want to use the twitch-dl package from PyPi. After installing it, the idea is to basically run it on the terminal like this:

twitch-dl download <twitch-vod-url>

And it works well when running on the terminal but my goal is to run this command inside my Python script:

os.system('twitch-dl download <twitch-vod-url>`')

All I get is 256 as my output when I run this code. It does not download anything.

Onur-Andros Ozbek
  • 2,998
  • 2
  • 29
  • 78
  • Can you try running it from terminal and share what error code you get? – AnkurSaxena Feb 01 '21 at 23:04
  • @AnkurSaxena There is no error. It runs well on the terminal. – Onur-Andros Ozbek Feb 01 '21 at 23:07
  • If your goal is to use the `twitch-dl` library itself within your code, it's usually advisable to import functions/classes from the package directly in your code rather than trying to invoke the CLI. I took a look, and it doesn't appear the author has provided any documentation for using the package directly from within your code. However, I would take a look at the source code and see if you can import whatever functions you need. I'd start here: https://github.com/ihabunek/twitch-dl/blob/master/twitchdl/download.py. The `download_file` and `download_files` functions look promising. – yanniskatsaros Feb 01 '21 at 23:29
  • @yanniskatsaros Thank you. I'll take a look but I also want to make this work. – Onur-Andros Ozbek Feb 01 '21 at 23:38
  • @oo92, I see. In that case, I suggest you take a look at [`subprocess.Popen`](https://docs.python.org/3/library/subprocess.html#subprocess.Popen) which allows you to execute a child program in a new process. – yanniskatsaros Feb 02 '21 at 01:02
  • @yanniskatsaros I tried that. Unless I got the syntax wrong. subprocess.Popen did not work. – Onur-Andros Ozbek Feb 02 '21 at 01:08
  • Both `subprocess.run(['twitch-dl' ,'download' ,'http://www.twitch.tv/videos/883439761'])` and `subprocess.Popen(['twitch-dl' ,'download' ,'http://www.twitch.tv/videos/883439761'])` do not work – Onur-Andros Ozbek Feb 02 '21 at 01:11

0 Answers0