Squeezebox Server thumbnail creator

This script creates thumbnails for all cover images in the selected folder and subfolders. This speeds up the listings in Squeezebox. It uses Graphicsmagick for the actual converting.

I made this script because there was no easy way to do this in windows as there is no good find command like in *nix.

Save the script below as thumber.vbs and run from the command line:

cscript thumber.vbs "foldername"

Example:

cscript thumber.vbs "c:\My Music"

The script:

  1. Dim fso, folder, folderName, coverFilenames, convertCommand, targetFilename
  2.  
  3. ' Change this if you use other filenames
  4. coverFilenames = "FOLDER.JPG,COVER.JPG"
  5.  
  6. ' Change this if you want to use another target filename
  7. targetFilename = "thumb.jpg"
  8.  
  9. ' Change this if you want to use different parameters for converting the image
  10. convertCommand = "gm convert -resize 50x50 ""#SOURCEFILENAME#"" ""#TARGETFILENAME#"""
  11.  
  12. If Wscript.Arguments.Count <> 1 Then
  13. WScript.Echo "Run from the command line: cscript thumber.vbs ""foldername"""
  14. Wscript.Quit
  15. End If
  16.  
  17. folderName = Wscript.Arguments(0)
  18.  
  19. Set fso = CreateObject("Scripting.FileSystemObject")
  20. Set oShell = WScript.CreateObject ("WScript.Shell")
  21.  
  22. If Not fso.FolderExists(folderName) Then
  23. WScript.Echo "The folder """ & folderName & """ does not exist"
  24. Wscript.Quit
  25. End If
  26.  
  27. WScript.Echo "Scanning """ & folderName & """"
  28.  
  29. Set folder = fso.GetFolder(folderName)
  30.  
  31. processFolders(folder)
  32.  
  33. Function processFolders(folder)
  34. Dim subfolder
  35.  
  36. processFiles(folder)
  37.  
  38. For Each subfolder in folder.SubFolders
  39. processFolders(subfolder)
  40. Next
  41. Set subfolder = Nothing
  42. End Function
  43.  
  44. Function processFiles(folder)
  45. Dim file, fileNames, cmd
  46.  
  47. For Each file in folder.Files
  48. If InStr(coverFilenames, UCase(file.name)) > 0 Then
  49. cmd = convertCommand
  50. cmd = Replace(cmd,"#SOURCEFILENAME#",file.Path)
  51. cmd = Replace(cmd,"#TARGETFILENAME#",file.ParentFolder & "\" & targetFilename)
  52. Set cmdOutput = oShell.Exec(cmd)
  53. WScript.Echo cmdOutput.StdOut.ReadAll
  54. End If
  55. Next
  56. Set file = Nothing
  57. End Function
  58.