--- apt-mirror-0.4.5/apt-mirror	2009-11-04 21:41:08.000000000 -0500
+++ /usr/bin/apt-mirror	2009-11-04 22:31:35.000000000 -0500
@@ -372,11 +372,53 @@
     }
 }
 
+sub should_process {
+    # print "should_process()\n";
+    my $pkg_name = shift;
+    my $section_name = shift;
+    my @popular_pkgs = @{ $_[0] };
+
+    # if the pkg isn't in the 'game' section...
+    if($section_name !~ /game/){
+        my %is_popular;
+        for (@popular_pkgs) { $is_popular{$_} = 1 };
+
+        if( $is_popular{$pkg_name} ) {
+            # print "processing popular pkg: " . $pkg_name . "\n";
+            return 1;
+        } else {
+            # print "skipping unpopular pkg: " . $pkg_name . "\n";
+            return 0;
+        }
+    } else {
+        # print "skipping game pkg: " . $pkg_name . "\n";
+        return 0;
+    }
+}
+
+
 sub proceed_index_gz {
     my $uri = shift;
     my $index = shift;
     my ($path, $package, $mirror, $files) = '';
 
+    # open our popcon database
+    my $db_path = "/home/tz/Desktop/by_inst";
+    open(FILE,$db_path) or die "Can't open popcon db: $!";
+    my @data=<FILE>; # beware record separator ($/) tweak below
+    close FILE;
+    my $num_comment_lines = 11;
+    my $threshold = 3000;
+    my $cur_line;
+    my @popular_pkgs;
+    # for each of the first $threshold lines, grab pkg name
+    foreach $cur_line (@data[$num_comment_lines .. ($num_comment_lines + $threshold)]) {
+        # print "cur_line: $cur_line";
+        my @tokens = split / +/, $cur_line;
+        # print "pkgname: " . $tokens[1] . "\n";
+        push( @popular_pkgs, $tokens[1] );
+    }
+
     $path = $uri;
     $path =~ s[^(\w+)://][];
     $path =~ s/~/\%7E/g if get_variable("_tilde");
@@ -403,7 +445,9 @@
 	    print FILES_MD5 $lines{"MD5sum:"} . "  " . remove_double_slashes($path . "/" . $lines{"Filename:"}) . "\n";
 	    if(need_update($mirror . "/" . $lines{"Filename:"}, $lines{"Size:"})) {
 		print FILES_NEW remove_double_slashes($uri . "/" . $lines{"Filename:"}) . "\n";
-		add_url_to_download($uri . "/" . $lines{"Filename:"}, $lines{"Size:"});
+		if( should_process( $lines{"Package:"}, $lines{"Section:"}, \@popular_pkgs ) ) {
+		     add_url_to_download($uri . "/" . $lines{"Filename:"}, $lines{"Size:"});
+		}
 	    }
 	} else {				# Sources index
 	    foreach (split(/\n/, $lines{"Files:"})) {
@@ -415,7 +459,9 @@
 		print FILES_MD5 $file[0] . "  " . remove_double_slashes($path . "/" . $lines{"Directory:"} . "/" . $file[2]) . "\n";
 		if(need_update($mirror . "/" . $lines{"Directory:"} . "/" . $file[2], $file[1])) {
 		    print FILES_NEW remove_double_slashes($uri . "/" . $lines{"Directory:"} . "/" . $file[2]) . "\n";
-		    add_url_to_download($uri . "/" . $lines{"Directory:"} . "/" . $file[2], $file[1]);
+		    if( should_process( $lines{"Package:"}, $lines{"Section:"}, \@popular_pkgs ) ) {
+			add_url_to_download($uri . "/" . $lines{"Directory:"} . "/" . $file[2], $file[1]);
+		    }
 		}
 	    }
 	}
