#!/usr/bin/perl -w # Author: Chris Ball # Gives a list of popular bands based on livejournal.com 'music' entries. use strict; use IO::Socket; my $ljsock = IO::Socket::INET->new( PeerAddr => "216.231.32.123", PeerPort => "80", Proto => "tcp", Type => SOCK_STREAM) or die "Couldn't connect to the livejournal.com web server : $@\n"; # Declare some vars. my (@items, @music); my ($user, $pass, $key, $value, $total); my $counter = 1; my %artistes; print "Enter your livejournal username: "; $user = ; chomp $user; print "Enter your livejournal password: "; $pass = ; chomp $pass; # Set up before printing to ljsock. my $string = "mode=syncitems&user=$user&password=$pass"; my $line1 = "POST /cgi-bin/log.cgi HTTP/1.0\r\n"; my $line2 = "Host: www.livejournal.com\r\n"; my $line3 = "Content-type: application/x-www-form-urlencoded\r\n"; my $line4 = "Content-length: " . length($string) . "\r\n"; my $line5 = "\r\n"; # Retrieve all journal entries, using the syncitems mode. print $ljsock $line1 . $line2 . $line3 . $line4 . $line5 . $string. "\r\n\r\n"; my $reply = <$ljsock>; while(<$ljsock>) { push @items, $_ if $_ =~ /^L-/; if ($_ =~ /^sync_count$/) { $total = <$ljsock>; chomp $total; } } print "\n\nTotal number of journal entries to download: $total.\n\n"; foreach my $item (@items) { chomp($item); $item =~ s/L-//; $ljsock = IO::Socket::INET->new( PeerAddr => "216.231.32.123", PeerPort => "80", Proto => "tcp", Type => SOCK_STREAM) or die "Couldn't connect to the livejournal.com web server : $@\n"; my $string = "mode=getevents&user=$user&password=$pass&selecttype=one&itemid=$item"; my $line1 = "POST /cgi-bin/log.cgi HTTP/1.0\r\n"; my $line2 = "Host: www.livejournal.com\r\n"; my $line3 = "Content-type: application/x-www-form-urlencoded\r\n"; my $line4 = "Content-length: " . length($string) . "\r\n"; my $line5 = "\r\n"; # Retrieve all journal entries, using the getevents mode. print "Retrieving itemid: $item. ($counter of $total)\n"; $counter++; print $ljsock $line1 . $line2 . $line3 . $line4 . $line5 . $string. "\r\n\ r\n"; my $reply = <$ljsock>; while(<$ljsock>) { if (/^current_music$/) { <$ljsock>; my $found = <$ljsock>; push @music, $found; } } } foreach my $song (@music) { print $song; $song =~ s/\.//g; if ($song =~ /(.*) - (.*)/) { push @{$artistes{$1}}, $2 }; } print "$_: ",scalar @{$artistes{$_}},"\n" foreach sort { scalar @{$artistes{$b}}<=>scalar @{$artistes{$a}} || ($a cmp $b) } keys %artistes;