Make .M3U master playlist - output as relative path names

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Pablo84
Posts: 2
Joined: 30 Dec 2009 10:23

#16 Post by Pablo84 » 30 Dec 2009 10:31

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

DccD
Posts: 23
Joined: 26 Aug 2009 19:34

#17 Post by DccD » 30 Dec 2009 18:09

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:

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?

Pablo84
Posts: 2
Joined: 30 Dec 2009 10:23

#18 Post by Pablo84 » 31 Dec 2009 06:23

That worked perfectly - thanks for you help and advise

scaler
Posts: 6
Joined: 04 Mar 2010 12:46

Re:

#19 Post by scaler » 04 Mar 2010 13:45

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Make .M3U master playlist - output as relative path name

#20 Post by aGerman » 04 Mar 2010 14:16

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

scaler
Posts: 6
Joined: 04 Mar 2010 12:46

Re: Make .M3U master playlist - output as relative path name

#21 Post by scaler » 05 Mar 2010 23:42

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Make .M3U master playlist - output as relative path name

#22 Post by aGerman » 06 Mar 2010 06:09

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

scaler
Posts: 6
Joined: 04 Mar 2010 12:46

Re: Make .M3U master playlist - output as relative path name

#23 Post by scaler » 08 Mar 2010 07:58

Sorry for late reply, my net was down for couple of days.
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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Make .M3U master playlist - output as relative path name

#24 Post by aGerman » 08 Mar 2010 13:39

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?

scaler
Posts: 6
Joined: 04 Mar 2010 12:46

Re: Make .M3U master playlist - output as relative path name

#25 Post by scaler » 09 Mar 2010 04:15

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:

Code: Select all

E:\songs\鄭秀文\登峰造極世紀精選 Disc 1\01 我想我可以.wma

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Make .M3U master playlist - output as relative path name

#26 Post by aGerman » 09 Mar 2010 06:43

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) />

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.

scaler
Posts: 6
Joined: 04 Mar 2010 12:46

Re: Make .M3U master playlist - output as relative path name

#27 Post by scaler » 14 Mar 2010 10:04

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..."

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Make .M3U master playlist - output as relative path name

#28 Post by aGerman » 14 Mar 2010 10:55

Have you noticed my "edit"?

scaler
Posts: 6
Joined: 04 Mar 2010 12:46

Re: Make .M3U master playlist - output as relative path name

#29 Post by scaler » 18 Mar 2010 08:13

Yes I did notice your edit.
EDIT: still cannot solve problem yet.

Post Reply