| 
									
										
										
										
											2011-09-13 12:03:17 -04:00
										 |  |  | #!/usr/bin/perl | 
					
						
							| 
									
										
										
										
											2014-12-31 13:30:44 -05:00
										 |  |  | # Copyright (C) 2011, 2014, Bradley M. Kuhn | 
					
						
							| 
									
										
										
										
											2011-09-13 12:03:17 -04:00
										 |  |  | # | 
					
						
							|  |  |  | # This program gives you software freedom; you can copy, modify, convey, | 
					
						
							|  |  |  | # and/or redistribute it under the terms of the GNU General Public License | 
					
						
							|  |  |  | # as published by the Free Software Foundation; either version 3 of the | 
					
						
							|  |  |  | # License, or (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is distributed in the hope that it will be useful, but | 
					
						
							|  |  |  | # WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  | # General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # You should have received a copy of the GNU General Public License along | 
					
						
							|  |  |  | # with this program in a file called 'GPLv3'.  If not, write to the: | 
					
						
							|  |  |  | #    Free Software Foundation, Inc., 51 Franklin St, Fifth Floor | 
					
						
							|  |  |  | #                                    Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  | use strict; | 
					
						
							|  |  |  | use warnings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | my %data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | while (<>) { | 
					
						
							|  |  |  |   chomp; | 
					
						
							| 
									
										
										
										
											2014-12-31 13:24:41 -05:00
										 |  |  |   next unless /^(\S+)\s+[^"]+"\s*(GET)\s+(\S+)[\s"]/; | 
					
						
							|  |  |  | #  die "invalid line: $_" | 
					
						
							|  |  |  | #    unless /^(\S+)\s+[^"]+"\s*(LOCK|HEAD|GET|POST|OPTIONS|PUT|CONNECT|PROPFIND)\s+(\S+)[\s"]/; | 
					
						
							| 
									
										
										
										
											2011-09-13 12:05:54 -04:00
										 |  |  |   my($ip, $method, $url) = ($1, $2, $3); | 
					
						
							|  |  |  |   next unless $method =~ /^\s*GET\s*$/i; | 
					
						
							| 
									
										
										
										
											2011-09-13 12:03:17 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-13 13:17:34 -04:00
										 |  |  |   $url =~ s/\s*\.(ogg|mp3)\s*$/.audio/i;   # Treat ogg and mp3 downloads same. | 
					
						
							|  |  |  |   $url =~ s/\s*\/$$//;   # Always remove trailing slash  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-13 12:03:17 -04:00
										 |  |  |   $data{$url}{__TOTAL__} = 0 unless defined $data{$url}{__TOTAL__}; | 
					
						
							|  |  |  |   $data{$url}{__TOTAL__}++; | 
					
						
							| 
									
										
										
										
											2014-12-31 13:30:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   $data{$url}{__UNIQUE_TOTAL__} = 0 unless defined $data{$url}{__UNIQUE_TOTAL__}; | 
					
						
							|  |  |  |   $data{$url}{__UNIQUE_TOTAL__}++ if not defined $data{$url}{$ip}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   $data{$url}{$ip} = 0 unless defined $data{$url}{$ip}; | 
					
						
							|  |  |  |   $data{$url}{$ip}++; | 
					
						
							| 
									
										
										
										
											2011-09-13 12:03:17 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-31 13:30:44 -05:00
										 |  |  | foreach my $url (sort { $data{$b}{__UNIQUE_TOTAL__} <=> $data{$a}{__UNIQUE_TOTAL__}} | 
					
						
							| 
									
										
										
										
											2011-09-13 12:03:17 -04:00
										 |  |  |                  keys %data) { | 
					
						
							| 
									
										
										
										
											2014-12-31 13:30:44 -05:00
										 |  |  |   print "$url: $data{$url}{__UNIQUE_TOTAL__}\n"; | 
					
						
							| 
									
										
										
										
											2011-09-13 12:03:17 -04:00
										 |  |  | } | 
					
						
							|  |  |  | ############################################################################### | 
					
						
							|  |  |  | # Local variables: | 
					
						
							|  |  |  | # compile-command: "perl -c oggcast-count.plx" | 
					
						
							|  |  |  | # End: |