m3u使用批处理脚本解析

时间:2017-05-09 10:33:05

标签: powershell batch-file m3u

我想用批处理命令

解析m3u播放列表中的艺术家和歌曲名称
#EXTM3U
#EXTINF:151,TJR - We Wanna Party Into We Want Some Pussy (BB Tribe EDIT)
\#Mixit\pjesme\TJR - We Wanna Party Into We Want Some Pussy (BeatBreaker Tribe EDIT).mp3
#EXTINF:202,Alan Walker - Alone (Prisoners Bootleg)
\Users\Asrock 880\Downloads\Alan Walker - Alone (Prisoners Bootleg).mp3
#EXTINF:236,Alan Walker - Alone 2k17 (#Ash Simons Bangerz) (Ft. Holl & Rush)

所以输出.txt文件看起来像这样

TJR - We Wanna Party Into We Want Some Pussy (BB Tribe EDIT)
Alan Walker - Alone (Prisoners Bootleg)
Alan Walker - Alone 2k17 (#Ash Simons Bangerz) (Ft. Holl & Rush)

任何帮助都会有用,谢谢

它可以是电源外壳或其他任何其他但有更好的描述我是DJ ......:P

2 个答案:

答案 0 :(得分:0)

  • 所以你只想要以行开头的信息 #EXTINF跟随逗号。
  • 您会在[SO]上找到数百个与findstr一起选择带有模式的行的示例(请参阅findstr /?
  • 以及使用for /f解析带有分隔符和标记的行的内容(请参阅for /?

批量生产:

@Echo off
(For %%M in (*.m3u
  ) Do For /f "tokens=1* delims=," "%%A" in (
    'findstr "^#EXTINF" %%M'
  ) Do Echo %%B
) > Playlists.txt

在cmd行:

@For /f "tokens=1* delims=," %A in ('findstr "^#EXTINF" playlist.m3u') Do @Echo %B

要重定向到文件,请在括号中包含for命令并附加>playlist.txt

答案 1 :(得分:0)

有人想删除PowerShell标记,所以这里只有一个内容:

(Select-String *.m3u -Pattern '^#EXTINF') -Replace '^[^,]+,'|Out-File PlayList.txt