##### 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 = "Skipping Around....\n"; my $not_playing_entry = "Music is Off!\n"; my $subject = "Current Music"; 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 journal 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$current_title\n"; $text_title_only .= "Extended info not available"; my $text_id3_tags = "Title: \t$id3title\n"; $text_id3_tags .= "Artist: \t$id3artist\n"; $text_id3_tags .= "Album: \t$id3album\n"; $text_id3_tags .= "Year: \t$id3year\n"; $text_id3_tags .= "Genre: \t$id3genre\n"; $text_id3_tags .= "Comment: \t$id3comment"; # 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 debugging. # $lj->SetProtectPrivate(\%new_entry) || die "$0: Failed to protect 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"; }