Advertisement
Haulien

np.scpt

Dec 26th, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -------------------------------------------
  2. -- textual /np script modified to check between spotify and itunes
  3. -- also modified to take in a value (cmd) if the user wants to show/hide the song info (iTunes only)
  4. -- (default is to hide it)
  5. --
  6. -- Modified By: Steven Saric 28th October 2011
  7. -- < http://twitter.com/BoomBoxCreation >
  8. -------------------------------------------
  9.  
  10.  
  11. on textualcmd(cmd)
  12.    
  13.    
  14.     set listening to "/debug You dont have any media players open you doof!"
  15.    
  16.    
  17.    
  18.     if application "Spotify" is running then
  19.        
  20.         tell application "Spotify"
  21.            
  22.             if player state is playing then
  23.                
  24.                 set theurl to spotify url of the current track
  25.                
  26.                 if theurl contains "track" then
  27.                     set realurl to (characters 15 thru 36 of theurl) as string
  28.                 else
  29.                     set realurl to the theurl
  30.                 end if
  31.                
  32.                 set realurl to ("http://open.spotify.com/track/" & realurl)
  33.                 set artistinfo to " by " & artist of the current track
  34.                 set Albuminfo to ", from the album " & album of the current track
  35.                
  36.                
  37.                 if cmd is "bitrate" then
  38.                    
  39.                     set listening to "/me is listening to \"" & name of the current track & "\"" & artistinfo & Albuminfo & " on Spotify. " & realurl & "[" & time of current track & "]"
  40.                    
  41.                 else
  42.                    
  43.                     set listening to "/me is listening to \"" & name of the current track & "\"" & artistinfo & Albuminfo & " on Spotify. " & realurl
  44.                    
  45.                 end if
  46.                
  47.                
  48.                
  49.                
  50.                
  51.             else
  52.                
  53.                 set listening to "/me is not currently playing anything in Spotify"
  54.                
  55.             end if
  56.            
  57.            
  58.            
  59.         end tell
  60.        
  61.        
  62.        
  63.     else if application "iTunes" is running then
  64.        
  65.        
  66.         tell application "iTunes"
  67.             if player state is playing then
  68.                 set listening to "/me is listening to "
  69.                
  70.                 if current stream title is not missing value then
  71.                     set listening to listening & name of current track & " streaming \""
  72.                     set {art, nom} to my text_to_list(current stream title, " - ")
  73.                     set listening to listening & art & " - " & nom & "\""
  74.                 else
  75.                     set the_kind to kind of current track
  76.                     set songsize to ((size of current track) / 1048576)
  77.                     set songsize to (round (songsize * 100)) / 100
  78.                    
  79.                     set movie_list to {"Movies", "TV Shows", "Podcasts", "iTunes U"}
  80.                     set movie_kinds to {"MP4", "Movie", "WAV"}
  81.                    
  82.                     if the_kind contains "MPEG-3 audio file" then set the_kind to "MP3"
  83.                     if the_kind contains "MPEG-4 video file" then set the_kind to "MP4"
  84.                     if the_kind contains "QuickTime movie file" then set the_kind to "Movie"
  85.                     if the_kind contains "AAC" then set the_kind to "AAC"
  86.                     if the_kind contains "WAV" then set the_kind to "WAV"
  87.                     if the_kind contains "Apple Lossless" then set the_kind to "Apple Lossless"
  88.                    
  89.                     if name of current playlist is in movie_list and the_kind is in movie_kinds then
  90.                        
  91.                         set iartist to artist of current track
  92.                        
  93.                        
  94.                         if cmd is "bitrate" then
  95.                            
  96.                            
  97.                             if length of iartist is 0 then
  98.                                 set listening to "/me is watching " & name of current track & " [" & time of current track & " mins] [" & bit rate of current track & " kbps " & the_kind & "] [" & songsize & " MB]"
  99.                             else
  100.                                 set listening to "/me is watching " & artist of current track & " - " & name of current track & " [" & time of current track & " mins] [" & bit rate of current track & " kbps " & the_kind & "] [" & songsize & " MB]"
  101.                             end if
  102.                            
  103.                            
  104.                            
  105.                         else
  106.                            
  107.                             if length of iartist is 0 then
  108.                                 set listening to "/me is watching " & name of current track
  109.                             else
  110.                                 set listening to "/me is watching " & artist of current track & " - " & name of current track
  111.                             end if
  112.                            
  113.                            
  114.                         end if
  115.                        
  116.                     else
  117.                        
  118.                        
  119.                         if cmd is "bitrate" then
  120.                             set listening to "/me is listening to \"" & name of current track & "\" by " & artist of current track & ", from the album " & album of current track & " on iTunes. [" & time of current track & " mins] [" & bit rate of current track & " kbps " & the_kind & "] [" & songsize & " MB] [played " & played count of current track & " times]"
  121.                            
  122.                         else
  123.                             set listening to "/me is listening to \"" & name of current track & "\" by " & artist of current track & ", from the album " & album of current track & " on iTunes."
  124.                            
  125.                         end if
  126.                        
  127.                        
  128.                        
  129.                        
  130.                     end if
  131.                 end if
  132.             else
  133.                 set listening to "/me is not currently playing anything in iTunes"
  134.             end if
  135.         end tell
  136.        
  137.        
  138.     else
  139.        
  140.         set howToUse to "/debug  Usage: \"/np\"     ,     \"np bitrate\"
  141. /debug If you do \"/np bitrate\" it will show the music info (iTunes only) (play count, song size, bitrate and length)"
  142.        
  143.         set listening to "/me does not currently have iTunes or Spotify open" & "
  144. " & listening & "
  145. " & howToUse
  146.        
  147.     end if
  148.    
  149.     return listening
  150.    
  151. end textualcmd
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162. -- text_to_list AppleScript function from:
  163. -- <http://dougscripts.com/itunes/itinfo/locatemf.php>
  164. on text_to_list(txt, delim)
  165.     set saveD to AppleScript's text item delimiters
  166.     try
  167.         set AppleScript's text item delimiters to {delim}
  168.         set theList to every text item of txt
  169.     on error errStr number errNum
  170.         set AppleScript's text item delimiters to saveD
  171.         error errStr number errNum
  172.     end try
  173.     set AppleScript's text item delimiters to saveD
  174.     return (theList)
  175. end text_to_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement