Linux shell 中 youtube-dl 的简单队列
youtube-dl 是一个 Python 脚本,允许用户下载 YouTube 视频。它支持批量下载选项:
-a FILE, --batch-file=FILE
包含要下载的 URL 的文件(“-”表示标准输入)
我想设置某种队列,这样我就可以简单地将 URL 附加到文件中并让 youtube-dl
处理它们。目前,它不会从批处理文件中删除文件。我看到“-”标准输入的选项,但不知道是否可以利用它来发挥我的优势。
实际上,我想将 youtube-dl
作为某种形式的守护进程运行,它将检查队列文件并下载包含的文件名。
我该怎么做?
youtube-dl is a Python script that allows one to download YouTube videos. It supports an option for batch downloads:
-a FILE, --batch-file=FILE
file containing URLs to download ('-' for stdin)
I want to setup some sort of queue so I can simply append URLs to a file and have youtube-dl
process them. Currently, it does not remove files from the batch file. I see the option for '-' stdin and don't know if I can use this to my advantage.
In effect, I'd like to run youtube-dl
as some form of daemon which will check the queue file and download the contained file names.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
tail -f 将不起作用,因为脚本会立即读取所有输入。
如果您修改脚本以执行批处理文件的连续读取,它将起作用。
然后只需按以下方式运行脚本:
当您将一些数据附加到batch.txt 中时,请说:
脚本将开始将附加的视频下载到批处理中。
这是您应该应用于最新版本的“youtube-dl”的补丁:
希望它有帮助,
快乐观看视频
;)
注意:由于代码重组,此补丁将不再起作用。有兴趣看看是否可以将其添加到上游代码中。
The tail -f will not work because the script reads all the input at once.
It will work if you modify the script to perform a continuous read of the batch file.
Then simply run the script as:
When you append some data into batch.txt, say:
The script will start downloading the appended video to the batch.
This is the patch you should apply to the latest version of "youtube-dl":
Hope it helps,
Happy video watching
;)
NOTE: Due to code restructuring this patch will no longer work. Would be interested to see if this could be added to the upstream code.
您也许可以使用
tail -f
来读取文件。当到达文件末尾时它不会退出,而是等待更多数据追加到文件中。由于
tail -f
不会退出,youtube-dl
应继续从 stdin 读取文件名并且永不退出。You might be able to get away with using
tail -f
to read from your file. It will not exit when it reaches end-of-file but will wait for more data to be appended to the file.Since
tail -f
does not exit,youtube-dl
should continue reading file names from stdin and never exit.