youtube-dl 參數中的正規表示式

youtube-dl 參數中的正規表示式

我想從 youtube-dl 參數中提取兩個路徑,即輸出模板和 ffmpeg 位置

-o (.*%\(ext\)s).* --ffmpeg-location (.*)

使用上面的正規表示式,我可以從下面的表達式捕獲輸出模板和 ffmpeg 位置

-o D:/Deskttop/test//%(title)s.%(ext)s -i -f (best)[height=1080]/best --recode-video mp4 https://www.youtube.com/watch?v=MMuUFjxLQJU --no-playlist --encoding utf-8 --ffmpeg-location D:/Deskttop/test/

問題是有時未提供 ffmpeg 位置,如下所示:

-o D:/Deskttop/test//%(title)s.%(ext)s -i -f (best)[height=1080]/best --recode-video mp4 https://www.youtube.com/watch?v=MMuUFjxLQJU --no-playlist --encoding utf-8

我希望即使在僅使用一種正規表示式的表達式中不存在 ffmpeg 位置時也能夠捕獲輸出模板。

我正在測試這個這裡

答案1

我將我的評論作為答案。

使用這個正規表示式,它適用於兩種情況:

-o (.*%\(ext\)s).+?(?:--ffmpeg-location (.+?))?$

演示與說明

相關內容