Tunnelling Media Over SSH
Fri Jun 08, 2007 · 360 words

If this site had a “just too cool” section, this next bit would be the first one there. You're at the office and want to play some tunes from your home Mac. Do you set up a file server to access them? Or maybe some streaming system? Try to hack iTunes to share beyond the LAN?

Or just use SSH (which you're probably serving anyway). The trick is to cat the remote file over the SSH tunnel to a local media player that can read from stdin, like mpg123:

$ ssh remote.machine.com cat sometune.mp3 | mpg123 -

Or how about listening to every single MP3 on your system from anywhere in the world?

$ ssh remote.machine.com "find Music/ -name *.mp3 -exec cat {} ;" | mpg123 -

But you usually want something a little more specific, like a certain artist and here's where the Tiger goodness really shines:

$ ssh remote.machine.com mdfind "kMDItemAuthors == '*Isis*'" -0 | xargs -0 cat | mpg123 -

A good way to find out all the available search criteria is to use mdls:

> mdls /Users/filipp/Music/iTunes/iTunes Music/Ochre/Lemodie/03 Sosacharo.mp3

/Users/filipp/Music/iTunes/iTunes Music/Ochre/Lemodie/03 Sosacharo.mp3 -------------
kMDItemAlbum                    = "Lemodie"
kMDItemAttributeChangeDate      = 2006-09-02 16:30:07 +0300
kMDItemAudioBitRate             = 320
kMDItemAudioChannelCount        = 2
kMDItemAudioEncodingApplication = "LAME 3.96.1 --alt-preset insane"
kMDItemAudioSampleRate          = 44100
kMDItemAuthors                  = (Ochre)
kMDItemComment                  = "Ben034Cd"
kMDItemContentCreationDate      = 2006-06-27 11:13:02 +0300
kMDItemContentModificationDate  = 2006-06-27 11:13:02 +0300
kMDItemContentType              = "public.mp3"

… or you can also use Finder to graphically construct the query with a Smart Folder and just copy/paste it from the Get Info window. A lot of the iTunes-metadata (rating, playcount etc) is not exposed to Spotlight so you'll have to do some XML parsing if you want to find stuff based on that (sounds like a fun weekend project, now that I think about it…).

None of this will of course work with the M4P files from iTS. Regular M4A's shouldn't be a problem if you just use faad2.

And yes, it also works with video, just get a video player that reads from stdin (and a fat uplink!):

Pasted Graphic

MPEG4 video wouldn't play however, no matter what options I tried. Should probably try it with MPEG4IP some day.

back · essays · credits ·