I'm sharing this as it may help others to automate some things, including updating the Subsonic index when new music arrives.
Parts of this script could be used to suite other needs such as updating Subsonic every 5 or 10 minutes.
Copy/paste this into notepad and save with a .vbs extension:
- Code: Select all
'This script monitors a "completed music downloads" folder.
'
'Newly completed downloads are copied to a Subsonic music folder,
'and the Subsonic index is manually updated.
'
'In practice, I use the paid version of MediaMonkey to automatically organize
'my Subsonic music folder which takes place instantly after new files/folders
'are detected.
'To customize, make sure to change the sourceFolder and musicFolder paths
'and the Win32_Directory.Name path. Also, change the port #, YOURUSERNAME, and YOURPASSWORD in the "Manually update Subsonic index" section.
'
'I'm not a programmer so I apologize in advance for the sloppy code.
'Set paths for source and destination music folders
sourceFolder = "D:\Downloads\Complete\Music"
musicFolder = "D:\Music"
'Set WMI connection as local PC
strComputer = "."
'Create WMI connection
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Create filesystem connection
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set option to overwrite destination files if necessary
Const OverWriteFiles = True
'Monitor source folder for new items
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'Win32_SubDirectory' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""D:\\\\Downloads\\\\Complete\\\\Music""'")
'Copy new source folder items to destination folder
Do While True
Set objEventObject = colMonitoredEvents.NextEvent()
If objEventObject.Path_.Class = "__InstanceCreationEvent" Then
strFolder = objEventObject.TargetInstance.PartComponent
strFolder = Mid(strFolder, InstrRev(strFolder, "\"), Len(strFolder))
strFolder = Left(strFolder,len(strFolder)-1)
objFSO.CopyFolder sourceFolder & strFolder , musicFolder & strFolder , OverWriteFiles
'Manually update Subsonic index
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", "http://127.0.0.1:8001/login.view?user=YOURUSERNAME&password=YOURPASSWORD", False
xml.Send
Wscript.Sleep 20000
xml.Open "GET", "http://127.0.0.1:8001/searchSettings.view?update", False
xml.Send
End If
'Restart script to monitor for new items
Loop