Batch m3u playlist creation for all folders, with the playlist named like the folder |
![]() ![]() |
Batch m3u playlist creation for all folders, with the playlist named like the folder |
Jul 3 2006, 19:54
Post
#1
|
|
|
Group: Members Posts: 22 Joined: 30-April 05 Member No.: 21806 |
I've been trying to find an easy way to do this, but I can't seem to find exactly what I need. I just want a simple way to:
Any help is appreciated. |
|
|
|
Jul 3 2006, 22:05
Post
#2
|
|
![]() Group: Members Posts: 15 Joined: 10-May 02 Member No.: 2014 |
I've been trying to find an easy way to do this, but I can't seem to find exactly what I need. I just want a simple way to:
This script should sort you out: CODE Const ForReading = 1, ForWriting = 2, ForAppending = 8 delete = false set args = WScript.Arguments if args.Count > 0 then if LCase(args(0)) = "-d" then delete = true end if end if set fso = createobject("scripting.filesystemobject") wscript.echo WriteM3u(fso.GetAbsolutePathName("."), delete) & " files written" function WriteM3u(path, delete) dim count set fso = createobject("scripting.filesystemobject") set fdr = fso.GetFolder(path) if fdr.SubFolders.Count = 0 then m3u = path & "\" & fdr.name & ".m3u" if fso.FileExists(m3u) then if delete then wscript.echo "... deleting existing file" fso.DeleteFile m3u else wscript.echo "... renaming existing file" fso.MoveFile m3u, m3u & ".old" end if end if wscript.echo "... writing """ & fdr.name & ".m3u""" set m3ufile = fso.OpenTextFile(m3u, ForWriting, True) for each f in fdr.Files if right(f.Name, 3) = "mp3" or right(f.Name, 3) = "ogg" then m3ufile.WriteLine(f.Name) end if next m3ufile.Close count = 1 else count = 0 for each subfolder in fdr.subfolders wscript.echo "Searching """ & subfolder.path & """" count = count + WriteM3u(subfolder.path, delete) next end if WriteM3u = count end function Just save it to "WriteM3u.vbs" and stick it in the root directory of your mp3 and ogg files. To run, type: CODE cscript WriteM3u.vbs By default it will rename any existing m3u files it finds. If you would rather delete them, just add "-d" to the end of the command-line, i.e. CODE cscript WriteM3u.vbs -d -Paul |
|
|
|
Jul 4 2006, 00:04
Post
#3
|
|
|
Group: Members Posts: 12 Joined: 18-October 05 Member No.: 25195 |
TAG can also do this from the command line. I use Speek's tag frontend, as the number of switches can be quite intimidating.
|
|
|
|
Jul 4 2006, 01:14
Post
#4
|
|
|
Group: Members Posts: 53 Joined: 26-July 05 Member No.: 23534 |
Thank you Paul, this is a nice and useful script
|
|
|
|
Jul 4 2006, 21:08
Post
#5
|
|
![]() Group: Members Posts: 15 Joined: 10-May 02 Member No.: 2014 |
|
|
|
|
Jul 5 2006, 22:51
Post
#6
|
|
|
Group: Members Posts: 22 Joined: 30-April 05 Member No.: 21806 |
Yeah, thanks, it's awesome. If you wrote it yourself, maybe you could help me make one modification to it? It doesn't work right for albums with multiple CDs, because my folder structure for them looks like this:
Foldername\Disc 1\ Foldername\Disc 2\ Right now the script writes: Foldername\Disc 1\Disc 1.m3u Foldername\Disc 2\Disc 2.m3u Is there any way to make it write (ideal): Foldername\Disc 1\Foldername (Disc 1).m3u Foldername\Disc 2\Foldername (Disc 2).m3u or: Foldername\Foldername (Disc 1).m3u Foldername\Foldername (Disc 2).m3u or even: Foldername\Foldername.m3u (with files from both folders) This would make the script supremely useful for me, hope you can do it This post has been edited by zambaretzu: Jul 5 2006, 22:54 |
|
|
|
Jul 6 2006, 18:04
Post
#7
|
|
![]() Group: Members Posts: 15 Joined: 10-May 02 Member No.: 2014 |
Yeah, thanks, it's awesome. If you wrote it yourself, maybe you could help me make one modification to it? It doesn't work right for albums with multiple CDs, because my folder structure for them looks like this: Foldername\Disc 1\ Foldername\Disc 2\ ... No problem zambaretzu. Try this: CODE Const ForReading = 1, ForWriting = 2, ForAppending = 8 delete = false set args = WScript.Arguments if args.Count > 0 then if LCase(args(0)) = "-d" then delete = true end if end if set fso = createobject("scripting.filesystemobject") wscript.echo WriteM3u(fso.GetAbsolutePathName("."), delete) & " files written" function WriteM3u(path, delete) dim count set fso = createobject("scripting.filesystemobject") set fdr = fso.GetFolder(path) if fdr.SubFolders.Count = 0 then if len(fdr.Name) = 6 and left(fdr.Name, 5) = "Disc " then m3uName = fdr.ParentFolder.Name & " (" & fdr.Name & ").m3u" else m3uName = fdr.Name & ".m3u" end if m3u = path & "\" & m3uName if fso.FileExists(m3u) then if delete then wscript.echo "... deleting existing file" fso.DeleteFile m3u else wscript.echo "... renaming existing file" fso.MoveFile m3u, m3u & ".old" end if end if wscript.echo "... writing """ & m3uName & """" set m3uFile = fso.OpenTextFile(m3u, ForWriting, True) for each f in fdr.Files if right(f.Name, 3) = "mp3" or right(f.Name, 3) = "ogg" then m3uFile.WriteLine(f.Name) end if next m3uFile.Close count = 1 else count = 0 for each subFolder in fdr.SubFolders wscript.echo "Searching """ & subFolder.Path & """" count = count + WriteM3u(subFolder.path, delete) next end if WriteM3u = count end function |
|
|
|
Jul 6 2006, 20:49
Post
#8
|
|
|
Group: Members Posts: 22 Joined: 30-April 05 Member No.: 21806 |
Thanks a lot masterofimages.
There's still a small issue: for some albums, I have artwork, stored under \Foldername\art\. The script writes an empty \Foldername\art\art.m3u but no \Foldername\Foldername.m3u like it should. |
|
|
|
Jul 7 2006, 01:22
Post
#9
|
|
![]() Group: Members Posts: 15 Joined: 10-May 02 Member No.: 2014 |
Thanks a lot masterofimages. There's still a small issue: for some albums, I have artwork, stored under \Foldername\art\. The script writes an empty \Foldername\art\art.m3u but no \Foldername\Foldername.m3u like it should. So it does CODE Const ForReading = 1, ForWriting = 2, ForAppending = 8
' Parse command-line arguments delete = false set args = WScript.Arguments if args.Count > 0 then if LCase(args(0)) = "-d" then delete = true end if end if ' Write m3u files for current directory tree set fso = CreateObject("Scripting.FileSystemObject") wscript.echo WriteM3u(fso.GetAbsolutePathName("."), delete) & " files written" ' Recursive function to write m3u files for a given path function WriteM3u(path, delete) count = 0 set fso = CreateObject("Scripting.FileSystemObject") set fdr = fso.GetFolder(path) ' Write m3u file for each subfolder if fdr.SubFolders.Count > 0 then for each subFolder in fdr.SubFolders count = count + WriteM3u(subFolder.path, delete) next end if ' If no files found in subfolders, write m3u file for this folder if count = 0 then wscript.echo "Scanning """ & fdr.Path & """" ' Build list of mp3/ogg files mp3List = "" for each f in fdr.Files if right(f.Name, 3) = "mp3" or right(f.Name, 3) = "ogg" then mp3List = mp3List & f.Name & VBCrLf end if next ' If any files found, write m3u file if mp3List <> "" then ' Multi-disc folder handling if len(fdr.Name) = 6 and left(fdr.Name, 5) = "Disc " then m3uName = fdr.ParentFolder.Name & " (" & fdr.Name & ").m3u" else m3uName = fdr.Name & ".m3u" end if ' Existing m3u file handling m3u = path & "\" & m3uName if fso.FileExists(m3u) then if delete then wscript.echo "... deleting existing file" fso.DeleteFile m3u else wscript.echo "... renaming existing file" fso.MoveFile m3u, m3u & ".old" end if end if ' Write new m3u file wscript.echo "... writing """ & m3uName & """" set m3uFile = fso.OpenTextFile(m3u, ForWriting, True) m3uFile.Write(mp3List) m3uFile.Close count = 1 else wscript.echo "... no mp3/ogg files found" end if end if ' Return m3u file count WriteM3u = count end function |
|
|
|
Jul 12 2006, 01:00
Post
#10
|
|
|
Group: Members Posts: 22 Joined: 30-April 05 Member No.: 21806 |
Thank you, thank you!
This post has been edited by zambaretzu: Jul 12 2006, 01:00 |
|
|
|
Jul 24 2006, 14:26
Post
#11
|
|
|
Group: Members Posts: 2 Joined: 8-July 06 Member No.: 32699 |
Thanks for the great script!! Is it possible to make it name the playlists Artist - Album.m3u using the name of the album's containing folder?
|
|
|
|
Jan 5 2013, 15:52
Post
#12
|
|
|
Group: Members Posts: 1 Joined: 5-January 13 Member No.: 105611 |
I had been looking for an automated way to create folder based playlists for over 4 years. Today I got lucky and came across this thread. The script kindly shared by masterofimages worked beautifully and solved my problem.
Thank you so much. |
|
|
|
Jan 27 2013, 11:53
Post
#13
|
|
|
Group: Members Posts: 1 Joined: 28-December 09 Member No.: 76423 |
It would be perfect if the files were order by name.
This script produce a caual (not ordered) list of mp3 files inside the folders, producing an inconsistent playlist. |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 22nd May 2013 - 18:05 |