aIRC — File Browser

aIRCv0.8.69 / aIRCv0.8.69 / addons / sound1.mrc

sound1.mrc — 15.98 KB — Download this file

;/**********************************************************************
; *
; * aIRC
; * Sound System (/mp3+mainstuff+supportaliases)
; *
; **********************************************************************/
;
;

alias _sound.addonver { return 1.0 }
alias _sound.unload {
  if ($dialog(_aircamp)) || ($dialog(_soundsetup)) || ($dialog(_soundindex)) || ($dialog(_aIRCpster)) {
    error.a Please close all MP3 dialogs before you unload the Sound System
    return
  }
  .timer -mo 1 1 if ($ $+ script($script)) error.a Sound System uninstallation failed $chr(124) else info.a Sound System Uninstalled!
  .unload -rs $script
}
alias _sound.inifile { return $_chfile($_usrdir(sound.ini)) }
alias _sound.tinifile { return $_chfile($_usrdir(soundt.ini)) }
alias soundsetup {
  _dialog -m _soundsetup _soundsetup
  var %i = 1001
  while (%i <= 1006) {
    if ($1- == $did(_soundsetup,%i).text) {
      did -c _soundsetup %i
      break
    }
    inc %i
  }
}
; /mp3 [stop|-lrvoq|-setup] [file[.mp3]|mask]
alias mp3 {
  var %stop,%switches,%parm,%m,%t,%r,%file,%s,%d,%l = 0
  if (-* iswm $1) { var %switches = $1,%parm = $2- }
  else { var %parm = $1- }

  if ($1 == -setup) { soundsetup $2- }
  elseif ($1- == stop) { _mp3.stop 1 }
  elseif ($_list.total(mp3dirs) == 0) {
    error.a You must set up a MP3 directory
    .timer -o 1 0 mp3 -setup
  }
  elseif ($1- == $null) { aircamp }
  elseif (v isin %switches) || (r isin %switches) {
    if (v isin %switches) { _dummy $_playlist.open($2-,%switches) }
    if (r isin %switches) {
      %m = $_mp3.parm2wc(%parm)
      if ($_mp3.files.total(%m,-rn)) { %file = $_mp3.files.get(%m,$rand(1,$ifmatch)) }
      if (%file != $null) { _mp3.play -s %file }
      else { error.a No matches found: %m }
    }
  }
  elseif (l isin %switches) || (o isincs %switches) || (q isincs %switches) { %l = 1 }
  elseif (%switches != $null) { error.a Usage: /mp3 [stop|-lrvoq|-setup] [file[.mp3]|mask] }
  else { %l = 1 }

  if (%l) {
    var %m = $_mp3.parm2wc(%parm),%i = $_list.total(mp3dirs),%s = 0,%win = @__mp3tmp
    close -@ %win
    window -hl %win
    %s = $_mp3.wc2win(%m,%win)
    %file = $line(%win,1)
    close -@ %win
    if (%s >= 1) { _dummy $_playlist.open(%m,%switches) }
    elseif (%s == 1) { _mp3.play -s %file }
    else { error.a No matches found: %m }
  }
}
alias _mp3.wc2win {
  var %m = $1,%win = $2,%i = $_list.total(mp3dirs),%s = 0,%d
  %i = $_list.total(mp3dirs)
  while (%i) {
    _dummy $findfile($_list.get(mp3dirs,%i),%m,0,%win)
    dec %i
  }
  %s = $line(%win,0)
  return %s
}
alias _mp3.parm2wc {
  var %parm = $1,%m,%t,%e
  if (%parm == $null) { %m = *.mp3 }
  elseif (? isin %parm) || (* isin %parm) { %m = * $+ $replace(%parm,$chr(32),*) $+ * }
  else { %m = * $+ %parm $+ * }
  if (*.* iswm %m) {
    %t = $deltok(%m,-1,46)
    %e = $gettok(%m,-1,46)
    if (mp3* iswm %e) || (mp2* iswm %e) || (mp1* iswm %e) { %e = $left(%e,3) }
    elseif (mp* iswm %e) { %e = mp? }
    else { var %t = %t $+ . $+ %e,%e = mp? }
    %m = %t $+ . $+ %e
  }
  while (** isin %m) { %m = $replace(%m,**,*) }
  if (mp? !iswm $gettok(%m,-1,46)) { %m = $gettok(%m,1,46) $+ .mp? }
  return $replace(%m,$chr(32),*)
}
;;
;
; $_mp3.files.total(*filemask*)
;
alias _mp3.files.total {
  if ($1 == $null) { return }
  var %r = 0,%mpfiles = $_getsetup(mp3,totalmp3files),%t = $gettok(%mpfiles,2,32)
  if ($_isint($gettok(%mpfiles,1,32))) { %r = $ifmatch }
  if (r isin $2) || (%t > $ctime) || ($calc($ctime - %t) > 3600) {
    var %i = $_list.total(mp3dirs),%r = 0
    while (%i) {
      if ($findfile($_list.get(mp3dirs,%i),$1,0)) { inc %r $ifmatch }
      dec %i
    }
    if (n !isin $2) { _setsetup mp3 totalmp3files %r $ctime }
  }
  return %r
}
;;
;
; $_mp3.files.get(*filemask*,N)
;
alias _mp3.files.get {
  if ($1 == $null) || ($_not($_isint($2))) { return }
  var %m = $1,%n = $2,%l = 0,%i = $_list.total(mp3dirs),%d,%f,%r = 0
  while (%i) {
    %d = $_list.get(mp3dirs,%i)
    %f = $findfile(%d,%m,0)
    if (%f) { inc %r %f }
    if (%r >= %n) { return $findfile(%d,%m,$calc(%n - %l)) }
    inc %l %f
    dec %i
  }
}
; $_playlist.open(*wildcard*,flags)
alias _playlist.open {
  var %m = $_mp3.parm2wc($1),%i,%win = @__oldPlaylist,%flags = $2
  if (-* !iswm %flags) { %flags = -w }
  elseif (o isincs %flags) || (q isincs %flags) { %flags = -w $+ $ifmatch }
  _openwins %win
  _dummy $_mp3.wc2win(%m,%win)
  _playlist.error
  aircamp %flags %win %m
  close -@ %win
}
alias _mp3.format.remote {
  if ($_getsetup(mp3,sendfileson!nickfile)) { return $_getsetup(mp3,format.remote.o) }
  return $_getsetup(mp3,format.remote.n)
}
alias _mp3.format.local { return $_getsetup(mp3,format.local) }
alias _mp3.replaceformat {
  var %tmp = $replace($1,<KBPS>,<BITRATE>,<HZ>,<SAMPLE>,<STEREO>,<MODE>,<SIZE>,<FILESIZE>)
  return $_evaltext($replace(%tmp,<ALBUM>,$hget($2,album),<TITLE>,$hget($2,title),<ARTIST>,$hget($2,artist),<YEAR>,$hget($2,year),<COMMENT>,$hget($2,comment),<GENRE>,$hget($2,genre),<TRACK>,$hget($2,track),<LENGTH>,$hget($2,length),<VERSION>,$hget($2,version),<BITRATE>,$hget($2,bitrate),<VARIABLE>,$hget($2,variable),<SAMPLE>,$hget($2,sample),<MODE>,$hget($2,mode),<COPYRIGHT>,$hget($2,copyright),<PRIVATE>,$hget($2,private),<CRC>,$hget($2,crc),<KHZ>,$hget($2,khz),<FILESIZE>,$hget($2,filesize),<FILE>,$hget($2,file),<PATHFILE>,$hget($2,pathfile),<DURATION>,$hget($2,duration),<TRIGGER>,$hget($2,trigger)))
}
alias _mp3.ad_on_play {
  var %file = $1-,%mychans = $_mychans,%myqueries = $_myqueries,%mychats = $_chats,%adchans = $_getsetup(mp3,playto.chans),%adqueries = $_getsetup(mp3,playto.queries),%adchats = $_getsetup(mp3,playto.chats),%fchans,%fqueries,%fchats,%ad,%irc,%ctcp

  if ($_getsetup(mp3,playto.status)) {
    if ($_mp3.replaceformat($_mp3.format.local,_aircamphtmp) != $null) { info.s $ifmatch }
  }

  %ad = $_mp3.replaceformat($_mp3.format.remote,_aircamphtmp)
  %ctcp = $_not($_getsetup(mp3,dontsendctcp))
  if (%ad == $null) { return }
  if (%adchans == *) { %fchans = %mychans }
  elseif (%adchans == $null) { var %fchans }
  else { %fchans = $__~mp3.ad_on_play(%adchans,%mychans) }
  if (%adqueries == *) { %fqueries = %myqueries }
  elseif (%adqueries == $null) { var %fqueries }
  else { %fqueries = $__~mp3.ad_on_play(%adqueries,%myqueries) }

  %irc = %fchans %fqueries
  %irc = $replace(%irc,$chr(32),$chr(44))

  if (%adchats != $null) {
    var %i = 1,%n = $chat(0),%c,%=c,%r
    while (%i <= %n) {
      var %c = $chat(%i),%=c = = $+ %c
      if ($chat(%c).status == active) {
        if (%adchats == *) || ($istok(%adchats,%c,32)) || ($istok(%adchats,%=c,32)) {
          msg %=c %ad
          if (%ctcp) { .msg %=c SOUND $nopath(%file) $+  }
        }
      }
      inc %i
    }
  }
  if ($_connected) && (%irc != $null) {
    _massmsgnotice - msg %irc %ad
    if (%ctcp) { _massmsgnotice - .ctcp %irc MP3 $nopath(%file) }
  }
}
alias -l __~mp3.ad_on_play {
  var %i = 1,%adchats = $replace($1,$chr(44),$chr(32)),%n = $numtok($2,32),%c,%r
  while (%i <= %n) {
    %c = $gettok($2,%i,32)
    if ($istok(%adchats,%c,32)) { %r = %r %c }
    inc %i
  }
  return %r
}
alias _mp3.exists {
  var %i = 1,%n = $_list.total(mp3dirs),%file,%rep = $replace($1-,$chr(32),_),%re? = $replace(%rep,_,?)
  while (%i <= %n) {
    %file = $findfile($_list.get(mp3dirs,%i),%re?,1)
    if ($replace($nopath(%file),$chr(32),_) == %rep) && ($isfile(%file)) { return %file }
    inc %i
  }
}
CTCP *:SOUND:*:{ _sound.triggeredctcp $1- }
CTCP *:MP3:*:{ _sound.triggeredctcp $1- }
CTCP *:MP2:*:{ _sound.triggeredctcp $1- }
ON &*:CHAT:*:{
  if (* !iswm $1-) || ($count($1-,) != 2) { return }
  tokenize 32 $remove($1-,)
  var %file = $_sound.parse($2-).file,%action = $_sound.parse($2-).action,%type = $_sound.parse($2-).type
  if (%file == $null) { return }
  if ($1 == SOUND) || ($1 == %type) { _dummy $_sound.request.chat($1,%type,%file,%action) }
}
alias -l _sound.triggeredctcp {
  var %file = $_sound.parse($2-).file,%action = $_sound.parse($2-).action,%type = $_sound.parse($2-).type
  if (%file != $null) && (($1 == SOUND) || ($1 == %type)) {
    if ($target ischan) { _aircpster.addreq ChanOffer $nick %file }
    if ($halted == $false) {
      if (%file == $null) { return }
      _dummy $_sound.request.ctcp($1,%type,%file,%action)
    }
  }
}
alias _sound.request.chat {
  if ($_flood.main(1,0,2,0,30,$_nospaces(__sound.,$nick),0)) { return }
  var %ctcp = $1,%type = $2,%file = $3,%action = $4
  echo $colour(action) -it = $+ $nick [ $+ $nick SOUND] %action
  _sound.request.touchmebaby %type %file
  halt
}
alias _sound.request.ctcp {
  if ($_flood.main(1,0,2,0,30,$_nospaces(__sound.,%++maskclon),0)) { return }
  var %ctcp = $1,%type = $2,%file = $3,%action = $4
  if (%action != $null) {
    if ($chan($chan)) { echo $colour(action) -it $chan * $nick %action }
    elseif ($query($nick) != $null) { echo $colour(action) -it $nick * $nick %action }
    else { lechol.a $colour(highlight) * $+ $nick $+ * %action }
  }
  _sound.request.touchmebaby %type %file
  %+ctcp.show = 0
  %+ctcp.reply = 0
  halt
}
alias _sound.request.touchmebaby {
  if ($_flood.main(1,0,3,0,60,__sound.botnet,0)) { return }
  if ($_not($_getsetup(mp3,remotesreqs.status))) { return }
  var %type = $1,%file = $2-,%found = 0,%echo,%lfile,%nignore = $_not($_getsetup(mp3,remotesreqs.ignoreifplaying))
  if ($istok(wav mid,%type,32) == $false) && (mp? !iswm %type) { return }
  if ($nopath($_fixfilename(%file)) == $null) { %found = 0 }
  elseif (%type == wav) {
    %lfile = $wavedir $+ %file
    if ($isfile(%lfile)) {
      if (%nignore) || ($_not($inwave)) { .splay -w " $+ %lfile $+ " }
      %found = 1
    }
  }
  elseif (%type == mid) {
    %lfile = $mididir $+ %file
    if ($isfile(%lfile)) {
      if (%nignore) || ($_not($inmidi)) { .splay -m " $+ %lfile $+ " }
      %found = 1
    }
  }
  elseif ($_mp3.exists(%file)) {
    if (%nignore) || ($_not($_mp3.inmp3)) { _mp3.play -st $ifmatch }
    %found = 1
  }

  if ($_not(%found)) && ($_getsetup(mp3,remotesreqs.warnifnofile)) {
    if ($event == chat) { %echo = echo.w $colour(info) = $+ $nick }
    elseif ($chan($chan)) { %echo = echo.w $colour(info) $chan }
    elseif ($query($nick) != $null) { %echo = echo.w $colour(info) $nick }
    else { %echo = lechol.a $colour(info) }
    %echo * Sound request from $nick $_bracket($address) $+ : can't find ' $+ %file $+ '
  }
}
alias _sound.parse {
  tokenize 32 $1-
  var %file,%action,%text,%tp
  if ("* iswm $1-) { var %file = $gettok($1-,1,34),%action = $gettok($1-,2-,34) }
  elseif (*.mp3 iswm $1-) || (*.mp2 iswm $1-) || (*.wav iswm $1-) || (*.mid iswm $1-) { var %text = $right($ifmatch,4),%file = $1-,%action }
  elseif (*.mp3 * iswm $1-) || (*.mp2 * iswm $1-) || (*.wav * iswm $1-) || (*.mid * iswm $1-) { var %text = $mid($ifmatch,2,4),%tp = 3 + $pos($replace($1-,$chr(32), ),$_nospaces(%text, ),1),%file = $left($1-,%tp),%action = $right($1-,$calc(%tp * -1)) }
  elseif (*.mp3 * iswm $1-) || (*.mp2 * iswm $1-) || (*.wav * iswm $1-) || (*.mid * iswm $1-) { var %text = $mid($ifmatch,2,4),%tp = 3 + $pos($1-,$_nospaces(%text, ),1),%file = $left($1-,%tp),%action = $right($1-,$calc(%tp * -1)) }
  elseif (*.mp3	* iswm $1-) || (*.mp2	* iswm $1-) || (*.wav	* iswm $1-) || (*.mid	* iswm $1-) { var %text = $mid($ifmatch,2,4),%tp = 3 + $pos($1-,$_nospaces(%text,	),1),%file = $left($1-,%tp),%action = $right($1-,$calc(%tp * -1)) }
  else { return }
  %file = $nopath($remove(%file,"))
  if (*.mp3 !iswm %file) && (*.mp2 !iswm %file) && (*.wav !iswm %file) && (*.mid !iswm %file) { return }
  if ($prop == action) { return %action }
  if ($prop == type) { return $gettok(%file,-1,46) }
  return %file
}

alias _playlist.error {
  var %win1 = @__oldPlaylist,%win2 = @PLAYLIST ERROR,%i = 1,%m = 1
  close -@ %win2
  window -ahkl %win2
  clear %win2
  filter -ww %win1 %win2
  while (%i <= $line(%win2,0)) {
    if ($chr(32) $+ $chr(32) isin $line(%win2,%i)) {
      sline -a %win2 %i
      inc %i
      dline %win1 %m
    }
    else { dline %win2 %i }
    inc %m
  }
  if ($line(%win2,0) == 0) { close -@ %win2 }
  else {
    iline %win2 1 -
    iline %win2 2 These files have double spaces in the their filename
    iline %win2 3 mIRC can't handle them!
    iline %win2 4 Please rename these files:
    iline %win2 5 -
    sline -a %win2 6
    window -aw %win2
    window -k %win2
  }
}
menu nicklist {
  $iif(($_connected) && ($snick(#,0) > 0),&mp3)
  .&stats:{ say @ $+ $1 $+ -stats }
  .&list:{ say @ $+ $1 }
  .&queue:{ say @ $+ $1 $+ -que }
  .&help { say @ $+ $1 $+ -help }
}
menu query,channel {
  $iif(($_connected) || ((=* iswm $active) && ($chat($right($active,-1)) == $right($active,-1))),&mp3)
  .@&find:{ say @find $_parameter($null,1,@find,normal,$null,@find:) }
  .@&locator:{ say @locator $_parameter($null,1,@locator,normal,$null,@locator:) }
}
menu menubar {
  &sound
  .&aircamp:{ aircamp }
  .airc&pster:{ aircpster }
  .play &random:{ mp3 -lr }
  .s&top:{ mp3 stop }
  .-
  .&setup:{ mp3 -setup }
  .&index:{ sindex }
}

; $_mp3info(file,tags,hashtable)
alias _mp3info {
  var %album,%title,%artist,%year,%comment,%genre,%track,%length,%version,%bitrate,%variable,%sample,%mode,%copyright,%private,%crc
  var %file = $1,%style = $2,%hashtable = $3,%msg.pre,%duration,%khz,%filesize,%ah = _hadd %hashtable,%tags

  if ($isfile(%file) == $false) { return }

  %tags = $replace(%style,<KBPS>,<BITRATE>,<HZ>,<SAMPLE>,<STEREO>,<MODE>,<SIZE>,<FILESIZE>)

  if (<album> isin %tags) { %album = $mp3(%file).album }
  if (<title> isin %tags) { %title = $mp3(%file).title }
  if (<artist> isin %tags) { %artist = $mp3(%file).artist }
  if (<year> isin %tags) { %year = $mp3(%file).year }
  if (<comment> isin %tags) { %comment = $mp3(%file).comment }
  if (<genre> isin %tags) { %genre = $mp3(%file).genre }
  if (<track> isin %tags) { %track = $mp3(%file).track }
  if (<length> isin %tags) || (<duration> isin %tags) { var %length = $mp3(%file).length,%duration = $round($calc(%length / 1000),0) }
  if (<version> isin %tags) { %version = $mp3(%file).version }
  if (<bitrate> isin %tags) || (<kbps> isin %tags) { %bitrate = $mp3(%file).bitrate }
  if (<variable> isin %tags) { %variable = $mp3(%file).variable }
  if (<sample> isin %tags) || (<khz> isin %tags) { var %sample = $mp3(%file).sample,%khz = $_round($calc(%sample / 1000),1) }
  if (<mode> isin %tags) { %mode = $mp3(%file).mode }
  if (<copyright> isin %tags) { %copyright = $mp3(%file).copyright }
  if (<private> isin %tags) { %private = $mp3(%file).private }
  if (<crc> isin %tags) { %crc = $mp3(%file).crc }
  if (<filesize> isin %tags) { %filesize = $file(%file).size }

  if (%album == $null) { %album = Unknown Album }
  if (%title == $null) { %title = $gettok($nopath(%file),1- [ $calc($numtok($nopath(%file),46) - 1) ] ,46) }
  var %ztmp = (*)*,%ytmp = [*]*
  if (%artist == $null) {
    if (%ztmp iswm %title) { var %artist = $remove($gettok(%title,1,41),$chr(40)),%title = $gettok(%title,2-,41) }
    elseif (%ztmp iswm %title) { var %artist = $remove($gettok(%title,1,93),$chr(91)),%title = $gettok(%title,2-,93) }
    elseif (*-* iswm %title) { var %artist = $gettok(%title,1,$asc(-)),%title = $gettok(%title,2-,$asc(-)) }
  }
  var %ztmp = (*),%ytmp = [*]
  if (%ztmp iswm %artist) || (%ytmp iswm %artist) { %artist = $left($right(%artist,-1),-1) }
  if (%artist == $null) { %artist = Unknown Artist }

  if (%hashtable != $null) {
    _hmake %hashtable 10
    %ah ALBUM %album
    %ah TITLE %title
    %ah ARTIST %artist
    %ah YEAR %year
    %ah COMMENT %comment
    %ah GENRE %genre
    %ah TRACK %track
    %ah LENGTH %length
    %ah VERSION %version
    %ah BITRATE %bitrate
    %ah VARIABLE %variable
    %ah SAMPLE %sample
    %ah MODE %mode
    %ah COPYRIGHT %copyright
    %ah PRIVATE %private
    %ah CRC %crc

    %ah DURATION %duration
    %ah KHZ %khz
    %ah FILESIZE %filesize
    %ah FILE $nopath(%file)
    %ah PATHFILE %file
    %ah TRIGGER ! $+ $me $nopath(%file)
  }
}
alias _windowsize.Playlist { return X Y 441 141 }
alias _windowopts.Playlist { return 0 1 1 }