#!/usr/bin/perl -w # -*- cperl - # # Parse ShoutCast v1.9.8 W3C log and append "GET" to each log line to pretend it's a web logfile # # Usage: perl sc_parse.pl -c /full/path/to/shoutcast/sc_w3c.log # # Written by Ryan Gehrig # use Getopt::Std; our $opt_c; getopts('c:'); # Open the log file if (-e $opt_c) { print "Parsing log '$opt_c' ...\n"; open FILE, "$opt_c" or die "ERROR: Failed to open log file\n"; my @lines = ; foreach(@lines) { # Ignore comments if("$_" !~ /^\#/) { # Lose newlines $_ =~ s/\n//; #### Here I start editing/adding # First approach: # This works, but I cant add such a line for # every known and future player! there should be a way # to get the 7th word replaced anyway: # Look for flashplayer #$_ =~ s/MPEG\%20OVERRIDE/FlashPlayer/; # More realistic approach: # Obviously it fails for an unexperienced programmer as me: # 7th string are players, focus on it #my @words = split(' ', $_); #if(@words[6] =~ m/MPEG\%20OVERRIDE/){ # @words[6] = "FlashPlayer"; #} #elsif(@words[6] =~ m/^vlc/){ # @words[6] = "VLC"; #} #I could add more occurences here #else { # @words[6] = "other"; #} #### Here ends my editing/adding # Write this line to new log file "sc_w3c.log_x" open (MYFILE, '>>'.$opt_c.'_x'); print MYFILE "$_" . ' GET' . "\n"; close (MYFILE); } } close(FILE); } else { print "ERROR: The specified log file doesnt exist. Exiting.\n"; }