我在使用Manjaro Linux。我改变了yt的zsh配置现在我得到了
❯ ytvp
deal_with_long_filename:1: command not found: xsel -ob
deal_with_long_filename:2: command not found: xsel -ob
日志显示
Usage: yt-dlp [OPTIONS] URL [URL...]
yt-dlp: error: no such option: --continue
--no-overwrites
--no-post-overwrites
--verbose
--restrict-filenames
--retry-sleep fragment:exp
Usage: yt-dlp [OPTIONS] URL [URL...]
yt-dlp: error: no such option: --continue
--no-overwrites
--no-post-overwrites
--verbose
--restrict-filenames
--retry-sleep fragment:exp
为什么它把所有的选择都当作一个单一的选择呢?
我尝试过单独运行xsel -ob
命令,它运行得很好。
我该怎么解决这个问题?
我想保留我正在使用的发送到后台&
选项。它会给函数deal_with_long_filename
的定义带来问题吗?
这是我现在的配置
opts="--continue
--no-overwrites
--no-post-overwrites
--verbose
--restrict-filenames
--retry-sleep fragment:exp=2:64
--print-to-file"
if [ -f /usr/local/bin/youtube-dl ]; then
yt_dlp="/usr/local/bin/yt-dlp"
else
yt_dlp="$(which yt-dlp)"
fi
# If using Mac
if [[ "$(uname -a | awk '{print $1}')" == "Darwin" ]]; then
paste="pbpaste"
opts="${opts} --ffmpeg-location /usr/local/bin/ffmpeg"
else # If using Linux
paste="xsel -ob"
fi
sanitize_linux_filename() {
echo "$1" | sed -e 's/[^a-zA-Z0-9._-]/_/g'
}
get_log_name() {
TIMESTAMP=$( date +%y%m%d%H%M%S )
NAME=$( sanitize_linux_filename "$1" )
echo "yt-dlp_${TIMESTAMP}_${NAME}.log"
}
deal_with_long_filename() {
if ! $yt_dlp $opts --output "%(upload_date>%Y-%m-%d|)s%(upload_date& |)s%(title)s-%(id)s.%(ext)s" "$($paste)" >> "/tmp/$LOG_NAME" 2>&1; then
$yt_dlp $opts --output "%(upload_date>%Y-%m-%d|)s%(upload_date& |)%(webpage_url_domain)s-%(id)s.%(ext)s" "$($paste)" >> "/tmp/$LOG_NAME" 2>&1
fi
}
# Video Playlist
ytvp() {
LOG_NAME=$( get_log_name "$1" )
opts="${opts}
--format '(bv+(wa[abr>=64]/ba))/b'
--format-sort res:720,tbr~2000
--no-playlist
--download-archive 'downloaded.txt'"
deal_with_long_filename "$1" "$LOG_NAME"
}
发布于 2022-10-21 09:52:52
错误消息是正确的,您的系统上没有名为xsel -ob
的命令。您试图使用的命令是xsel
,以及它的-ob
选项。由于将命令放入字符串中,因此将其视为单个实体。
这个问题类似于如何运行存储在变量中的命令?中描述的问题。
一定要存储有序字符串的集合,这样就可以将它们作为单独的字符串使用,使用数组。
opts=(
--continue
--no-overwrites
--no-post-overwrites
--verbose
--restrict-filenames
--retry-sleep fragment:exp=2:64
--print-to-file
)
添加到数组中:
opts+=( --ffmpeg-location /usr/local/bin/ffmpeg )
# ...
opts+=(
--format '(bv+(wa[abr>=64]/ba))/b'
--format-sort res:720,tbr~200
--no-playlist
--download-archive 'downloaded.txt'
)
然后,在zsh
shell中,使用它作为$opts
。
您的paste
变量也有相同的问题,它也应该是一个数组,因为您可能希望将它视为两个字符串xsel
和-ob
:
paste=( xsel -ob )
您的脚本中还有许多不必要复杂的事情,比如使用uname
获取操作系统类型:
if [[ $OSTYPE == darwin* ]]; then ...; fi
..。或者使用sed
从字符串中删除某些字符:
NAME=${1//[^[:alnum:].-]/_}
https://unix.stackexchange.com/questions/721873
复制相似问题