需要2个批处理文件(第1个调用第2个):
第一个很容易,我几乎得到了它; - )
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\
很容易啊?
我需要你的帮助来写第二个.bat,动态的:
create_m3u.bat output-playlist-name.m3u folder-1 folder-2 [...] folder-n
要轻松播放,输出文件.m3u应如下所示(注意所有相对路径并搜索* .mp3 * .mp4 * .ogg(无论何种类型我cutomize / hard -code)将递归到指定的文件夹中)
(原始.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 TAG阅读和格式如下
#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:啤酒,我会煮鸭子; - )
答案 0 :(得分:2)
@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.bat
create_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
注意“包含空格的路径必须在引号中”