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

yt-dlp在PowerShell中路径双反斜杠及文件写入失败问题求助

解决yt-dlp在PowerShell中路径双反斜杠及文件名特殊字符写入失败问题

核心问题拆解

  • PowerShell解析变量时,可能自动把路径反斜杠转成双反斜杠,导致yt-dlp识别路径出错
  • 视频标题带|、"这类Windows禁用文件名字符,即便开了--restrict-filenames,也可能因参数优先级或配置冲突失效

具体解决办法

1. 修复PowerShell变量转义问题

传递-P和--output参数时,用单引号包裹变量,避免PowerShell自动转义反斜杠:

yt-dlp.exe --config-location "$($_.ConfigFile)" -P '$($_.Path)' --output '$($_.Filename)' $($_.URL) $($_.Action) $($_.Range)

或者提前用PowerShell命令处理路径,确保格式正确:

$fixedPath = (Resolve-Path $($_.Path)).Path
$cleanFilenameTemplate = $($_.Filename) -replace '[^\w\s\-\(\)\.]', '_'
yt-dlp.exe --config-location "$($_.ConfigFile)" -P "$fixedPath" --output "$cleanFilenameTemplate" $($_.URL) $($_.Action) $($_.Range)

2. 强制启用Windows专属文件名限制

把--windows-filenames和--restrict-filenames放到命令最前面,避免被配置文件参数覆盖——--windows-filenames是专门针对Windows系统的规则,比通用的--restrict-filenames更精准:

yt-dlp.exe --windows-filenames --restrict-filenames --config-location "$($_.ConfigFile)" -P '$($_.Path)' --output '$($_.Filename)' $($_.URL) $($_.Action) $($_.Range)

3. 给配置文件加全局文件名限制

直接把--windows-filenames加到你的配置文件里,确保所有下载都生效:

-S "ext"
--windows-filenames
--sub-lang "en*" --write-auto-subs --embed-subs
--embed-thumbnail
--embed-metadata
--ffmpeg-location "D:\Tools\ffmpeg\bin"

4. 用yt-dlp内置过滤器清理标题

修改CSV里的Filename模板,用yt-dlp自带的replace过滤器直接替换非法字符:

Splinter Cell - Blacklist (Perfectionist-Ghost-NoKO) - s01e%(playlist_index)02d - %(title&replace:[\|"<>?*]|_).%(ext)s

这个模板会自动把标题里的|、"等禁用字符替换成下划线_

5. 先测单个视频排除循环问题

跳过ForEach循环,直接用单个视频链接测试,排除变量循环传递的问题:

yt-dlp.exe --windows-filenames --config-location "你的配置文件路径" -P "D:\Downloads\yt-dlp\Splinter Cell - Blacklist (Perfectionist-Ghost-NoKO) (Centerstrain01)" --output "Splinter Cell - Blacklist (Perfectionist-Ghost-NoKO) - s01e01 - %(title)s.%(ext)s" "https://www.youtube.com/watch?v=单个视频ID"

验证流程

  1. 先测单个视频,确认路径和文件名无异常
  2. 再逐步加回循环和播放列表参数
  3. 查看yt-dlp日志里的输出路径,确保没有双反斜杠和非法字符

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 02:06:30