Slashdot Mirror


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.

30 of 122 comments (clear)

  1. geez by Triumph+The+Insult+C · · Score: 4, Informative

    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!
  2. So? by ayf6 · · Score: 4, Interesting

    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.

    1. Re:So? by L0C0loco · · Score: 3, Interesting

      Well imagine this interfaced to a website where you can browse the available material and "print" tracks to the audio queue. Rather than just playing the audio locally, it adds it to the webacast audio stream you are listening to (a queue for each stream). You can easily monitor the queue/streams from the same website - all without needing to mess with a database. It would also be easy to have a background "DJ" script loading the queue periodically with randomly selected tracks with a low priority. That way a real user can easily jump ahead in the queue with thier request. Plus you can see who requested what. Personally, I'd rather muck around with a mysql db, but some others may find this useful and it does seem like a lot of functionality ready to use.

      --
      -- Instant Karma's gonna get you! [320848 = 2*2*2*2*11*1823]
    2. Re:So? by DeadSea · · Score: 2, Interesting

      Its pretty easy to send a file to a unix print queue from Windows: http://gccprinters.com/support/doc/lprutil.html

  3. Site is slashdotted; article text by ethnocidal · · Score: 5, Informative

    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.

    -- 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 /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:

    mp3:\ :lp=/dev/null:\ :sd=/var/spool/lpd/audio:\ :if=/usr/local/bin/audiofilter:\ :af=/var/log/audio-acct:\ :lf=/var/log/audio-errs:\ :sh

    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: :lp=/dev/null: - we're not hooking this up to a physical device in the normal sense
    * 3: :if=/usr/local/bin/audiofilter: - this is the input filter. I'll show how to create it later.
    * 4: :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.
    * 5: :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.
    * 6: :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.

    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 /usr/local/bin/audiofilter:

    #!/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 --

    1. Re:Site is slashdotted; article text by pridkett · · Score: 4, Informative

      So you're probably wondering why it is slashdotted...well probably not, but if you were. The site is served over a terrestrial wireless broadband from Sprint Broadband Direct with a maximum uplink of 15k/s. Furthermore the server, is circa 1997 AMD-K6/200 with 96 megs of ram.

      So this finally answers the question of "can slashdot destroy a low grade consumer broadband connection?". Incidentally, the load on the server is still around 0.4. I think it peaked out around 0.8.

      Sigh...slashdot needs a distributed automated mirroring service.

      And if you're wondering, I did the article on my weblog because people on deadly were asking about how to do it. On guy even thought they had a sound device (remember the speech thing?) connected to the parallel port doing it.

      --
      My Slashdot account is old enough to drink...
    2. Re:Site is slashdotted; article text by bsharitt · · Score: 5, Funny

      It's not Slashdotted, your just waiting in the LDP queue to see the site.

  4. Good hack, litteral sense by koh · · Score: 4, Funny

    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.
    1. Re:Good hack, litteral sense by uhoreg · · Score: 2, Informative

      There are already some emacs mp3 players.

      --

      To get something done, a committee should consist of no more than three persons, two of them absent.

  5. lpd generic wrapper libs in C/C++/Java/...? by hrbrmstr · · Score: 4, Interesting

    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...
  6. Useless... by TedCheshireAcad · · Score: 5, Funny

    ...unless it can be used as a porn queueing mechanism.

  7. Funky, but by nich37ways · · Score: 5, Funny

    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...
  8. Article mirror by SILIZIUMM · · Score: 3, Informative
    http://pages.infinit.net/pmessier/slashdotted/0001 28.html

    And enjoy. Don't mod me up though, it would be karma-whoring.

    And wanted to add that the idea isn't new as you can see in this recent thread on deadly.org here (See post "mp3's playing via lpr?").

  9. Been there, done that by dpokorny · · Score: 3, Interesting

    This is something I did about five years ago when MP3s where just starting to become popular. It included writing a front-end in Java that was served via an Apache web server on the music host.

    It was actually quite successful and kept my house in 24x7 music for about four years. Unfortunately, I retired all of my lpd-based printers and started using CUPS, so I also killed the mp3 queue too.

  10. lpd is nice? by timeOday · · Score: 3, Interesting

    I don't much like lpd. To me it is one of those crufty old programs that never seems to work right, never gives informative error messages, and whose configuration is arcane. Other nominees: ntp and sendmail. (And yes, I'm sure they're all wonderful once you've mastered them).

  11. CUPS also by FauxPasIII · · Score: 4, Informative

    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
    1. Re:CUPS also by FauxPasIII · · Score: 2, Informative

      The magic part is this:

      pstopnm -stdout file.ps | pnmtojpeg > file.jpeg

      Both of those filters are in the netpbm package:
      http://netpbm.sourceforge.net/

      --
      25% Funny, 25% Insightful, 25% Informative, 25% Troll
    2. Re:CUPS also by AnyoneEB · · Score: 3, Informative

      If you want a Windows PDF printer you can use FreePDF which is mostly a GhostScript frontend that appears as a printer.

      --
      Centralization breaks the internet.
  12. DNS zone transfers by hey · · Score: 2, Funny

    While we're hacking ... how about using DNS zone transfers. Its distributed (everywhere) and its cached until a change occurs. Maybe you'd have to uuencode the info. But what if every .com entry had a few MP3s!

  13. so an error could message may be by DrWhizBang · · Score: 4, Funny

    "/dev/dsp" is on fire!

    --
    Schrodinger's cat is either dead or really pissed off...
  14. HIgh End Queuing? by bigattichouse · · Score: 2, Insightful

    Could this be adapted for a MQ system (say queuing database queries?).. just adding some extra info into the "document", like where the query came from, etc. What kind of load can it handle?

    --
    meh
  15. That takes alot of paper! by Anonymous Coward · · Score: 5, Funny

    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....

  16. Responsible Reporting by nurb432 · · Score: 3, Interesting

    Slashdot REALLY needs to start being more responsible and contacting these people first..

    Sure, report news as needed, but before *linking* ASK them if they can deal with the load.. or the cost after being hit hard..

    This is getting really bad, and i can feel a 'anti-slashdot' movement growing over this sort of thing.

    --
    ---- Booth was a patriot ----
    1. Re:Responsible Reporting by cjsnell · · Score: 2, Funny


      Well, in that case, warn this guy that his page will be slashdotted early next week, when the dupe story gets posted.

      Chris

  17. If I accidentally print an MP3... by fobbman · · Score: 4, Interesting

    ...will it do something like this?

  18. Huh ? by Moderation+abuser · · Score: 2, Funny

    I just let xmms handle the queueing of music, in a thing called a "play list".

    However, for real geekiness, you should be using gridengine to queue and distribute your mp3s.

    --
    Government of the people, by corporate executives, for corporate profits.
  19. I'm sure it's very nice... by The+Fanta+Menace · · Score: 4, Funny

    ...until you accidentally spool that mp3 to the printer ;)

    --
    -- Even if a god did exist, why the fsck should I worship it?
  20. So sick of this! by sker · · Score: 4, Funny

    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.
  21. Did it with cups! by zdzichu · · Score: 3, Funny

    Whoa. My CUPS is right now playing some .ogg files :)

    Steps are simple:
    1. uncomment
    #application/octet-stream
    at the very end of /etc/cups/mime.types

    3. drop this
    ---
    #!/bin/bash

    if [ $# = 0 ] ; then
    echo network audioplay \"Unknown\" \"Audio Player\";
    exit 0;
    fi
    /usr/local/bin/mplayer -really-quiet "$6" >> /dev/null
    ----
    in /usr/lib/cups/backend/ as audioplay
    chmod it +x and restart cups

    4. Add printer in cups:
    name: audio
    location: /dev/null
    description: Hacked Audio-playing CUPS
    device: Audio player
    (if you don't see this device, you probably haven't restarted cups or audioplay is not executable)
    device uri: audioplay://unused/
    make: raw
    model: rawqueue

    4. cat your_favourite.ogg | lpr -r -Paudio
    you can also do
    lpr -Paudio -r song.mp3
    but be careful, lpr likes to delete file after printing.

    5. Prof^WEnjoy!

    --
    :wq
  22. Securitah Warning by cjsnell · · Score: 2, Interesting


    Beware, these scripts appear to be vulnerable to to un-escaped shell command characters (ie ', ", &, etc) in the filename. The script does not do any validation of the file that is sent to it. Since LPD doesn't do any authentication by default, be very careful about running this stuff on a public-accessible machine.

    Chris