All pastes #1688088 Raw Edit

foobar2000 display

public text v1 · immutable
#1688088 ·published 2009-11-26 13:39 UTC
rendered paste body
; 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,FormatTitle,1,bstr,$1-)
  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 %fb2k_default_format fb2k %sep $field(artist) %sep $field(title) %sep $field(album) %sep $field(length) %sep $field(codec) $field(bitrate) kbps %sep
  return $fb2k_get_current_format(%fb2k_default_format)
}

alias aud {
  say $fb2k_get_current
}