搜索
熱搜: 活動 交友 discuz
查看: 2624|回復: 0
打印 上一主題 下一主題

以程式控制FOOBAR的播放等動作

  [複製鏈接]
跳轉到指定樓層
1#
發表於 2007-7-27 20:54:05 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
'***** 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
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

本論壇為非營利之網路平台,所有文章內容均為網友自行發表,不代表論壇立場!若涉及侵權、違法等情事,請告知版主處理。


Page Rank Check

廣告刊登  |   交換連結  |   贊助我們  |   服務條款  |   免責聲明  |   客服中心  |   中央分站

手機版|中央論壇

GMT+8, 2024-4-29 14:00 , Processed in 0.462301 second(s), 16 queries .

Powered by Discuz!

© 2005-2015 Copyrights. Set by YIDAS

快速回復 返回頂部 返回列表