Wanted: Command line m3u creator
Moderators: NeilBlanchard, Ralf Hutter, sthayashi, Lawrence Lee
Wanted: Command line m3u creator
I'm looking for a Win32 program (or a script) that creates an extended m3u file. It must be command line and work with both mp3 and flac.
For example lets say I have a few files:
c:\music_album\1.flac
c:\music_album\2.flac
c:\music_album\1.mp3
c:\music_album\2.mp3
Executing c:\music_album\createM3u.exe should result in the file
c:\music_album\music_album.m3u
with this content:
#EXTM3U
#EXTINF:123,1
1.flac
#EXTINF:123,1
1.mp3
#EXTINF:123,2
2.flac
#EXTINF:123,2
2.mp3
(Assuming all files are 123 seconds long).
Anyone knows of such a program?
For example lets say I have a few files:
c:\music_album\1.flac
c:\music_album\2.flac
c:\music_album\1.mp3
c:\music_album\2.mp3
Executing c:\music_album\createM3u.exe should result in the file
c:\music_album\music_album.m3u
with this content:
#EXTM3U
#EXTINF:123,1
1.flac
#EXTINF:123,1
1.mp3
#EXTINF:123,2
2.flac
#EXTINF:123,2
2.mp3
(Assuming all files are 123 seconds long).
Anyone knows of such a program?
Should be easily doable, e.g. in python (assuming you have command line programs to tell the length in seconds for each music file type, otherwise it becomes more work).
Here's a start, but I can't be bothered to implement the length() function that finds out the correct length in seconds (and figures out if a file is a song or not).
Note to other programmers: far from ready, so rather than complaining about any bugs, just complete it yourself.
Code: Select all
import sys,os
def duration(f):
return 1 # TODO output length in seconds if f is a song, else None
dir = sys.argv[1]
os.chdir(dir)
n = os.getcwd().split('/')[-1]
playlist = n + ".m3u"
m3u = open(playlist,'w')
m3u.write("#EXTM3U\n")
for f in os.listdir(dir):
l = duration(f)
if l:
m3u.write("#EXTINF:"+str(l)+','+f.strip('.')[0]+'\n'+f+'\n')
elif f != playlist:
print "found unknown file:", f
Note to other programmers: far from ready, so rather than complaining about any bugs, just complete it yourself.
Head to here: http://sourceforge.net/projects/flac/files/flac-win/
And grab the latest flac package. Inside you will find metaflac.exe, using it you can retrieve the sample_rate and total samples in a file. samples / sample_rate will give the length.
There may be other methods, but this is one I found using the standard flac tools.
And grab the latest flac package. Inside you will find metaflac.exe, using it you can retrieve the sample_rate and total samples in a file. samples / sample_rate will give the length.
There may be other methods, but this is one I found using the standard flac tools.
Thank you ascl. I think I finally got a batch script together that does what I need it to do.
I'm using metaflac and mp3info to get the length of the files. Another productive night here at work.
edit: Made a few slight changes to the script.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
if not exist *.flac if not exist *.mp3 goto nofiles
for %%x in (".") do set dir=%%~nx
echo #EXTM3U > "%dir%".m3u
for %%x in (*.flac) do (
for /f "tokens=*" %%a in ('metaflac.exe --show-total-samples "%%x"') do set samples=%%a
for /f "tokens=*" %%a in ('metaflac.exe --show-sample-rate "%%x"') do set rate=%%a
set /a seconds=!samples!/!rate!
echo #EXTINF:!seconds!,%%~nx >> "%dir%".m3u
echo %%x >> "%dir%".m3u
)
for %%x in (*.mp3) do (
for /f "tokens=*" %%a in ('mp3info.exe -p %%S "%%x"') do set seconds=%%a
echo #EXTINF:!seconds!,%%~nx >> "%dir%".m3u
echo %%x >> "%dir%".m3u
)
echo %dir%.m3u created
goto EOF
:nofiles
echo Cannot find any flac/mp3 files
edit: Made a few slight changes to the script.
Last edited by Vicotnik on Sun Nov 01, 2009 7:14 am, edited 1 time in total.
Excellent, thanks for posting. One small potential problem is:
I think this doesn't round properly, it just truncates to an 'int', which may mean your song length isn't quite right (ie samples = 3, rate = 2, length will equal 1).
Not sure how much it matters (if at all) in an m3u file.
Code: Select all
set /a seconds=!samples!/!rate!
Not sure how much it matters (if at all) in an m3u file.
Sorry I didn't see this thread a bit earlier, I might have saved you a bit of bother: http://www.synthetic-soul.co.uk/tag/Vicotnik wrote:Thank you ascl. I think I finally got a batch script together that does what I need it to do.
tag --playlist *.flac should give you what you want.