Playlist Exporter to .PLA files
Posted: Sun Jun 18, 2006 9:02 pm
I modified the ExportM3Us.vbs script to export all playlists in MediaMonkey to .pla files to be used with my Sandisk Sansa E200 series MP3 player. It may work for other devices that use PLA/PLP files. It assumes that you use "\Music\Album Artist\Album\Filename" when you sync your tracks to the player.
This did take very long to modify. If there are more options that would make this more useful let me know and I can try to make the changes.
<-IJuan->
This did take very long to modify. If there are more options that would make this more useful let me know and I can try to make the changes.
Code: Select all
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' This file is a modifed version of the ExportM3U.vbs
' script. This was created to make playlist for the Sandisk
' Sansa E200 series mp3 player. It may work with other mp3
' players that use PLA/PLP playlist files. Here is a sample
' of what can be added to the Scripts.ini file.
'
'[ExportPLAs]
'FileName=ExportPLAs.vbs
'ProcName=ExportPLAs
'Order=45
'DisplayName=Export all Playlists to PLA...
'Description=Exports all Playlists to .pla
'Language=VBScript
'ScriptType=0
'
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Option Explicit ' report undefined variables, ...
' SDB variable is connected to MediaMonkey application object
' Recursively process all playlists
Sub ReadPlaylists( playlists, plst, prefix)
Dim items
Set items = plst.ChildPlaylists
If prefix<>"" Then
prefix = prefix & " - "
End If
Dim i, newplst, title
For i=0 To items.Count-1
Set newplst = items.Item(i)
title = prefix & newplst.Title
If Not playlists.exists(title) Then
playlists.Add title, newplst
End If
ReadPlaylists playlists, newplst, title
Next
End Sub
Function AddSpacing(strOriginal)
Dim strWithSpacing, i
For i = 1 to len(StrOriginal)
strWithSpacing = strWithSpacing & Mid(strOriginal, i, 1) & Chr(00)
Next
AddSpacing = strWithSpacing & Chr(13) & Chr(00) & Chr(10) & Chr(00)
End Function
Function GetFileName(FullPath)
Do While InStr(FullPath, "\") <> 0
FullPath = Mid(FullPath, Instr(FullPath, "\") + 1)
Loop
GetFileName = FullPath
End Function
Sub ExportPLAs
' Open inifile and get last used directory
Dim iniF
Set iniF = SDB.IniFile
' Let user select the output path
Dim path
path = iniF.StringValue( "Scripts", "LastExportPLAsDir")
path = SDB.SelectFolder( path, SDB.Localize( "Select where to export all PLA/PLP files."))
If path="" Then
Exit Sub
End If
If Right( path, 1)<>"\" Then
path = path & "\"
End If
' Write selected directory to the ini file
iniF.StringValue( "Scripts", "LastExportPLAsDir") = path
Set iniF = Nothing
' Connect to the FileSystemObject
Dim fso
Set fso = SDB.Tools.FileSystem
Dim playlists
Set playlists = CreateObject("Scripting.Dictionary")
' Use progress to notify user about the current action
Dim Progress, ExpText
Set Progress = SDB.Progress
ExpText = SDB.Localize("Exporting...")
Progress.Text = ExpText
' Prepare a list of all playlists
ReadPlaylists playlists, SDB.PlaylistByTitle( ""), ""
' Go through the list and export each playlist
Dim i, iTrck, plst, fout, plsts, titles, title, tracks, trck, ln', tlen, art, tit
plsts = playlists.Items
titles = playlists.Keys
Progress.MaxValue = playlists.count
For i=0 To playlists.Count-1
Set plst = plsts(i)
Set tracks = plst.Tracks
title = Titles(i)
Progress.Text = ExpText & " (" & title & ")"
Set fout = fso.CreateTextFile( path & fso.CorrectFilename(title) & ".pla", True)
fout.Write AddSpacing("PLP PLAYLIST")
fout.Write AddSpacing("VERSION 1.20")
fout.Write AddSpacing("")
If tracks.Count>0 Then
For iTrck=0 To tracks.Count-1
Set trck = tracks.Item(iTrck)
ln = "HARP, MUSIC\" & trck.ArtistName & "\" & trck.AlbumName & "\" & GetFileName(trck.Path)
fout.Write AddSpacing(ln)
Next
fout.Close
End If
Progress.Value = i+1
Next
End Sub