linux 具有多个参数并在某些命令之间等待的xargs

cnwbcb6i  于 2023-05-06  发布在  Linux
关注(0)|答案(1)|浏览(100)

首先,我是一个编程新手,总体上我一无所知。
好了,我写了一个剧本,现在我来解释一下。

# Input YouTube video URL into tool that will download the YouTube video file and then uploads it to Internet Archive (archive.org)

tubeup -i $URL

# Wait 15 seconds to avoid any connection errors

sleep 15

# Uses yt-dlp to parse YouTube video URL to download the YouTube video's comment information to a file

yt-dlp --get-comments --no-write-info-json --skip-download --print-to-file "%(comments)#j" "%(id)s.comments" $URL

# Uses yt-dlp to parse YouTube video URL to fetch the YouTube video's information and assigns them to variables

EXTRACTOR=$(yt-dlp --skip-download --print "%(extractor)s" $URL)
ID=$(yt-dlp --skip-download --print "%(id)s" $URL)

# Uploads comment information file to the correct file repository on Internet Archive (archive.org)

ia upload $EXTRACTOR-$ID $ID.comments

# Wait 15 seconds again to avoid any possible errors

sleep 15

# Delete the YouTube video comment information file from my local harddrive

rm $ID.comments

# Reset previously used variables

unset URL
unset EXTRACTOR
unset ID

当我想通过手动输入YouTube URL来上传YouTube视频时,这个脚本对我非常有用。但最近,我想输入一个文本文件的网址到脚本和脚本将自动执行这些命令顺序和一次一个为每个视频。
看起来xargs可以允许我这样做,但我看了其他关于xargs的线程,它们都让我感到困惑。
有人能帮帮我吗
我在其他线程中测试了xargs示例,但它们没有按照我预期的方式工作。
xargs命令,我尝试从以下示例创建:Running multiple commands with xargs

cat list.txt | xargs -i  sh -c 'tubeup -i {} | sleep 15 && yt-dlp --get-comments --no-write-info-json --skip-download --print-to-file "%(comments)#j" "%(id)s.comments" {} && EXTRACTOR=$(yt-dlp --skip-download --print "%(extractor)s" {}) && ID=$(yt-dlp --skip-download --print "%(id)s" {}) && ia upload $EXTRACTOR-$ID $ID.comments && sleep 15 && rm $ID.comments && unset URL && unset EXTRACTOR && unset ID'

我所做的代码片段的问题在于,xargs不会等待第一个命令完成,直到它执行第二个命令。就像它试图上传到互联网档案馆,即使视频还没有完成下载。

l0oc07j2

l0oc07j21#

@jhdc的评论回答:
命名是强大的。如果你有一个接受URL的工作脚本,就使用它:

<list.txt xargs -I@ path/to/yourscript @

相关问题