|
'***** foobar2000 control script v1.0a
'***** by: blert
'***** last update: 8/24/03
'***** README
' This script controls Foobar2000 ( http://www.foobar2000.org/ )
' by the use of command line parameters and Foobar2000 keyboard shortcuts.
'
' CoolMon link that tells Foobar2000 to play:
' <LINK="x:\path\to\fb2k_control.vbs" param="play">
'
' Valid parameters:
' play ... fire it up, man!
' paws ... hang on, gotta scratch the cat.
' stop ... enough already!
' prev ... what the hell was that?
' next ... yeah, yeah.
'***** SETUP
' The following six variables need to match what Foobar2000
' says they are: Foobar2000->Preferences->Keyboard Shortcuts.
fb2kplay = "c" ' play (default = "c")
fb2kpause = "x" ' pause (default = "x")
fb2kstop = "z" ' stop (default = "z")
fb2kprevious = "+v" ' previous song (default = "+v")
fb2knext = "v" ' next song (default = "v")
fb2ksearch = "^f" ' playlist search (default = "^f")
' Keystroke syntax can be found here:
' http://msdn.microsoft.com/librar ... l/wsmthsendkeys.asp
' This script will automatically check to see if you are
' running the most recent version of Foobar2000 and output a
' color tag to a text file so you can tag something in CoolMon
' with it if you want. This will only work if you send
' %_foobar2000_version% along in your "Play String" to your
' text file using the "Text writer" plugin for Foobar2000...
' Can be found here... http://fb2k-plugins.hydrogenaudio.org/General.html
' Example: Foobar2000->Preferences->Text writer->Playing string...
' $if(%_is_paused%,Foobar2K$char(13)$char(10)Paused$char(13)$char(10)$char(13)$char(10),Artist$char(13)$char(10)%artist%$char(13)$char(10)Title$char(13)$char(10)%title%$char(13)$char(10)%_foobar2000_version%)
' The example will put the version you are running on line five
' of the text file while playing.
' The following eight variables deal with this.
checkforupdate = "y" ' y/n ... if no, don't worry about the rest
opath = "fb2k_update.txt" ' path\filename to output text file
foobarpath = "F:\foobar2000\" ' path to your Foobar2000 directory
ipath = "nowplaying.txt" ' filename of your Foobar2000 nowplaying.txt
linenumber = 5 ' line number to find Foobar version
normalcolor = "<c:green>" ' no update available color
alertcolor = "<c:yellow>" ' update available color
errorcolor = "<c:red>" ' error color
'***** NO USER DEFINABLE VARIABLES BELOW THIS POINT
' It would not be wise to futz with the stuff below...
' ...but hey, we all know you are going to anyway. XP
'*****
on error resume next
dim pid
set argobj = wscript.arguments
fb2kcommand = argobj(0)
set colitems = getobject("winmgmts:{impersonationLevel=impersonate}").instancesof ("win32_process")
for each item in colitems
if item.name = "foobar2000.exe" then
pid = item.processid
end if
next
if pid <> "" then
set wshshell = wscript.createobject("wscript.shell")
wshshell.appactivate pid
wscript.sleep 100
select case lcase(fb2kcommand)
case "play"
WshShell.SendKeys fb2kplay
if lcase(checkforupdate) = "y" then
updatecheck()
end if
case "paws"
WshShell.SendKeys fb2kpause
case "stop"
WshShell.SendKeys fb2kstop
case "prev"
WshShell.SendKeys fb2kprevious
case "next"
WshShell.SendKeys fb2knext
case "srch"
WshShell.SendKeys fb2ksearch
end select
end if
function updatecheck()
set http = createobject("microsoft.xmlhttp")
http.open "GET","http://www.foobar2000.org/", false
http.send
strng = deHTML(http.responsetext)
dim regex
set regex = new regexp
regex.global = true
regex.pattern = "Current version: (.*?)<ul>"
set matches = regex.execute(strng)
currentver = "foobar2000 v" & trim(matches(0).submatches(0))
set fs = createobject("scripting.filesystemobject")
wscript.sleep 1000
set textfile = fs.opentextfile(foobarpath & ipath, 1)
if linenumber = 1 then
installedver = textfile.readline
else
for i = 1 to linenumber - 1
textfile.skipline
next
installedver = textfile.readline
end if
textfile.close
if (left(installedver,12) <> "foobar2000 v") then
installedver = "error"
end if
set ofile = fs.createtextfile(opath, true)
ofile.writeline "Version posted on website: " & currentver
ofile.writeline "Installed version: " & installedver
select case installedver
case "error"
ofile.writeline errorcolor
case currentver
ofile.writeline normalcolor
case else
ofile.writeline alertcolor
end select
ofile.close
end function
function deHTML(st)
st = replace(st,vbLf," ")
st = replace(st,vbCr," ")
st = replace(st,vbCrLf," ")
st = replace(st," "," ")
for i = 0 to 10
st = replace(st," "," ")
next
deHTML = st
end function |
|