1.

Solve : m3u Ramdomizer Project?

Answer»

I need some help with this:

I got a an m3u list which contains this :
Code: [Select]#EXTM3U
C:\Video\Twisted Sisters - I Wanna Rock.avi
C:\Video\Amy Dimond - Thank You.avi
C:\Video\Andreas Da Man.avi
C:\Video\Bicycle.avi
C:\Video\Billy Idiol - Mony Mony.avi
C:\Video\Billy Idol - Rebel Yell.avi
C:\Video\Billy Idol- White Wedding.avi
C:\Video\Bily Idol - You Spin Me Right Round.avi
C:\Video\Black Uhuru - Great Train Robbery.avi
C:\Video\Crashday.avi
C:\Video\Dream1.avi
C:\Video\En gammal Amazon.avi
C:\Video\Gigi D' Agostino - Bla Bla.avi
C:\Video\Gone In 60 Seconds SoundTrack.avi
C:\Video\Guns N Roses - Welcome To The Jungle.avi
C:\Video\Kiss Strutter.avi
C:\Video\Marshall Jefferson - Move Your Body.avi
C:\Video\Masterboy - Is this the love.avi
C:\Video\Michael Jackson - I'm BAD.avi
C:\Video\Ozzy Osbourne - HellRaiser.avi
C:\Video\Rihanna SOS.avi
C:\Video\Scorpions_-_Rock_You_Like_A_Hurricane.avi
C:\Video\SWINE.avi
C:\Video\The GAP Band - You Dropped A Bomb On Me.avi
C:\Video\Toto - Hold the line.avi

I want to build a program that edits the 1.m3u file like this :

Line 2 - 25 (Or whatever the last line nuber is) is my target

These lines will be in a new random order each time I launch the program

Does anyone know how to do this in Batch, Java or C++ ?



If you install Cygwin to get the bash shell and the normal GNU utilities like head, tail and sort, you could do it like this. (I haven't tested this code.)

Code: [Select]$!/bin/sh
test -w "$1" || exit 1
TEMPFILE=/tmp/$$.tmp
head -n1 $1 > $TEMPFILE
tail -n+2 $1 | sort -R >>$TEMPFILE
mv -f $TEMPFILE $1
Name this file randomize and then at the bash prompt execute:
$ randomize 1.m3uWell, that code works in half

It does randomize the m3u file - But VLC won't deal with it and plays all files in the same way all the time - no matter of how many times i launch the batch file

One detail I didn't think of until now is the line ending. Most Windows apps expect a sequence at the end of every line. But I think Cygwin will do the Linux default, which is to write only a .

You can use either the unix2dos or dos2unix -u2d commands to restore line endings.

If that's not the problem, are you sure the application is READING the input file?Well now I found out that this code won't work at all :

Code: [Select]$ randomize 123.m3u
"C:\VLC\vlc.exe" "123.m3u"
pause
It does nothing with the 123.m3u I originally put the $ there just to show that you were at the bash command prompt. You shouldn't type it or put it in a script. Sorry for the confusion. Also, it's not clear if that is running in a bash shell or the Windows CMD shell. (In theory, either should work.)

I just noticed vlc has a -Z or --random switch which will "play files randomly forever". At least the Linux version has it, so the Windows version probably does too. So maybe you don't need to use any script, just this command:

vlc -Z 123.m3uAny language which supports associative arrays and a randomizer should be able to do this.

Window machines come installed with VBScript. Here is one solution:

Code: [Select]Const ForReading = 1
Const ForWriting = 2

Set dct = CREATEOBJECT("Scripting.Dictionary")
Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("c:\temp\123.m3u", ForReading)
strHdr = f.ReadLine

Do While f.AtEndOfLine <> True
keynum = keynum + 1
strLine = f.ReadLine
dct.Add keynum, strLine
Loop
f.Close

Set f = fso.OpenTextFile("c:\temp\123.m3u", ForWriting)
f.WriteLine(strHdr)

Do Until dct.Count= 0
Randomize
key = Int((keynum - 1 + 1) * Rnd + 1)
If dct.Exists(key) Then
f.WriteLine(dct.Item(key))
dct.Remove(key)
End If
Loop
f.Close

Change any path specifications as needed. Save script with a vbs extension and run from the command prompt as cscript scriptname.vbs

Good luck. Sidewinder - That code works well

Thanks both of you for helping me out...

------------------------------------------------------------------------

BTW: Is there anywhere I can learn VB for free ?

I have worked with these languages so far :

Batch
HTML
Flash Action Script 1.0
Java
C++
GML
Delphi (- Not very much, just a Hello World Looper)



Discussion

No Comment Found