; Basic interface to the foobar2000 COM Automation Server component
; Only works with the 0.7 series of the fb2k COM Automation Server
;
; Currently only allows getting title formatted strings, but can be extended
; Mostly useful for now-playing scripts
;
; Script written by Niels Hansen (jfs) and may be freely distributed without limitations
; Customized by demi_alucard
alias fb2k_ensure_open {
if ($com(fb2kPlayback) != fb2kPlayback) {
if ($com(fb2k) != fb2k) {
.comopen fb2k Foobar2000.Application.0.7
if ($comerr == 0) {
}
else {
echo -a * Failed opening foobar2000 COM object
halt
}
}
echo -a * foobar200 Playback COM object not open, opening...
if ($com(fb2k,Playback,3,dispatch* fb2kPlayback) == 0) {
echo -a * Failed opening fooobar2000 Playback COM object
halt
}
}
}
alias fb2k_get_current_format {
fb2k_ensure_open
var %res = $com(fb2kPlayback,FormatTitleEx,1,bstr,$1-,int,3)
if (%res) {
return $com(fb2kPlayback).result
}
else {
echo -a * Failed getting title data from foobar2000
halt
}
}
alias -l field {
return $chr(37) $+ $1 $+ $chr(37)
}
alias fb2k_get_current {
var %sep 4::
var %artist $fb2k_get_current_format($field(artist))
var %title $fb2k_get_current_format($field(title))
var %album $fb2k_get_current_format($field(album))
var %date $fb2k_get_current_format($field(date))
var %_time_elapsed $fb2k_get_current_format($field(_time_elapsed))
var %length $fb2k_get_current_format($field(length))
var %bitrate $fb2k_get_current_format($field(bitrate))
var %codec $fb2k_get_current_format($field(codec))
var %fb2k_default_format fb2k %sep %artist %sep %title %sep %album ( $+ %date $+ ) %sep %_time_elapsed $+ / $+ %length %sep %bitrate $+ kb/s %codec %sep
return %fb2k_default_format
}
alias aud {
say $fb2k_get_current
}