This script will put make the top post of your LiveJournal reflect the music you're listening to in your Winamp, in near-realtime.
The requirements and settings are all in the code below. Note you will need a slightly modified Winamp::Control which adds user-configurable passwords.

I should note that at the moment there is a slight delay between deleteing the old post and posting the new one, so the box for Current Music will sometimes be missing. If you increase the update interval, this will be less noticeable.

Assuming I'm at my cowputer, you can see this in action at my livejournal. It's not very interesting... yet. :-)
##### Winamp -> LiveJournal ##### # winamp2lj.pl # # Author: Joshua Thomas (jthomas @ poweronemedia dot com) # Version: 0.01 # Platform: Win32 # Copyright: GNU Public License (http://www.gnu.org) # # This script will make the top entry in your LiveJournal reflect # the music playing in your Winamp. It is smart enough to detect # when you're skipping around or not listening to anything. # # Requires: Modified Winamp::Control (added password option) # (http://cowbert.2y.net/~ibanix/winamp-control-0.02-new.tar) # # LJ::Simple, and Winamp httpQ plugin also required. # httpQ was last seen at: http://www.kostaa.com/winamp # Install the modules. Activate the plugin, chose a password and port. # Edit variables (below) to reflect settings, and let 'er rip. # # Great canidate to run as a NT/2K/XP service via FireDaemon. # ################################### use strict; use warnings; use LJ::Simple; use Winamp::Control; # These three should reflect settings in the httpQ module my $host = "localhost"; my $port = 4800; my $pass = "somepassword"; # How often to update my $interval = 10; # How far to look back to delete entry # Shouldn't have to mess with this unless you update really often my $lookback = 3; my $before = undef; my @opts = ( $lookback, $before ); # undef = never timeout # anything else = die if can't talk to server after X seconds # my $timeout = 60; # $LJ::Simple::Timeout = $timeout; undef $LJ::Simple::timeout; my %Entries=(); my %new_entry=(); # LJ connection # Change to reflect your LJ username/password my $lj = new LJ::Simple ( { user => "MyUserNameHere", pass => "MyPasswordHere", pics => 0, moods => 0, } ); # Winamp control my $winamp = Winamp::Control->new( host => $host, port => $port, pass +=> $pass ) || die "Could not connect: $!\n"; my $skipping_entry = "<i>Skipping Around....</i>\n"; my $not_playing_entry = "<i>Music is Off!</i>\n"; my $subject = "<b>Current Music</b>"; LOOP: while (sleep $interval) { # Get old post if any (defined $lj->GetEntries(\%Entries,undef,"lastn",@opts)) || die "$ +0: Failed to get entries - $LJ::Simple::error\n"; # If we find a match (after startup, we should!), delete foreach my $Entry (values %Entries) { my $subj=$lj->GetSubject($Entry); if ($subj eq $subject) { my ($item_id,$anum,$html_id)=$lj->GetItemId($Entry); $lj->DeleteEntry($item_id) || die "$0: Failed to delete jo +urnal entry - $LJ::Simple::error\n"; print "Deleted old entry #: $item_id\n"; } } # Now we can slurp relevant Winamp info my $id3title = $winamp->getid3tag_songname(); my $id3artist = $winamp->getid3tag_artist(); my $id3album = $winamp->getid3tag_album(); my $id3year = $winamp->getid3tag_year(); my $id3genre = $winamp->getid3tag_genre(); my $id3comment = $winamp->getid3tag_comment(); my $current_title = $winamp->getcurrenttitle(); my $is_playing = $winamp->isplaying(); my $pos = $winamp->getoutputtime( a => 0); $pos /= 1000; # Build output for LJ my $text_title_only = "Song: \t<i>$current_title</i>\n"; $text_title_only .= "<i>Extended info not available</i>"; my $text_id3_tags = "Title: \t<i>$id3title</i>\n"; $text_id3_tags .= "Artist: \t<i>$id3artist</i>\n"; $text_id3_tags .= "Album: \t<i>$id3album</i>\n"; $text_id3_tags .= "Year: \t<i>$id3year</i>\n"; $text_id3_tags .= "Genre: \t<i>$id3genre</i>\n"; $text_id3_tags .= "Comment: \t<i>$id3comment</i>"; # LJ entry header $lj->NewEntry(\%new_entry) || die "$0: Failed to prepare new post +- $LJ::Simple::error\n"; # Pick our entry text depending on what's going on # Order of these is important! $lj->SetEntry(\%new_entry, $text_title_only) if not ($id3title); $lj->SetEntry(\%new_entry, $text_id3_tags) if ($id3title); $lj->SetEntry(\%new_entry, $skipping_entry) if ($pos < 10); $lj->SetEntry(\%new_entry, $not_playing_entry) if ($is_playing != +1); # Set subject $lj->SetSubject(\%new_entry, $subject) || die "$0: Bad set subject + line\n"; # Uncomment this to make the post private. Really just for debuggi +ng. # $lj->SetProtectPrivate(\%new_entry) || die "$0: Failed to protec +t via private - $LJ::Simple::error\n"; # Post it, sucka my ($item_id, $anum, $html_id) = $lj->PostEntry(\%new_entry); defined $item_id || die "$0: Failed to submit new journal entry - +$LJ::Simple::error\n"; print "I posted new entry #: $item_id\n"; }
Cheers,
ibanix

update (broquaint): added <readmore> tags


In reply to Winamp -> LiveJournal by ibanix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.