Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on zero_pad(value, string_length)
  2.     set string_zeroes to ""
  3.     set digits_to_pad to string_length - (length of (value as string))
  4.     if digits_to_pad > 0 then
  5.         repeat digits_to_pad times
  6.             set string_zeroes to string_zeroes & "0" as string
  7.         end repeat
  8.     end if
  9.     set padded_value to string_zeroes & value as string
  10.     return padded_value
  11. end zero_pad
  12.  
  13. on music_char(seed)
  14.     if seed = 0 then set np_prefix to "♩"
  15.     if seed = 1 then set np_prefix to "♪"
  16.     if seed = 2 then set np_prefix to "♫"
  17.     if seed = 3 then set np_prefix to "♬"
  18.     return np_prefix
  19. end music_char
  20.  
  21. on buildNowPlaying()
  22.     tell application "iTunes"
  23.         set TrackAlbum to album of current track
  24.         set TrackArtist to artist of current track
  25.         set TrackName to name of current track
  26.         set TrackNumber to track number of current track
  27.         set TrackLength to time of current track
  28.         set TrackBitrate to bit rate of current track
  29.         -- Fix the time (current pos)
  30.         set T to player position
  31.         set H to T div 3600
  32.         set S to T mod 3600
  33.         set M to S div 60
  34.         set S to S mod 60
  35.         if M < 10 then set M to "0" & M
  36.         if S < 10 then set S to "0" & S
  37.         -- set CurrentTime to (H as text) & ":" & M & ":" & S
  38.         set CurrentTime to M & ":" & S
  39.         -- Fix the time (duration)
  40.         if (character 2 of TrackLength is ":") then set TrackLength to "0" & TrackLength
  41.     end tell
  42.     return music_char(random number from 0 to 3) & ": " & TrackArtist & " [" & TrackAlbum & "] " & zero_pad(TrackNumber, 2) & ": " & TrackName & " [" & CurrentTime & "/" & TrackLength & "] [" & TrackBitrate & " kbps]"
  43. end buildNowPlaying
  44.  
  45. using terms from application "Colloquy"
  46.     on process user command cmd with args for chatRoom
  47.         if cmd is equal to "np" then
  48.             set nowPlaying to buildNowPlaying() & " " & args
  49.             tell chatRoom to send message nowPlaying to chatRoom with action tense
  50.             return nothing
  51.         end if
  52.     end process user command
  53. end using terms from
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement