Make .M3U master playlist - output as relative path names
Moderator: DosItHelp
Hi Guys,
Not sure you can help, but by the looks of reading above you probably can.
My coding knowledge is very basic and I have cobbled something together to create m3u playlists for itunes. I have lots of mp3's on my computer in a number of directory. I have the following code:
@echo off
cd %1
If Exist *.wma Goto :M3U
If Exist *.mp3 Goto :M3U
dir *.wma /s
If Errorlevel 1 Goto :Check2
Goto :M3U
:Check2
dir *.mp3 /s
If Errorlevel 1 Goto :EOF
:M3U
echo %~f1
dir /o:n/a/b/s *.mp3 *.wma > "C:\Music\%~nx1.m3u"
This works fine and does exactly what I need, but only one folder at a time. Could someone give me an idea on how I can change the code, so I can use it on multiple folders at once.
Cheers
Not sure you can help, but by the looks of reading above you probably can.
My coding knowledge is very basic and I have cobbled something together to create m3u playlists for itunes. I have lots of mp3's on my computer in a number of directory. I have the following code:
@echo off
cd %1
If Exist *.wma Goto :M3U
If Exist *.mp3 Goto :M3U
dir *.wma /s
If Errorlevel 1 Goto :Check2
Goto :M3U
:Check2
dir *.mp3 /s
If Errorlevel 1 Goto :EOF
:M3U
echo %~f1
dir /o:n/a/b/s *.mp3 *.wma > "C:\Music\%~nx1.m3u"
This works fine and does exactly what I need, but only one folder at a time. Could someone give me an idea on how I can change the code, so I can use it on multiple folders at once.
Cheers
If you want to make the batch list files from different locations (c:\Music, d:\MP3s, etc) then you can previously make a list of all these locations then use a FOR loop to repeat the action for each of them. Depending on your use you can put that list inside the same batch or create a separate file, let's say MusicFolders.txt
Inside that file you'll put something like this:
Then the batch should look like this:
Does it help?
Inside that file you'll put something like this:
Code: Select all
c:\Music
d:\MP3s
...
Then the batch should look like this:
Code: Select all
@echo off
FOR /F "tokens=*" %%A IN (MusicFolders.txt) DO call :loop "%%A"
goto :EOF
:loop
echo %~f1
del /F /Q "c:\%~nx1.m3u" 2>nul
dir /o:n/a/b/s "%~1\*.mp3" "%~1\*.wma" >>"c:\Music\%~nx1.m3u"
Does it help?
Re:
DccD wrote:hmmm... I'm still working on this... special characters are tough !
In the mean time here is the new code fixing a bug when started from the root of a drive:Code: Select all
@ECHO OFF
SET currentfolder="%cd%"
CD ..
SET upperfolder="%cd%"
IF %upperfolder:~-2,-1%==\ SET upperfolder=%upperfolder:\=%
CALL SET folder=%%currentfolder:%upperfolder:"=%\=%%
CD %folder%
TITLE Generating Playlist for %folder%
ECHO.
ECHO Start time: %time:~0,-3%
ECHO Please wait...
FOR /F "tokens=*" %%A IN ('dir /s /b *.mp3') DO CALL :loop "%%~A"
GOTO end
:loop
SET file="%~1"
CALL SET file2="%%file:*%currentfolder:"=%\=%%"
SET file2=%file2:~0,-1%
setlocal enabledelayedexpansion
>>"# %folder:"=%.m3u" ECHO !file2:"=!
GOTO :EOF
:end
ECHO End time: %time:~0,-3%
ECHO
PAUSE
I favor the above code but I have a problem, I have songs that contain non-english characters. I believe I will need it saved in UTF-8. Is it possible to add a code in the batch to have it save in UTF-8?
Thanks in advance
Re: Make .M3U master playlist - output as relative path name
scaler wrote:I believe I will need it saved in UTF-8.
I believe you need to change your codepage to ANSI.
Code: Select all
:: ...snipp
ECHO Please wait...
REM save the current codepage in a variable
for /f "delims=: tokens=2" %%i in ('chcp') do set /a cp=%%~ni
REM change to ANSI
chcp 1252>nul
FOR /F "tokens=*" %%A IN ('dir /s /b *.mp3') DO CALL :loop "%%~A"
REM change back to your default ASCII codepage
chcp %cp%>nul
GOTO end
:: ...snipp
Re: Make .M3U master playlist - output as relative path name
Thank you for replying.
How do I do that and how does it help?
I tried understanding your code and running it but I still don't really know what it does.
Sorry I only have very minor programming knowledge and close to no knowledge on DOS, etc.
How do I do that and how does it help?
I tried understanding your code and running it but I still don't really know what it does.
Sorry I only have very minor programming knowledge and close to no knowledge on DOS, etc.
Re: Make .M3U master playlist - output as relative path name
The code page is a table that assigns the character encoding. Means what hex value (byte) should be interpreted to which sign.
I'm sure you've heard about ANSI and ASCII. 437 is the US ASCII (OEM) code page. I don't know where you come from, thats why I process your default code page to reset it later. 1252 is an ANSI code page.
Normaly your batch file works wit ASCII, but the file names are encoded in ANSI.
http://en.wikipedia.org/wiki/Code_page
http://en.wikipedia.org/wiki/Code_page_437
http://en.wikipedia.org/wiki/Code_page_1252
Well, I thought that you would realize that my code is only a snippet. You have to replace lines 11 to 13 in DccD's code with this snippet.
Regards
aGerman
I'm sure you've heard about ANSI and ASCII. 437 is the US ASCII (OEM) code page. I don't know where you come from, thats why I process your default code page to reset it later. 1252 is an ANSI code page.
Normaly your batch file works wit ASCII, but the file names are encoded in ANSI.
http://en.wikipedia.org/wiki/Code_page
http://en.wikipedia.org/wiki/Code_page_437
http://en.wikipedia.org/wiki/Code_page_1252
Well, I thought that you would realize that my code is only a snippet. You have to replace lines 11 to 13 in DccD's code with this snippet.
Regards
aGerman
Re: Make .M3U master playlist - output as relative path name
Sorry for late reply, my net was down for couple of days.
Do you mean it will look like this?
I tried it and I still get alot of ??? in my list. Here's some:
E:\songs\???\???????? Disc 1\01 ?????.wma
E:\songs\???\???????? Disc 1\02 ????.wma
E:\songs\???\???????? Disc 1\03 ???.wma
E:\songs\???\???????? Disc 1\04 ???.wma
E:\songs\???\???????? Disc 1\05 ??.wma
E:\songs\???\???????? Disc 1\06 ?????.wma
E:\songs\???\???????? Disc 1\07 ??.wma
E:\songs\???\???????? Disc 1\08 ??.wma
E:\songs\???\???????? Disc 1\09 ???????.wma
E:\songs\???\???????? Disc 1\10 ??.wma
E:\songs\???\???????? Disc 1\11 ??.wma
E:\songs\???\???????? Disc 1\12 ?????.wma
E:\songs\???\???????? Disc 1\13 ??.wma
E:\songs\???\???????? Disc 1\14 ??.wma
E:\songs\???\???????? Disc 1\15 ?????.wma
E:\songs\???\???????? Disc 1\16 ??.wma
E:\songs\???\???????? Disc 1\17 ???.wma
E:\songs\???\???????? Disc 1\18 ??.wma
E:\songs\???\?????\01 ????.wma
E:\songs\???\?????\02 ??.wma
E:\songs\???\?????\03 ?????.wma
E:\songs\???\?????\04 ?????.wma
E:\songs\???\?????\05 ????.wma
E:\songs\???\?????\06 ???.wma
E:\songs\???\?????\07 ?????.wma
E:\songs\???\?????\08 ???.wma
E:\songs\???\?????\09 ???.wma
E:\songs\???\?????\10 ????-?????.wma
E:\songs\???\?????\11 ????-?????.wma
Do you mean it will look like this?
Code: Select all
@ECHO OFF
SET currentfolder="%cd%"
CD ..
SET upperfolder="%cd%"
IF %upperfolder:~-2,-1%==\ SET upperfolder=%upperfolder:\=%
CALL SET folder=%%currentfolder:%upperfolder:"=%\=%%
CD %folder%
TITLE Generating Playlist for %folder%
ECHO.
ECHO Please wait...
REM save the current codepage in a variable
for /f "delims=: tokens=2" %%i in ('chcp') do set /a cp=%%~ni
REM change to ANSI
chcp 1252>nul
FOR /F "tokens=*" %%A IN ('dir /s /b *.mp3, *.wma, *.flac') DO CALL :loop "%%~A"
REM change back to your default ASCII codepage
chcp %cp%>nul
GOTO end
:loop
SET file="%~1"
CALL SET file2="%%file:*%currentfolder:"=%\=%%"
SET file2=%file2:~0,-1%
setlocal enabledelayedexpansion
>>"%folder:"=%.m3u" ECHO !file2:"=!
GOTO :EOF
:end
ECHO End time: %time:~0,-3%
ECHO
PAUSE
I tried it and I still get alot of ??? in my list. Here's some:
E:\songs\???\???????? Disc 1\01 ?????.wma
E:\songs\???\???????? Disc 1\02 ????.wma
E:\songs\???\???????? Disc 1\03 ???.wma
E:\songs\???\???????? Disc 1\04 ???.wma
E:\songs\???\???????? Disc 1\05 ??.wma
E:\songs\???\???????? Disc 1\06 ?????.wma
E:\songs\???\???????? Disc 1\07 ??.wma
E:\songs\???\???????? Disc 1\08 ??.wma
E:\songs\???\???????? Disc 1\09 ???????.wma
E:\songs\???\???????? Disc 1\10 ??.wma
E:\songs\???\???????? Disc 1\11 ??.wma
E:\songs\???\???????? Disc 1\12 ?????.wma
E:\songs\???\???????? Disc 1\13 ??.wma
E:\songs\???\???????? Disc 1\14 ??.wma
E:\songs\???\???????? Disc 1\15 ?????.wma
E:\songs\???\???????? Disc 1\16 ??.wma
E:\songs\???\???????? Disc 1\17 ???.wma
E:\songs\???\???????? Disc 1\18 ??.wma
E:\songs\???\?????\01 ????.wma
E:\songs\???\?????\02 ??.wma
E:\songs\???\?????\03 ?????.wma
E:\songs\???\?????\04 ?????.wma
E:\songs\???\?????\05 ????.wma
E:\songs\???\?????\06 ???.wma
E:\songs\???\?????\07 ?????.wma
E:\songs\???\?????\08 ???.wma
E:\songs\???\?????\09 ???.wma
E:\songs\???\?????\10 ????-?????.wma
E:\songs\???\?????\11 ????-?????.wma
Re: Make .M3U master playlist - output as relative path name
It's allmost impossible to answer you, because of much too less informations. The only thing I can see is that all the question marks are signs out of the ANSI table.
Could you post an example? Are this chinese signs or cyrillic signs ...? Where do this file names come from, how are they generated?
Could you post an example? Are this chinese signs or cyrillic signs ...? Where do this file names come from, how are they generated?
Re: Make .M3U master playlist - output as relative path name
They are chinese words. Some are traditional chinese, some simplified. But I have some japanese songs too.
Here's an example of how the 1st output should be:
Here's an example of how the 1st output should be:
Code: Select all
E:\songs\鄭秀文\登峰造極世紀精選 Disc 1\01 我想我可以.wma
Re: Make .M3U master playlist - output as relative path name
OMG, I'm unable to rename a file as shown with my (german) settings.
I'm sure that 1252 can't be the right code page but I've no idea which code page could be the right.
Write the following short batch:
<edit: the sign after delims= must be a tab, but it is shown like three blanks (no idea why) />
This should diplay you a number.
Replace the 1252 in your origin code with this number. I really hope that this will work. Otherwise I've no idea.
I'm sure that 1252 can't be the right code page but I've no idea which code page could be the right.
Write the following short batch:
<edit: the sign after delims= must be a tab, but it is shown like three blanks (no idea why) />
Code: Select all
@echo off
for /f "tokens=3 delims= " %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "ACP"') do echo %%a
pause
This should diplay you a number.
Replace the 1252 in your origin code with this number. I really hope that this will work. Otherwise I've no idea.
Re: Make .M3U master playlist - output as relative path name
Took a break from this issue due to commitments. Anyway, I tried and the only thing I have displayed is "Press any key to continue..."
Re: Make .M3U master playlist - output as relative path name
Have you noticed my "edit"?
Re: Make .M3U master playlist - output as relative path name
Yes I did notice your edit.
EDIT: still cannot solve problem yet.
EDIT: still cannot solve problem yet.