In this post, I talk about my challenges of finding an application to use with my Sansa and podcasts. Well, I settled on Juice. But, I still had an issue with playlists. Juice allows you to launch a program after a file is downloaded, so I decided to write a script to do what I want. I thought I would post it here just in case anyone else is looking to do the same thing.
Here are the steps to get the script to work with Juice (I’m going to assume you already have downloaded Juice, installed it, and have several podcasts actively downloading. I have Juice 2.2. If you have a different version, the instructions may be a bit different.):
- Download the script (right-click this link and choose save target as. Remember where you save the file)
- Launch Juice
- Go to File –> Preferences
- Go to the Advanced Tab
- Check the “Run this command after each download” checkbox
- In the text box, enter the following text (making the correct replacements, of course): BuildPlaylist.vbs “” “%n” “%f”
- PathToVBS is the location you saved the vbs to when you downloaded it.
- PathToPlaylistFIles is probably something like c:Documents and SettingsMy DocumentsMy MusicMy Playlists
- You want to enclose each item in ” (those are double quote marks). That way, Windows won’t barf on spaces
- Click the Save button
That’s it. If you need some help, just let me know. E-mail me at matt (at) techs4esus.com.
The script is below (or click here to download it):
””””””””””””””””””””””””
”Written By: Matthew Maxson (matt@techs4jesus.com)
”Date: 1 Jan 2007
”Copyright (c) Matthew Maxson
”This program is free software; you can redistribute it and/or modify
”it under the terms of the GNU General Public License as published by
”the Free Software Foundation; either version 2 of the License, or
”(at your option) any later version.
”
”This program is distributed in the hope that it will be useful,
”but WITHOUT ANY WARRANTY; without even the implied warranty of
”MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
”GNU General Public License for more details.”You should have received a copy of the GNU General Public License
”along with this program; if not, write to the Free Software
”Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
”
”To view the GPL, visit http://www.gnu.org/licenses/gpl.txt
””””””””””””””””””””””””
Option ExplicitDim args
Dim num
Dim i
Dim fs
Dim fname
Dim WPLPath
Dim PlaylistName
Dim PathToAdd
Dim objTextFile
Dim objFSOFunction SortedFiles(objFolder, strFilePattern, strSortedBy, blnReverse)
‘From
”http://www.fpschultze.de/smartfaq+faq.faqid+124+PHPSESSID+8d9ee6d45fbecaf8b122c956a124ea58.htm
”Used with permissionConst TEMP_FOLDER = 2
Const WINDOW_STYLE_HIDDEN = 0Dim objWS, objFS, objFiles, objFile
Dim strCmdLine, strTmpFile
Dim tmpArray
Dim iSortedFiles = Array()
Set objFS = WScript.CreateObject(“Scripting.FileSystemObject”)
Set objWS = WScript.CreateObject(“WScript.Shell”)
strTmpFile = objFS.GetSpecialFolder(TEMP_FOLDER) & “” & objFS.GetTempName
strCmdLine = “%ComSpec% /C DIR ” & Chr(34) & objFolder.Path
If Right(strCmdLine, 1) “” Then strCmdLine = strCmdLine & “”
strCmdLine = strCmdLine & strFilePattern & Chr(34) & ” /B /A-D /O”
If blnReverse Then strCmdLine = strCmdLine & “-“
Select Case LCase(strSortedBy)
Case “name” strCmdLine = strCmdLine & “N”
Case “size” strCmdLine = strCmdLine & “S”
Case “ext” strCmdLine = strCmdLine & “E”
Case “datetime” strCmdLine = strCmdLine & “D”
Case Else Exit Function
End Select
strCmdLine = strCmdLine & ” > ” & strTmpFile
objWS.Run strCmdLine, WINDOW_STYLE_HIDDEN, True
If objFS.FileExists(strTmpFile) Then
If objFS.GetFile(strTmpFile).Size > 0 Then
tmpArray = Split(objFS.OpenTextFile(strTmpFile).ReadAll, vbNewLine)
objFS.DeleteFile(strTmpFile)
ReDim Preserve tmpArray(UBound(tmpArray) – 1)
Set objFiles = objFolder.Files
For i = 0 to UBound(tmpArray)
Set objFile = objFiles((tmpArray(i)))
Set tmpArray(i) = objFile
Next
SortedFiles = tmpArray
End If
End IfEnd Function
function DoesPlaylistExist(ThePathToWPLFiles, ThePlaylistName)
”we need to figure out if the playlist already exists or not
Dim FSO
Dim TheReturnset FSO = CreateObject(“Scripting.FileSystemObject”)
if FSO.FileExists(ThePathToWPLFiles & ThePlaylistName) then
TheReturn = True
else
TheReturn = False
end ifset FSO = nothing
DoesPlaylistExist = TheReturnend function
function CreatePlaylistHeader(ThePlaylistTitle)
”helper function to create the header
Dim TheReturnTheReturn = “” & vbCRLF
TheReturn = TheReturn & “” & vbCRLF
TheReturn = TheReturn & “” & vbCRLF
TheReturn = TheReturn & “” & vbCRLF
TheReturn = TheReturn & “” & vbCRLF
” & Replace(Replace(ThePlaylistTitle, “.wpl”, “”), “_”, ” “) & “_SCRIPT TheReturn = TheReturn & “” & vbCRLF
TheReturn = TheReturn & “” & vbCRLF
TheReturn = TheReturn & “” & vbCRLF
TheReturn = TheReturn & “” & vbCRLFCreatePlaylistHeader = TheReturn
end functionfunction CreatePlaylistFooter()
”helper function to create the footer of the playlist
Dim TheReturnTheReturn= “” & vbCRLF
TheReturn= TheReturn & “” & vbCRLF
TheReturn= TheReturn & “” & vbCRLFCreatePlaylistFooter = TheReturn
end functionsub MakeNewPlaylist(ThePathToWPLFiles, ThePlaylistName, TheFileToAdd)
”we’ll use this to make a new playlist
Dim FSO
Dim fileset FSO = CreateObject(“Scripting.FileSystemObject”)
set file = FSO.CreateTextFile(ThePathToWPLFiles & ThePlaylistName,true)
file.WriteLine(CreatePlaylistHeader(Replace(Replace(ThePlaylistName, “.wpl”, “”), “_”, ” “)))file.WriteLine(“” & vbCRLF)
file.WriteLine(CreatePlaylistFooter())
file.Close
set file = nothing
set FSO = nothing
end subfunction GetDirectory(TheFileToAdd)
”use this function to split the path/file passed in. This will allow us to include other
”files in the same directory
Dim TheReturnTheReturn = Left(TheFileToAdd, InStrRev(TheFileToAdd, “”))
GetDirectory = TheReturn
end functionsub EditExistingPlaylist(ThePathToWPLFiles, ThePlaylistName, TheFileToAdd)
”if we need to edit an existing playlist, we’ll use this file
Dim DirToCheck
Dim DirFileList
Dim Folder
Dim FSO
Dim file
Dim Filenamestr
Dim PlaylistFilenameDirToCheck = GetDirectory(TheFileToAdd)
set FSO = CreateObject(“Scripting.FileSystemObject”)
set Folder = FSO.GetFolder(DirToCheck)
DirFileList = SortedFiles(Folder, “*.mp3”, “datetime”, false)set PlaylistFilename = FSO.CreateTextFile(ThePathToWPLFiles & ThePlaylistName,true)
PlaylistFilename.WriteLine(CreatePlaylistHeader(Replace(Replace(ThePlaylistName, “.wpl”, “”), “_”, ” “)))for each file in DirFileList
PlaylistFilename.WriteLine(“” & vbCRLF)
nextPlaylistFilename.WriteLine(CreatePlaylistFooter())
PlaylistFilename.Close
set PlaylistFilename = nothing
set FSO = nothing
end sub‘ OpenTextFile Method needs a Const value
‘ ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8set args = WScript.Arguments
num = args.Countif num = 0 then
WScript.Echo “Usage: BuildPlaylist.vbs “
WScript.Quit 1
end ifWPLPath = args.Item(0)
if Right(WPLPath, 1) “” then
WPLPath = WPLPath & “”
end ifPlaylistName = Replace(Replace(Replace(args.Item(1), “:”, “”), “.”, “”), ” “, “_”) & “.wpl”
PathToAdd = args.Item(2)if DoesPlaylistExist(WPLPath, PlaylistName) then
EditExistingPlaylist WPLPath, PlaylistName, PathToAdd
elseMakeNewPlaylist WPLPath, PlaylistName, PathToAdd
end if
[Update 2012-12-19 06:59:42] In getting ready to migrate my website, I found some broken links. Fixed the link to the script.