2017-09-04 32 views
0

有了这个代码的YouTube-DL不接受播放列表URL

import os 

with open('urls.txt') as f: 
    for line in f: 
      os.system("youtube-dl "+"--write-thumbnail "+"--skip-download "+"--yes-playlist " +line) 

在播放列表中的下载的第一图像,然后我得到一个错误信息说“列表”不被识别为一个内部或external类型命令,可操作程序或批处理文件。在'urls.txt'中,我只有一个Youtube播放列表的网址。网址是这样的:

https://www.youtube.com/watch?v=GA3St3Rf9Gs&list=PL-uc0GihCvU9s24BT_mvTzt3zm7e2uDGm

这是&符号后切断输入。如果我用'foo'替换url中的'list',我会得到相同的消息。我该如何让youtube-dl接受播放列表网址?

+0

试着看一下[这](https://askubuntu.com/questions/334081/downloading-multiple-files-with-youtube- DL)。也可以尝试更新'youtube-dl'。 – campovski

回答

0

您可以直接在您的脚本中使用youtube_dl库并通过网址下载。

import os 
import youtube_dl 

ydl_opts = { 
    'writethumbnail': True, 
    'skip_download': True, 
    'noplaylist': False 
} 


with open('urls.txt') as f: 
    sources = f.readlines() 

with youtube_dl.YoutubeDL(ydl_opts) as ydl:  
    ydl.download(sources) 
0

您的程序有一个主要的command injection security vulnerability。你已经触发了这个(无害的代码)意外。您正在执行

youtube-dl --write-thumbnail --skip-download --yes-playlist \ 
https://www.youtube.com/watch?v=GA3St3Rf9Gs&list=PL-uc0GihCvU9s24BT_mvTzt3zm7e2uDGm 

由于符号是一个command character in shell scripts,你正在运行的两个命令

youtube-dl --write-thumbnail --skip-download --yes-playlist \ 
    https://www.youtube.com/watch?v=GA3St3Rf9Gs 

list=PL-uc0GihCvU9s24BT_mvTzt3zm7e2uDGm 

由于没有与该名称的程序,第二个命令可能会失败。

为了解决这个问题,用正确的子进程调用与subprocess

import subprocess 

with open('urls.txt') as f: 
    for line in f: 
     subprocess.check_call([ 
      "youtube-dl", 
      "--write-thumbnail", "--skip-download", "--yes-playlist", 
      line])