Cache Youtube dengan Squid Proxy

Dengan melakukan cache video, image, pada web site yang sering di buka seperti cache youtube, cache facebook dan lain sebagai nya. Squid Proxy yang sudah di bangun akan lebih maksimal dalam hal penghematan bandwidth dan mempercepat saat browsing.

Untuk kali ini DSI akan berbagi tutorial Cache Youtube Video dengan Squid Proxy sesuai janji DSI pada artikel sebelumnya.

Baca : tutorial install squid3 dengan mudah

Masalah Cache YouTube

CDN ( Content Delivery Network) Youtube

Youtube mempunyai server cadangan di beberapa negara. Agar video youtube mudah dan cepat saat di akses oleh semua pengunjung di dunia. Pengunjung akan di respond dari server yang paling dekat dengan negara nya.

Dynamic URL Youtube

Url video youtube selalu ber ubah – ubah (Dinamis). Sebagai contoh lihat url video dari gambar berikut:

cache youtube

Solusi supaya url youtube menjadi statis (tetap) dan bisa di cache harus menggunakan “STORE-ID”. Sehingga dengan url yang statis maka squid dapat melakukan cache youtube.

Youtube Mengunakan Port 443 (HTTPS)

Untuk melakukan cache youtube anda harus meng install squid yang sudah support dengan web https.

baca : Tutorial install squid untuk cache HTTPS

STORE-ID Youtube

Sekilas STORE-ID, berfungsi menulis ulang url yang masuk ke dalam helper store-id menjadi url yang tetap (statis). Helper Store-id dapat di tulis dengan bahasa pemrograman seperti perl, php, Python dan lain sebagai nya.

Di sini DSI akan memberikan script store-id untuk cache youtube menggunakan bahasa program perl.

  • Buka program putty dan login menggunan user root.
  • Buat file perl dan berikan nama “store-id.pl” pada directory “/etc/squid/”
touch /etc/squid/store-id.pl
  • Beri permision / akses ijin file store-id
chmod 777 /etc/squid/store-id.pl
chown -R proxy:proxy /etc/squid/store-id.pl
  • Masukan Script di bawah ini pada file “store-id.pl” yang sudah di buat tadi.
#!/usr/bin/perl
# =====================================================
# = DSI store-id sample youtube 2016
# = https://www.facebook.com/R.dhani.dhanu
# = https://www.dokter-squid.com/
# =====================================================
 
$|=1;
while (<>) {
chomp;
 
my $dsi = "";
if (s/^(\d+\s+)//o) { $dsi = $1; }
 
@X = split;
if (@X[0] =~ m/^(exit|quit|x|q)/) {
print STDERR "quiting helper quietly\n";
exit 0;
}
$url = $X[0];
$referer = $X[1];
 
# youtube.com
if ($url =~ m/^https?:\/\/.*\.googlevideo\.com\/videoplayback\?.*/) {
        @id = m/[\&?|\%?|\s?]id=([^\&\%\s]+)/;
        @range = m/[\&?|\%?|\s?]range=([^\&\%\s]+)/;
        @itag = m/[\&?|\%?|\s?]itag=([^\&\%\s]+)/;
        @mime = m/[\&?|\%?|\s?]mime=([^\&\%\s]+)/;
        @clen = m/[\&?|\%?|\s?]clen=([^\&\%\s]+)/;
        if ($referer =~ m/^https?\:\/\/www\.youtube\.com\/(watch\?v\=|embed\/|v\/)(.*)/) {
            $v = $2;
        } else { $v = $id[0] }
        $out = "http://youtube.dokter-squid.com/" . $v . "@range@itag@mime@clen";
 
 
# ytimg.com
} elsif ($url =~ m/^https?:\/\/.*\.ytimg\.com(.*\.(webp|jpg|gif))/) {
    $out = "http://ytimg.dokter-squid.com/$1";
 
} else  {
    $out = "ERR";
}
if ($out =~ m/^http:\/\/.*/) {
    print $dsi, "OK store-id=$out\n";
} else {
    print $dsi, "ERR\n";
}
}
  • Buka “squid.conf” lalu tambahkan script di bawah ini:
acl youtube url_regex -i ^https?:\/\/.*\.googlevideo\.com\/videoplayback\?
acl youtube url_regex -i ^https?:\/\/.*\.ytimg\.com.*\.(webp|jpg|gif)
store_id_program /etc/squid/store-id.pl
store_id_extras "%{Referer}>h"
store_id_children 10 startup=5 idle=2 concurrency=100
store_id_access allow youtube
store_id_access deny all
 
refresh_pattern -i ^http.*\.dokter\-squid\.com 432000 100% 432000 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-store ignore-private ignore-auth ignore-must-revalidate
  • Setelah kita menambahkan script “store-id” dan edit “squid.conf” sekarang saat nya lakukan “reconfigure”:
squid -k reconfigure

Sampai di sini jika tidak ada informasi “error” maka kita sudah berhasil membuat store-id untuk cache youtube. Silahkan di coba ulang kembali jika saat “reconfigure” terdapat informasi “error”.

Sekarang saatnya uji coba, apakah youtube berhasil di cache atau tidak dengan store-id di atas. Berikut contoh “access.log” video youtube yang sudah berhasil di cache dengan store-id diatas:

cache youtube hit

Demikian cara cache youtube dengan squid 3, semoga dengan tutorial ini pembaca sudah bisa melakukan cache youtube pada mesin proxy nya.

Bagi yang masih bingung dan malas untuk oprek, kami membuka Jasa Setting Proxy lewat remote, harga bersahabat dan bergaransi.

Jangan lupa subscribe dan Share jika anda merasa terbantu dan suka dengan artikel ini.

Terimakasih

39 Comments

Leave a Reply