厌倦了每次在电脑和/或智能手机上添加新文件时手动更新巨大的mp3/mp4 db,
所以我需要一些帮助来创建一个批处理文件,它可以自动创建/更新我的所有播放列表.m3u。
需要两个批处理文件(第一个正在调用第二个):
第一个很简单,我差不多搞定了;-)
create_all_playlist.bat(不需要参数,自定义文件)

create_m3u.bat  misc-70-80.m3u            misc\70\ misc\80\
create_m3u.bat  misc-70-80-90.m3u         misc\70\ misc\80\ misc\90\
create_m3u.bat  misc-60-70-2000-2010.m3u  misc\60\ misc\70\ misc\2000\ misc\2010\
[...]
create_m3u.bat  albums-2010.m3u           albums\2010\

很容易啊?
我需要你的帮助来写第二个蝙蝠,动态的:
创建m3u.bat output-playlist-name.m3u folder-1 folder-2[…]folder-n
为了方便播放,输出文件m3u应该是这样的(注意所有文件都是相对路径,搜索*.mp3*.mp4*.ogg(无论是哪种类型的剪切/硬代码)都将递归到指定的文件夹中)
(raw.m3u与大多数android和pc播放器兼容)
misc\2000s\Kelly Rowland - Work (Freemasons Arabic Mix).mp3
misc\2000s\Keri Hilson - Knock You Down ft Kanye West and Ne-Yo.mp3
misc\2000s\Kid Cudi vs Crookers - Day n Nite.mp3
misc\2000s\Korn - Inja.mp3
[...]
misc\2000s\Ladyhawke - My Delirium.mp3

最好的情况下,只有最好的情况下,让我们假设某人有足够的技能来产生完整的mp3/mp4标签阅读和格式化,如下所示
#EXTM3U
#EXTINF:227,A-Ha - Take On Me
misc\80s\A-Ha - Take On Me.mp3
#EXTINF:257,ACDC - Back in Black
misc\80s\ACDC - Back in Black.mp3
#EXTINF:311,Aerosmith & Run Dmc - Walk This Way
misc\80s\Aerosmith & Run Dmc - Walk This Way.mp3
[...]
#EXTINF:289,Alannah Myles - Black Velvet
misc\80s\Alannah Myles - Black Velvet.mp3

谢谢!!
对于生的M3U,啤酒在我身上:-)
对于延长的完整M3U:啤酒和我将烹制鸭子马格里特;-)

最佳答案

@ECHO OFF
SETLOCAL

:: make a tempfile
:maketemp
SET "tempfile=%temp%\%random%"
IF EXIST "%tempfile%*" (GOTO maketemp) ELSE (ECHO.>"%tempfile%a")



:: Need the start of the tree to scan
SET "rootdir=c:\sourcedir"
>"%tempfile%b" (ECHO(%rootdir%&ECHO(*)
FOR /f "delims=:" %%a IN ('FINDSTR /o /L "*" "%tempfile%b"') DO SET /a len=%%a-1

SET "destfile=%~1"

:loop
SHIFT
SET nextdir=%~1
IF NOT DEFINED nextdir GOTO process
PUSHD "%rootdir%\%~1"
FOR /f "delims=" %%a IN ('dir /b /s /a-d *.mp3 *.mp4 *.ogg') DO >>"%tempfile%a" ECHO(%%~na:%%a
POPD
GOTO loop

:process
>%destfile% ECHO(#EXTM3U
(
FOR /f "tokens=1*delims=:" %%a IN ('SORT "%tempfile%a"') DO (
 ECHO(#EXTINF:???,%%a
 SET "location=%%b"
 SETLOCAL enabledelayedexpansion
 ECHO(!location:~%len%!
 endlocal
)
)>>%destfile%
DEL "%tempfile%*"
GOTO :EOF

我使用c:\sourcedir作为起始目录。不执行参数有效性检查。您需要从CALL create_m3u.batcreate_all_playlist.bat,因为目标可执行文件是批处理文件。
至于丢失的数据-最困难的部分是提取信息…
编辑以允许在文件名中!,并从路径中删除前导\
修订:允许绝对路径
@ECHO Off
SETLOCAL

:: make a tempfile
:maketemp
SET "tempfile=%temp%\%random%"
IF EXIST "%tempfile%*" (GOTO maketemp) ELSE (ECHO.>"%tempfile%a")



:: Need the start of the tree to scan
SET "rootdir=c:\sourcedir"
>"%tempfile%b" (ECHO(%rootdir%&ECHO(*)
FOR /f "delims=:" %%a IN ('FINDSTR /o /L "*" "%tempfile%b"') DO SET /a len=%%a-1

SET "destfile=%~1"

:loop
SHIFT
SET nextdir=%~1
IF NOT DEFINED nextdir GOTO process
IF %nextdir:~0,1%==\ (
 PUSHD "%~1"
 FOR /f "delims=" %%a IN ('dir /b /s /a-d *.mp3 *.mp4 *.ogg') DO >>"%tempfile%a" ECHO(%%~na:2:%%a
) else (
 PUSHD "%rootdir%\%~1"
 FOR /f "delims=" %%a IN ('dir /b /s /a-d *.mp3 *.mp4 *.ogg') DO >>"%tempfile%a" ECHO(%%~na:%len%:%%a
)
POPD
GOTO loop

:process
>%destfile% ECHO(#EXTM3U
(
FOR /f "tokens=1,2*delims=:" %%a IN ('SORT "%tempfile%a"') DO (
 ECHO(#EXTINF:???,%%a
 SET "location=%%c"
 SETLOCAL enabledelayedexpansion
  ECHO(!location:~%%b!
 endlocal
)
)>>%destfile%

del "%tempfile%*"

GOTO :EOF

注意“包含空格的路径必须用引号括起来”

关于windows - Windows批处理.bat自动.m3u播放列表的创建/更新,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22401214/

10-10 10:01