Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Display iTunes songs being listened to by others Apps
The other day I thought to myself "Gee, I wish I could see what songs people are listening to in my iTunes shared library...", so I created this AppleScript that does just that! Taking the idea of using lsof +D path/to/music | grep {mp3,m4a,m4p} from another post, this script displays the song title and artist of each track being played locally and over a network in a dialog box. It's been tested with iTunes 4.2 in Panther 10.3.2. Enjoy!

Read the rest of the hint for the script...

--Script created by Elliott Hoffman 2004
-- Thanks to Jonn of http://homepage.mac.com/jonn8/as/ 
-- for debugging help!
-- "dir" must be set to the directory of your iTunes Music Library
set dir to "Path/to/my/iTunes/Library" as string
set shell_script to "readout= lsof +D" & " " & dir & " | ¬
 grep [mp3,m4p,m4a]; echo -n $readout;"
set song_list to paragraphs of (do shell script shell_script)
try
  set message to "Songs people are listening to:" as string
  repeat with song_list_index from 1 to (count of song_list)
    set item song_list_index of song_list to ¬
     (trim_path(item song_list_index of song_list) & ¬
     (return)) as string
    song_list_index = song_list_index + 1
  end repeat
  set message to "Songs being listened to:" & return ¬
   & song_list
  on error
  set message to ¬
   "There are no songs being listened to right now." as string
end try
display dialog ¬
message ¬
  buttons {"OK"} default button 1 with icon 1
  on trim_path(song_string)
    my set_delim("/")
    set song to (text item -1 of song_string)
    set artist to (text item -3 of song_string)
    my set_delim(".")
    set song to (text item -2 of song)
    set song_string to ("•" & song & " by " & artist)
    my set_delim("")
    if song_string's length is greater than 36 then
      set song_string to (get text 1 thru 36 of song_string) & "..."
    end if
    return song_string
  end trim_path
on set_delim(the_delim)
  set AppleScript's text item delimiters to the_delim
end set_delim
If you'd prefer to skip the typing, you can download a formatted version.

P.S.: This can be added to the iTunes scripts menu by saving the script as an Application and putting it in the ~/Library -> iTunes -> Scripts folder (you can create it if you don't have it).
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[8,063 views]  

Display iTunes songs being listened to by others | 7 comments | Create New Account
Click here to return to the 'Display iTunes songs being listened to by others' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Display iTunes songs being listened to by others
Authored by: phlops on Feb 10, '04 11:22:36AM

There is also <a href='http://www.macupdate.com/info.php/id/13791'>iTunes Monitor</a>, an app that will show you who's listening to your music and what they're listening to.

---
/phil



[ Reply to This | # ]
Display iTunes songs being listened to by others
Authored by: mm2270 on Feb 10, '04 11:23:24AM

Nice script!

Cute doggie! ;)



[ Reply to This | # ]
hmmm
Authored by: Lectrick on Feb 10, '04 03:55:38PM

For some reason, only the following version of the command works for me:

lsof +D /Users/you/Music/iTunes/ | grep "m4a\|mp3\|m4p"

(did i accidentally install a new version of grep with fink? hmmm)

---
In /dev/null, no one can hear you scream



[ Reply to This | # ]
Display iTunes songs being listened to by others
Authored by: jules on Feb 10, '04 06:02:54PM

A little python fun...

#!/usr/bin/env python2.3

from os import popen
from string import split

stuff_to_slice = popen("/usr/sbin/lsof +D ~/Music/iTunes/ | /usr/bin/grep -e '.*[mp3|m4(a|p)]$'").readlines()

if stuff_to_slice:
    for item in stuff_to_slice:
        the_list = split(item,'/')
        artist, album, song = the_list[-3], the_list[-2], the_list[-1]
        print "Artist: %s \nAlbum: %s \nSong: %s " % ( artist, album, song )
else:
    print "Nothing playing or wrong path to your music."


[ Reply to This | # ]
Memory consideration
Authored by: henry on Feb 11, '04 08:19:53AM

Taken from the lsof man page, regarding the +D option:

lsof may process this option slowly and require a large amount of dynamic memory to do it. This is because it must descend the entire directory tree, rooted at [the specified directory], calling stat(2) for each file and directory, building a list of all the files it finds, and searching that list for a match with every open file. When [the specified directory] is large, these steps can take a long time, so use this option prudently.

Although the supplied script runs pretty quickly on my music library, I don't have that much music (~10GB). If you have a large music library, this script could use a lot of memory. That said, it's probably not much of a concern, I just thought people should be aware of it.



[ Reply to This | # ]
Display iTunes songs being listened to by others
Authored by: tuckerj on Feb 13, '04 02:00:49AM

Anyone know how to modify this script to show Username and/or IP address of the person accessing your library? That would be sweet, there must be some Unix command(s) that can do this.



[ Reply to This | # ]
Display iTunes songs being listened to by others
Authored by: Kaedwen on Mar 24, '04 01:57:49PM
Since itunes evidently uses port 3689, you should be able to do something like:

netstat -n | grep `ifconfig en0 | grep netmask | awk '{print $2}'`.3689 | awk '{print $5}' | cut -f1-4 -d"."
en0 is the default ethernet port, if you're using an airport card, you'd want to use en1 (or whatever is appropriate for your box). If the ip address appears once, they either are or were looking over your library. If there are 2 connections, they're listening to something.

You can simplify it if you want more info:


netstat -n | grep .3689
This'll show your connections to other shares also.

[ Reply to This | # ]