rem Option Explicit
dim m3u, aText, nLines, fso, dialog

Dim Textzeile
Dim Zeile
Dim Wrong
Dim LastZeile
Dim strLVText
Dim stred
Dim Laenge_Text
Dim FileTitle
Dim FileExt
Dim Laenge_tmp
Dim F
Dim artist
Dim Interpret(50)
Dim Titel(50)
Dim hr(50)
Dim mt(50)
Dim Laenge(50)
Dim Gesamtlaenge
Dim geshr
Dim gesmt
Dim girl

girl = 1
set fso = CreateObject("Scripting.FileSystemObject")

n = 0
Gesamtlaenge = 0

Dim oShExt, code

' create object reference
Set oShExt = WScript.CreateObject("ShellExtension.ShellObjects")
Set WSHShell = WScript.CreateObject("WScript.Shell")

' now we set the properties of the dialog
oShExt.WSHDialogTitle = "Playlists"  ' Title
oShExt.WSHDialogFilter = "All files (*.*)" & chr(0) & _
                         "*.*" & chr(0) & _
                         "m3u files (*.m3u)" & chr(0)

oShExt.WSHDialogFilterIndex = 2  ' 2nd entry selected

oShExt.WSHDialogInitDir = "C:\"  ' empty string = current directory

If oShExt.WSHShowOpen () <> 0 Then 
  MsgBox "Es geht los !", vbOKOnly + vbExclamation,"Aus M3U wird CDC"
Else
 MsgBox "Sorry, no file selected"
End if


cdcfile = Trim(oShExt.WSHDialogFile)
cdcfile = Left(cdcfile, Len(cdcfile) - 4)
cdcfile = cdcfile + "cdc"


set readfile = fso.OpenTextFile(oShExt.WSHDialogFile, 1, false)
set writefile = fso.OpenTextFile(cdcfile, 2, true)

do while readfile.AtEndOfStream <> true

    	contents = readfile.ReadLine
	' Zeile in Variable einlesen.

          If Zeile = 1 And contents <> "#EXTM3U" Then
          Wrong = True
          End If

	  If Left(contents, 8) = "#EXTINF:" Then
		n = n + 1
          ' zusätzliche Infos der zuletzt eingelesenen
          ' Zeile auswerten
          	strLVText = Right(contents, Len(contents) - 8)
          
          	' Länge (Spieldauer) ermitteln
          	stred = InStr(strLVText, ",")
		pos = stred
          	If stred > 0 Then
            		Laenge(n) = Left(strLVText, stred - 1)
            		hr(n) = Int(FormatNumber(Laenge(n))/60)
			mt(n) = (FormatNumber(Laenge(n)) mod 60) + 1
			rem MsgBox CStr(hr(n)) + ":" + CStr(mt(n))
		End If
		Gesamtlaenge = Gesamtlaenge + Laenge(n)

		' Interpret
		stred = InStr(strLVText, "-")
		If stred > 0 Then
            		Interpret(n) = Mid(strLVText, pos + 1, stred - 5)
			
		End If
						
		' Titel
		Titel(n) = Mid(strLVText, stred + 2, Len(strLVText))
		rem MsgBox Laenge(n)
 	
	  End If
loop
	for a = 2 to n
	boy = StrComp(Interpret(a), Interpret(a-1))
		if boy <> 0 then
		girl = 0
		end if
	next

	if girl = 0 then
	artist = InputBox("Welche","Interpreten ?","Beatles", 100, 100)
	else
	artist = Interpret(n)
	End If
readfile.close

geshr = Int(FormatNumber(Gesamtlaenge)/60)
gesmt = (FormatNumber(Gesamtlaenge) mod 60) + 1

title = InputBox("Titeleingabe","Albumtitel","White Album", 100, 100)

' Write CDC collection info
writefile.WriteLine("[Parameters]")
writefile.WriteLine("Language=English")
writefile.WriteLine("[CDINFO]")
writefile.WriteLine("Type=Audio-CD")
writefile.WriteLine("Title=" & title)
writefile.WriteLine("Artist=" & artist)
writefile.WriteLine("Tracks=" & CStr(n))
writefile.WriteLine("Playtime=" & CStr(geshr) + ":" + CStr(gesmt))

x=0
do while x <> n
x=x+1
writefile.WriteLine("[Track" & CStr(x) & "]")
writefile.WriteLine("Type=Audio-CD")
writefile.WriteLine("Artist=" & Interpret(x))
writefile.WriteLine("Title=" & Titel(x))
writefile.WriteLine("Playtime=" & CStr(hr(x)) + ":" + CStr(mt(x)))
loop

writefile.close
MsgBox "FERTICH"





