LPD For Fun and MP3 Playing
poop writes "Most true Unix geeks will recognize just how nice LPD is as a distributed queueing mechanism for managing all jobs sent to the printer. But, what most people don't realize is that LPD can be used for other things too. In fact, it can be viewed as a general queueing mechanism with a few added bells and whistles for printers. So let's examine a more interesting use of LPD, an engine for distributed spooling of MP3s." Bruha points out this mirror.
this has been getting a lot of coverage this week (article on deadly, some canadian newspaper, and now here). they did it at the obsd hackathon last year, and again this year.
lpd is quite cool. i've used it to queue software builds on remote machines where we aren't given ssh accounts. it's pretty slick.
vodka, straight up, thank you!
The real beauty of this would be if he had written a "print" driver that would allow a remote PC running windows to queue up a song thus utilizing lpd to be a "music" server rather then just an mp3 player hack.
I don't normally do this, but as the site seems to be almost dead within the first three posts, I've duplicated the article content in this post.
/etc/printcap on my redhat 7.3 system (no sound card on the openBSD firewall) it is /etc/printcap.local. You'll want to paste the following snipped of code in there:
:lp=/dev/null:\ :sd=/var/spool/lpd/audio:\ :if=/usr/local/bin/audiofilter:\ :af=/var/log/audio-acct:\ :lf=/var/log/audio-errs:\ :sh
:lp=/dev/null: - we're not hooking this up to a physical device in the normal sense :if=/usr/local/bin/audiofilter: - this is the input filter. I'll show how to create it later. :af=/var/log/audio-acct: - this is the accounting file. You could do some fun stuff with this to monitor who uses the queue the most and what not. :lf=/var/log/audio-errs: - this is the file that errors will be logged to. Well, some errors; not all errors will end up here. :sh - tells it to supress any header information that would normally be sent. This is important or you may get junk before every file which causes audiofilter to fail.
/usr/local/bin/audiofilter:
;; ;; ;;
-- article --
May 23, 2003
LPD for fun and MP3 playing
Background
Most true Unix geeks will recognize just how nice LPD is as a distributed queueing mechanism for managing all jobs sent to the printer. It has a beautiful simplicity to it, and some mean power to go along with it. It's a difficult beast to tame, but once you understand it, everything will start coming out exactly like you want it.
But, what most people don't realize is that LPD can be used for other things too. In fact, it can be viewed as a general queueing mechanism with a few added bells and whistles for printers. So let's examine a more interesting use of LPD, an engine for distributed spooling of MP3s.
Motivation
The main thing that got me started on this quest was seeing these two pictures (one, two) from the c2k3 openBSD hackathon I saw that obviously someone else had figured out how to do it. I sure as heck could also.
Initial Assessment
The first stop on my quest was examine the all-knowing seer of the Internet, google. That returned a wonderful page in Swedish about how to do this very task. Unfortunately, my swedish sucks, but thankfully the scripts were written in bash, and the other big thing was just a printcap file.
Creating a Printcap Entry
The first thing that you need to do is to create an entry in your printcap file for your shiny new mp3 printer. On most systems this file is
mp3:\
Now we'll walk through the entry line by line. I'll ignore the \ at the end of almost every line, that just tells lpd to keep reading because there is more to come. The last line doesn't need the \ obviously.
* 1: mp3: - the name of your mp3 printer. In this case, just mp3
* 2:
* 3:
* 4:
* 5:
* 6:
An Audio Input Filter
The key to the whole system is that all of the processing is done by input filter. On some platforms this may cause it say that the printing has stalled while a song is playing, but that's not a big deal. There is no output from the input filter, and thus nothing is done after this. You'll want to put the following piece of code on your system as
#!/bin/bash
#
# This script was originally made by Teddy Hogeborn.
# Small alterations was made by:
# Peter Lundqvist
# Patrick Wagstrom
#
# This is a "printer filter" for playing audio files
for arg in "$@"; do
case "$arg" in
-d*) dir="${arg#-d}"
-e*) basefile="${arg#-e}"
-f*.*) ext="${arg##*.}"
esac
done
mp3player="mpg123 -q -o oss";
modplayer="mikmod --quiet --playmode 0 --noloops --
I'm suprised they didn't try to pull this feat on Emacs first though.
:)
Next in line, "sendmail configuration files used as crypto keys"
Karma cannot be described by words alone.
Anyone have any links to some libraries or projects that might use lpd as a transport for generic queueing? Seems like a nice, language-agnostic, non-complex mechanism for cross-system job scheduling, etc. No real security model (though one could adapt something to it), but cool and readily available nonetheless.
Given what one can do with ghostscript queues, this is not exactly rocket science, but it goes to show the flexibility of *nix once again.
Mind the gap...
...unless it can be used as a porn queueing mechanism.
The real problem I see with this is, you will always get some sadistic bastard who spools a ton of *pop* music before disapearing out of ear shot or some fool who doesnt understand how it works and sticks the same song in over and over again.
Apart form that looks very fun for a small network with shared sound.
37 - what does it stand for really...
I like CUPS's mechanism for this kind of thing even more. You basically have two components, a filter and a backend. The filter takes in one a few forms of input (mostly postscript, but plain text and some image formats also) and dumps out the native data format of the selected printer model (or just echos the input if you set it as a raw queue). The backend is then responsible for somehow getting it to the printer, either queueing it on the parallel port or sending it out on the network somehow, or anything else.
Some fun things I've done with backends:
Network printing over SSH
Text-to-speech queueing (print your source code to hear it read aloud by festival)
Dumping into a jpeg as a way of snapshotting any document you might want to save
Dumping into a PDF with ps2pdf to make your Windows friends feel stupid for buying Distiller =)
25% Funny, 25% Insightful, 25% Informative, 25% Troll
"/dev/dsp" is on fire!
Schrodinger's cat is either dead or really pissed off...
I sent my entire playlist to lpd and i've gone through all my paper, is there a way to make it print 4-up to save a few trees? To be honest I don't see the appeal of this....
...will it do something like this?
...until you accidentally spool that mp3 to the printer ;)
-- Even if a god did exist, why the fsck should I worship it?
I can't BELIEVE the RIAA is trying to shut thus guy down for...
Oh they're not?
Well.. How DARE SCO sue this guy for using...
Err, wait..
This is an article.. about someone using software technology... to accomplish a task... and there's no litigation involved???
OH MY GOD!!!!
nonsig. unsig. desig.