Solution: Copy new music to main folder and update Subsonic

General discussions.

Moderator: moderators

Solution: Copy new music to main folder and update Subsonic

Postby headcase59 » Thu Jul 21, 2011 3:47 pm

For Windows only.

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
headcase59
 
Posts: 8
Joined: Thu Jul 21, 2011 3:06 pm

Return to General

Who is online

Users browsing this forum: No registered users and 12 guests