You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新手求助:如何编写脚本循环执行yt-dlp命令并替换频道变量?

实现yt-dlp多频道循环下载的脚本方案

如果你用的是Linux/macOS这类支持Bash的环境,可以用下面的脚本实现循环处理所有频道:

脚本代码

#!/bin/bash

# 把需要处理的频道列在这里,每行一个
channels=(
    "@channel1"
    "@channel2"
    "@channel5"
    "@channel7"
    "@ewchannel7"
)

# 循环遍历每个频道,执行下载命令
for channel in "${channels[@]}"
do
    /home/server/yt-dlp  --match-filter "title~=(?i)앨리스" --write-thumbnail --write-subs --sub-langs all --write-description --write-annotations --write-info-json --continue --ignore-errors --convert-thumbnails jpg  --download-archive done.txt "https://www.youtube.com/${channel}/search?query=앨리스"
done

使用步骤

  1. 将上述代码保存为一个文件,比如命名为yt_download.sh
  2. 给脚本添加执行权限:
    chmod +x yt_download.sh
    
  3. 直接运行脚本即可:
    ./yt_download.sh
    

关键说明

  • 频道列表存在channels数组里,后续要新增/修改频道,直接修改这个数组的内容就行
  • 脚本会自动把每个频道值替换到原命令的$value$位置,逐个执行下载
  • --ignore-errors参数确保某个频道下载出错时,脚本会继续处理下一个频道
  • done.txt会记录已下载的内容,避免重复下载同一资源

内容的提问来源于stack exchange,提问作者user18953534

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 09:47:23