All pastes #466116 Raw Edit

Mine

public text v1 · immutable
#466116 ·published 2007-04-30 20:31 UTC
rendered paste body
3B itunes.mrc v1.0 by d00dman@Efnet
;
; Apple has released the COM SDK for iTunes, yay.
; http://developer.apple.com/sdk/#iTunesCOM
;
; I hacked this little script together to query the current track
; information from iTunes.  It also serves as a nice example of using
; simple COM interfaces and the dispatch pointer from mIRC.
;
; There is a known side effect of using this script:
;
;   Every time you create a iTunes.Application object, it actually
;   launches iTunes.  This is to be expected, but can be annoying
;   if you don't always have iTunes open but still use the popups
;   for the status window and/or channel window.  I suggest that you
;   comment out the menu block below if you find this annoying.
;
; Comments and suggestions welcome: chris at d0rk dot org.
;
; $itunesinfo - returns "<artist> - <song>"
alias itunesinfo {
  var %itunes = $+(itunes., $ticks)
  var %track = $+(%itunes, .track)
  .comopen %itunes iTunes.Application
  itunes_comerr

  if (!$com(%itunes, CurrentTrack, 3, dispatch* %track)) itunes_comerr

  var %line

  ; if you're not playing anything, this will be a null ref
  if ($com(%track)) {
    %line = $trackinfo(%track).artist - $trackinfo(%track).name
    .comclose %track
  }

  .comclose %itunes

  return %line
}

; /showitunes [target]
alias showitunes {
  var %target = $1

  if (!%target) %target = $active
  if ($count(%target, $chr(32)) > 0) %target = $null

  var %itunes = $+(itunes., $ticks)
  var %track = $+(%itunes, .track)
  .comopen %itunes iTunes.Application
  itunes_comerr

  if (!$com(%itunes, CurrentTrack, 3, dispatch* %track)) itunes_comerr

  var %line

  if ($com(%track)) {
    %line =  $+ $trackinfo(%track).artist - $trackinfo(%track).name $+
    var %x

    ; only show album if it has one.
    ; exclude any album starting with ` (I have a "`Singles" album)
    %x = $trackinfo(%track).album
    if ((%x != $null) && (`* !iswm %x)) {
      %line = %line ( $+ %x

      ; only show track if its from a collection > 1
      if ($trackinfo(%track).trackcount > 1 && $trackinfo(%track).tracknumber > 0) {
        %line = %line $+([, $trackinfo(%track).tracknumber, /, $trackinfo(%track).trackcount, ])
      }

      ; only show disc if its from a collection > 1
      if ($trackinfo(%track).disccount > 1 && $trackinfo(%track).discnumber > 0) {
        %line = %line $+([, $trackinfo(%track).discnumber , /, $trackinfo(%track).disccount , ])
      }

      %line = %line $+ )

    }

    %line = %line $+([, $trackinfo(%track).time, ])

    .comclose %track
  }

  .comclose %itunes

  if (!%line) return

  if (!%target) echo $color(info) -ta * %line
  else msg %target %line
}

; $trackinfo(<IITTrack>).<property>
alias -l trackinfo {
  var %com = $$1
  if (!$com(%com)) return
  if ($com(%com, $prop, 2)) return $com(%com).result
}

alias itunes_comerr {
  if (!$comerr) return
  echo $color(info) -ta * iTunes COM Error!
  halt
}
alias np {
  /msg $chan I'm currently playing $$gettok($itunesinfo,2,45) $+  by  $+ $$gettok($itunesinfo,1,45) on iTunes!
}
alias anp {
  /echo -a I'm currently playing $$gettok($itunesinfo,2,45) $+  by  $+ $$gettok($itunesinfo,1,45) on iTunes!
}