Advertisement
wollux

SwiftIRC iTunes Now Playing by Kvn

Aug 14th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 8.38 KB | None | 0 0
  1. ;;----------------------------------------------------------;;
  2. ;; iTunes script by Kvn Pfc :: http://rseos.com/EchoScript/ ;;
  3. ;;              Revised Version August 2011                 ;;
  4. ;;----------------------------------------------------------;;
  5.  
  6. ;;----------------------------------------------------------;;
  7. ;;                         Options                          ;;
  8. ;;            Edit these lines to your preference           ;;
  9. ;;----------------------------------------------------------;;
  10.  
  11. ;; checkForItunes - Should return $true if you want to use the
  12. ;; -- chkprog alias to see if iTunes is running before each
  13. ;; -- command. Slows the program down slightly, but the script
  14. ;; -- will not run iTunes if it is not open. If $false, the
  15. ;; -- script will run slightly faster and it will assume the
  16. ;; -- user knows whether or not iTunes is open, and due to
  17. ;; -- the COM interface, will run iTunes if it is not open.
  18. alias -l checkForITunes { return $false }
  19.  
  20. ;; useTimer - Should return $true if you want the iTunes script
  21. ;; -- to run periodically, i.e. every 480 seconds. If $false,
  22. ;; -- no timers will be run.
  23. alias -l useTimer { return $true }
  24.  
  25.  
  26. ;; doNotMessageChans -- This should be a space delimited list of
  27. ;; -- channels you do not want the script to message. By default
  28. ;; -- the script will message your active channel, so if one of
  29. ;; -- these channels is your active channel, it will do nothing
  30. ;; -- Syntax: #chan1 #chan2 #chan3 #chanN
  31. alias -l doNotMessageChans { return #staff #help }
  32.  
  33. ;; period -- Edit the number to the number of seconds you want
  34. ;; -- as a delay between automatic messages.
  35. alias -l period { return 180 }
  36.  
  37. ;; Colors - Change the double digit numeric to modify the colors
  38. ;; -- used in the iTunes script. Play around with it until you
  39. ;; -- find what you like.
  40. alias -l c1 { return $+($chr(3),07) }
  41. alias -l c2 { return $+($chr(3),14) }
  42. alias -l c3 { return $+($chr(3),04) }
  43. alias -l c4 { return $+($chr(3),12) }
  44.  
  45. ;; Text separators - These are totally up to you, I recommend
  46. ;; -- keeping these fairly simple. Modification is not actually
  47. ;; -- necessary.
  48. alias -l l { return $+($chr(2),$c3,»,$chr(3),$chr(2)) }
  49. alias -l ll { return $+($c2,$1-,$c3,:,$c1) }
  50. alias -l it { return $+($c2,[,$c4,iTunes,$c2,],$chr(2),$c3 —›,$chr(2)) }
  51. alias -l lll { return $+($c2,[,$c1,$1-,$c2,]) }
  52. ;; End Options ---------------------------------------------;;
  53.  
  54.  
  55. ;; Begin Script --------------------------------------------;;
  56. alias itunes {
  57.   _iTunes
  58.   if ($useTimer) { .timeriTunes 0 $period noop $!_itunes }
  59. }
  60. alias itunesoff {
  61.   .timeriTune* off
  62.   echo -at $c1 $+ ** $it $c2 $+ iTunes timer stopped.
  63. }
  64. alias _itunes {
  65.   if (!$chkprg(iTunes.exe)) {
  66.     if (!$isid) {
  67.       var %x = $?!="Would you like to run iTunes?"
  68.       if (%x) { run iTunes.exe | echo -at $c1 $+ ** $it $+($c2,Now running,$chr(32),$c1,iTunes.exe,$c2,. Type /itunes again when iTunes finishes opening and you have started playing music.) }
  69.       else { echo -at $c1 $+ ** $it $+ $c2 No action taken.  }
  70.     }
  71.     .timeriTune* off
  72.     return
  73.   }
  74.   scid $activecid
  75.   var %p = iTunes, %i = IITTrack, %b = $chr(2), %% = $+(%b,$c3,»,$chr(3),%b)
  76.   .comopen iTunes iTunes.Application
  77.   if ($comerr) { .timeriTunes off | goto error }
  78.   if $com(%p,CurrentTrack,3,dispatch* %i) {
  79.     if (!$com(%i)) { echo -at $c1 $+ ** $it $+ $c2 No track is currently playing. | goto error }
  80.     var %k = $com(%i,Name,2)
  81.     var %name = $com(%i).result
  82.     var %k = $com(%i,Album,2), %album = $com(%i).result, $&
  83.       %k = $com(%i,Artist,2), %artist = $com(%i).result, $&
  84.       %k = $com(%i,BitRate,2), %bitrate $com(%i).result, $&
  85.       %k = $com(%i,Time,2), %time = $regsubex($com(%i).result,/(\d+):(\d+)/,$+(\1,$c2,:,$c1,\2)), $&
  86.       %k = $com(%i,Rating,2), %n = $com(%i).result, $&
  87.       %rating = $+($str(¤,$calc(%n /20)),%b,$str(-,$calc(5 - (%n /20))),%b), $&
  88.       %k = $com(%i,Year,2), %year = $com(%i).result
  89.     var %k = $com(%i,Duration,2), %k = $com(%p,PlayerPosition,2), $&
  90.       %position = $regsubex($asctime($com(%p).result,n:ss),/(\d+):(\d+)/,$+(\1,$c2,:,$c1,\2)), $&
  91.       %pr = $calc($com(%p).result / $com(%i).result), $&
  92.       %progress = $+(%b,$chr(3),4,$str(¦,$floor($calc(%pr *10))),$chr(3),1¦,$chr(3),3,$str(¦,$calc(10- $round($calc(%pr *10),0))),%b,$c2), $&
  93.       %k = $com(%p,PlayerState,2), %st = $com(%p).result, $&
  94.       %k = $com(%i,Genre,2), %genre = $com(%i).result, $&
  95.       %k = $com(%i,PlayedCount,2), %played = $com(%i).result
  96.     var %msg = $it $ll(Track) %name $iif(!%st,$lll(Paused)) $&
  97.       $iif(%artist,%% $ll(Artist) %artist $iif(%year,$lll(%year))) $&
  98.       $iif(%album,%% $ll(Album) %album) $&
  99.       %% $ll(Position) $+(%position,$c2,/,$c1,%time) $&
  100.       $lll($calc($round(%pr,2) *100) $+ %) $+([,%progress,]) $&
  101.       %% $ll(Rating) %rating $&
  102.       %% $ll(Bitrate) $+(%bitrate,$c2,kbps) $&
  103.       $iif(%genre,%% $ll(Genre) %genre) $&
  104.       %% $ll(PlayedCount) %played $+ $chr(15)
  105.     $iif($active ischan && !$istok($doNotMessageChans,$active,32),msg $active,noop) $iif(c !isincs $chan($active).mode,%msg,$strip(%msg,c)))
  106.   }
  107.   :error
  108.   while ($com(0)) { .comclose $com(1) }
  109. }
  110.  
  111. alias pause {
  112.   if (!$chkprg(iTunes.exe)) { return }
  113.   .comopen iTunes iTunes.Application
  114.   noop $com(iTunes,Pause,3)
  115.   echo -at $c1 $+ ** $it $c2 $+ Music Paused.
  116.   .comclose iTunes
  117. }
  118.  
  119. alias resume {
  120.   if (!$chkprg(iTunes.exe)) { return }
  121.   .comopen iTunes iTunes.Application
  122.   noop $com(iTunes,Play,3)
  123.   echo -at $c1 $+ ** $it $c2 $+ Music Resumed.
  124.   .comclose iTunes
  125. }
  126.  
  127. alias setrating {
  128.   if (!$1) {
  129.     echo -at $c1 $+ ** $it $c2 $+ Please specify a rating to give this song, between 0 and 5 inclusive.
  130.     return
  131.   }
  132.   var %p = iTunes, %i = IITTrack
  133.   .comopen iTunes iTunes.Application
  134.   if ($comerr) { .timeriTunes off | goto error }
  135.   if $com(%p,CurrentTrack,3,dispatch* %i) {
  136.     if (!$com(%i)) {
  137.       echo -at $c1 $+ ** $it $c2 $+ No track is currently selected.
  138.       .timeriTunes off
  139.       goto error
  140.     }
  141.     var %k = $com(%i,Rating,4,long,$calc($1 *20)), $&
  142.       %k = $com(%i,Name,2), %n = $com(%i).result
  143.     echo -at $c1 $+ ** $it $+($c2,Rating for:,$c1,$chr(32),%n,$chr(32),$c2,changed to,$c1,$chr(32),$1,$c2,.)
  144.   }
  145.   :error
  146.   while ($com(0)) { .comclose $com(1) }
  147. }
  148.  
  149. alias next {
  150.   if (!$chkprg(iTunes.exe)) { return }
  151.   var %p = iTunes, %i = IITTrack
  152.   .comopen iTunes iTunes.Application
  153.   if ($comerr) { .timeriTunes off | goto error }
  154.   if $com(%p,CurrentTrack,3,dispatch* %i) {
  155.     var %k = $com(%p,NextTrack,3)
  156.     .timer 1 .5 _next
  157.   }
  158.   :error
  159.   while ($com(0)) { .comclose $com(1) }
  160. }
  161.  
  162. alias back {
  163.   if (!$chkprg(iTunes.exe)) { return }
  164.   var %p = iTunes, %i = IITTrack
  165.   .comopen iTunes iTunes.Application
  166.   if ($comerr) { .timeriTunes off | goto error }
  167.   if $com(%p,CurrentTrack,3,dispatch* %i) {
  168.     var %k = $com(%p,PreviousTrack,3)
  169.     .timer 1 .5 _back
  170.   }
  171.   :error
  172.   while ($com(0)) { .comclose $com(1) }
  173. }
  174.  
  175. alias -l _back {
  176.   var %p = iTunes, %i = IITTrack
  177.   .comopen iTunes iTunes.Application
  178.   if ($comerr) { .timeriTunes off | goto error }
  179.   if $com(%p,CurrentTrack,3,dispatch* %i) {
  180.     var %k = $com(%i,Name,2)
  181.     echo -at $c1 $+ ** $it $+($c2,Advanced to previous track:,$c1) $com(%i).result
  182.   }
  183.   :error
  184.   while ($com(0)) { .comclose $com(1) }
  185. }
  186.  
  187. alias -l _next {
  188.   var %p = iTunes, %i = IITTrack
  189.   .comopen iTunes iTunes.Application
  190.   if ($comerr) { .timeriTunes off | goto error }
  191.   if $com(%p,CurrentTrack,3,dispatch* %i) {
  192.     var %k = $com(%i,Name,2)
  193.     echo -at $c1 $+ ** $it $+($c2,Advanced to next track:,$c1) $com(%i).result
  194.   }
  195.   :error
  196.   while ($com(0)) { .comclose $com(1) }
  197. }
  198.  
  199. alias chkprg {
  200.   if (!$checkForITunes) { return $true }
  201.   if ($file(pro.vbs) != 294) {
  202.     .fopen -o processes processes.txt
  203.     .fclose processes
  204.     var %% = aline @@, %x = processes.txt
  205.     window -h @@
  206.     %% Dim z, x, t
  207.     %% Set z = CreateObject("Scripting.FileSystemObject")
  208.     %% Set x = z.OpenTextFile(" $+ $mircdir $+ %x $+ ", 2, 1)
  209.     %% t = "."
  210.     %% For Each obj In GetObject("winmgmts://" & t & "/root/cimv2").ExecQuery("SELECT * FROM Win32_Process")
  211.     %% x.Write(obj.Description & vbCrLf)
  212.     %% Next
  213.     savebuf @@ pro.vbs
  214.     window -c @@
  215.   }
  216.   .comopen q wscript.shell  
  217.   .comclose q $com(q,run,3,bstr,wscript " $+ $mircdir $+ pro.vbs",uint,5,bool,true)
  218.   return $read(processes.txt,r,$1)
  219. }
  220. ;; End Script ----------------------------------------------;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement