Advertisement
Haulien

np.scpt

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