Penguin

(Using Squid 2.7)

Configuration

acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl localnet1 src x.x.0.0/16
acl localnet2 src x.x.0.0/16
acl SSL_ports port 443
acl CONNECT method CONNECT

http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localnet1
http_access allow localnet2
http_access deny all
icp_access allow localnet
icp_access deny all
http_port 3128
maximum_object_size_in_memory 65535 KB
cache_dir ufs /usr/local/squid/var/cache 10000 16 256
maximum_object_size 65535 KB
access_log /usr/local/squid/var/logs/access.log squid
storeurl_rewrite_children 50
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i \.flv$       10080   90%     999999 ignore-no-cache override-expire ignore-private
refresh_pattern ^http://sjl-v[0-9]+\.sjl\.youtube\.com 10080 90% 999999 ignore-no-cache override-expire ignore-private
refresh_pattern get_video\?video_id 10080 90% 999999 ignore-no-cache override-expire ignore-private
refresh_pattern youtube\.com/get_video\? 10080 90% 999999 ignore-no-cache override-expire ignore-private
refresh_pattern .               0       20%     4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
coredump_dir /usr/local/squid/var/cache
acl youtube dstdomain .youtube.com .googlevideo.com .video.google.com .video.google.com.au
acl youtubeip dst 74.125.15.0/24
acl youtubeip dst 64.15.0.0/16
cache allow youtube
cache allow youtubeip
acl store_rewrite_list dstdomain mt.google.com mt0.google.com mt1.google.com mt2.google.com
acl store_rewrite_list dstdomain mt3.google.com
acl store_rewrite_list dstdomain kh.google.com kh0.google.com kh1.google.com kh2.google.com
acl store_rewrite_list dstdomain kh3.google.com
acl store_rewrite_list dstdomain kh.google.com.au kh0.google.com.au kh1.google.com.au
acl store_rewrite_list dstdomain kh2.google.com.au kh3.google.com.au
acl store_rewrite_list dstdomain .youtube.com
storeurl_access allow store_rewrite_list
storeurl_access deny all
storeurl_rewrite_program /archives/youtube
quick_abort_min -1 KB

The /archives/youtube program

#!/usr/bin/perl
use IO::File;

STDOUT->autoflush(1);

my $logfile = '/tmp/debug.log';

open my $logfh, '>>', $logfile
    or die "Couldn't open $logfile for appending: $!\n";

$logfh->autoflush(1);

while (<>) {
    chomp;
    my $out =
        m{kh(.*?)\.google\.com(.*?)/(.*?) } ? "http://keyhole-srv.google.com$2.SQUIDINTERNAL/$3"                 :
        m{mt(.*?)\.google\.com(.*?)/(.*?) } ? "http://map-srv.google.com$2.SQUIDINTERNAL/$3"                     :
        m{^http://([A-Za-z]*?)-(.*?)\.(.*)\.youtube\.com/get_video\?video_id=([^&]+).* }
                                            ? "http://video-srv.youtube.com.SQUIDINTERNAL/get_video?video_id=$4" :
        m{^http://([A-Za-z]*?)-(.*?)\.(.*)\.youtube\.com/get_video\?video_id=(.*) }
                                            ? "http://video-srv.youtube.com.SQUIDINTERNAL/get_video?video_id=$4" :
        $_;

    print $logfh "Original: $_\n", "Translation: $out\n\n";
    print "$out\n";
}