#!/usr/bin/perl

$|=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?:\/\/.*youtube.*\/(stream_204|ptracking|player_204|user_watch|playback|qoe|atr|delayplay|gen_204|watchtime|set_awesome)\?.*/) {
		@code = m/[\&?|\%?|\s?](v|docid|video_id|content_v)=([^\%\&\s]+)/;
		@cpn = m/[\&?|\%?|\s?]cpn=([^\&\%\s]+)/;
		unless	(-e "/tmp/@cpn") {
		open code, ">/tmp/@cpn";
		print code "@code[1]";
		close code;}
		$out = "ERR";

} elsif ($url =~ m/^https?:\/\/.*\.googlevideo\.com\/videoplayback\?.*/) {
		@id = m/[\&?|\%?|\s?]id=([^\&\%\s]+)/;
		@range = m/[\&?|\%?|\s?]range=([^\&\%\s]+)/;
		@itag = m/[\&?|\%?|\s?]itag=([^\&\%\s]+)/;
		@cpn = m/[\&?|\%?|\s?]cpn=([^\&\%\s]+)/;
		@mime = m/[\&?|\%?|\s?]mime=([^\&\%\s]+)/;
		@clen = m/[\&?|\%?|\s?]clen=([^\&\%\s]+)/;
		if ($referer =~ m/^https?\:\/\/www\.youtube\.com\/(watch\?v\=|embed\/|v\/)(.*)/) {
			$v = $2;
		} elsif (defined(@cpn[0])){
		if      (-e "/tmp/@cpn") {
		open code, "/tmp/@cpn";
		@idd = <code>;
		close code;}
			$v = $idd[0];		
		} 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";

# youtube-mp.com
} elsif ($url =~ m/^http:\/\/[a-z0-9]+\.vd\.aclst\.com\/dl\.php\/[0-9a-zA-Z]+\/.*\.mp3\?video_id\=([a-zA-Z0-9]+)\&.*/) {
	$out = "http://youtube.dokter-squid.com/$1";

# windowsupdate
} elsif ($url =~ m/^http:\/\/.+?\.(ws\.microsoft|windowsupdate)\.com\/.+?\_([0-9a-z]{40}\.(cab|exe|ms[i|u|f]|asf|wm[v|a]|dat|zip|psf|appx|esd))/) {
	$out = "http://dokter-squid.com.windowsupdate.com/$2";	

# playstation
} elsif ($url =~ m/^http:\/\/.*\.dl\.playstation\.net\/[^\/]+\/a?ppkgo\/prod\/[^\/]+\/[^\/]+\/[^\/]+\/[a-zA-Z0-9]{1,2}\/(.*\.pkg)(\?.*|)/) {
	$out = "http://playstation.dokter-squid.com/$1";

# facebook.com
} elsif ($url =~ m/^https?:\/\/(fbcdn|scontent).*(akamaihd|fbcdn)\.net\/(h|s)(profile|photos).*\/((p|s).*\.(png|gif|jpg))(\?.+)?$/) {
	$out = "http://facebook.dokter-squid.com/$5";

} elsif ($url =~ m/^https?:\/\/fbcdn\-video\-.*\.akamaihd\.net\/h?video[^\/]+\/[^\/]+\/[^\/]+\/([^\/]+\.mp4)\?/) {
	$out = "http://facebook.dokter-squid.com/$1";

} elsif ($url =~ m/^https?:\/\/(fbcdn|scontent).*(akamaihd|fbcdn)\.net\/(h|s)(profile|photos).*\/(.*\.(png|gif|jpg))(\?.+)?$/) {
	$out = "http://facebook.dokter-squid.com/$5";

# gstatic
} elsif ($url =~ m/^https?:\/\/.*\.gstatic\.com\/images\?q=tbn\:(.*)/) {
	$out = "http://gstatic.dokter-squid.com/$1";

# F1
} elsif ($url =~ m/^http.*\.bitgravity\.com\/cdn\/\_definst_\/[^\/]+\/[^\/]+\/(\d+\d+\/\d+\/[^\/]+)\/.*\.ts$/) {
	$out = "http://f1.dokter-squid.com/$1";

# NBA
} elsif ($url =~ m/^http:\/\/a66\-w23\-.*\-nbavod\-f\.akamaihd\.net\/z\/nba\/big\/.*\/\d+\/\d+\/\d+\/(.*)\?.*/) {
	$out = "http://nba.dokter-squid.com/$1";

# 4shared preview and download
} elsif ($url =~ m/^https?:\/\/[a-z0-9]{5}\.(4shared\.com)\/(img|(download))\/(([\w]+\/[\w]+\/dlink__[23]F([\w]+)_[23]F(.*)\_3Ftsid_[\w].*)|(.*)\/.*\?.*)/) {
	$out = "http://4shared.dokter-squid.com/$1$3$6$7$8";

} elsif ($url =~ m/^http:\/\/.*4shared\.com\/download\/([a-zA-Z0-9]+)\?tsid\=.*/) {
	$out = "http://4shared.dokter-squid.com/$1";

# reverbnation
} elsif ($url =~ m/^https?:\/\/.*(reverbnation\.com)\/.*\/(ec_stream_song|download_song_direct|stream_song)\/([0-9]*).*/) {
	$out = "http://reverbnation.dokter-squid.com/$1$3";

# dota 2
} elsif ($url =~ m/^http:\/\/[^\/]+\/depot\/[^\/]*\/chunk\/([0-9a-zA-Z]+)$/) {
	$out = "http://steampowered.dokter-squid.com/$1";

} elsif ($url =~ m/^http:\/\/[^\/]+\/depot\/[^\/]*\/chunk\/([0-9a-zA-Z]+)\?etime\=[0-9a-z]+\&h\=[0-9a-z]+/) {
	$out = "http://steampowered.dokter-squid.com/$1";

# firedrive
} elsif ($url =~ m/^http:\/\/.*firedrive\.com\/download\/[0-9]+\/[0-9]+\/.*\?h=.*e\=.*f\=(.*)\&.*/) {
	$out = "http://firedrive.dokter-squid.com/$1";

# bing
} elsif ($url =~ m/^http:\/\/.*\.[a-z]+\.bing\.net\/(.*)\&w=.*/) {
	$out = "http://bing.dokter-squid.com/$1";

} elsif ($url =~ m/^https?:\/\/.*\.bing\.(net|com)\/.*\?id=([a-zA-Z]\.[0-9]+)&pid=.*/) {
	$out = "http://bing.dokter-squid.com/$2";

# sourceforge
} elsif ($url =~ m/^https?:\/\/.*\.dl\.sourceforge\.net\/project\/[a-zA-Z]+\/.*\/(.*\.(exe|zip|mp3|mp4))/) {
	$out = "http://sourceforge.dokter-squid.com/$1";

# FILEHIPPO
} elsif ($url =~ m/^https?:\/\/fs[0-9]+\.filehippo\.com\/.*\/.*\/(.*)/) {
	$out = "http://filehippo.dokter-squid.com/$1";

# softpedia
} elsif ($url =~ m/^http:\/\/.*\.softpedia\.(com|ro)\/dl\/.*\/.*\/(.*\.(exe|zip|msi|rar))/) {
	$out = "http://softpedia.dokter-squid.com/$2";

# fosshub
} elsif ($url =~ m/^http:\/\/mirror[0-9]+\.fosshub\.com\/([^\&\s]*\/.*\.(zip|exe|msi|rar|tar.bz2|tar.gz|apk))/) {
	$out = "http://fosshub.dokter-squid.com/$1";

# majorgeeks
} elsif ($url =~ m/^http:\/\/files[0-9]+\.majorgeeks\.com\/.*\/(\w+\/.*\.(exe|msi|zip|rar))/) {
	$out = "http://majorgeeks.dokter-squid.com/$1";

# cnet
} elsif ($url =~ m/^http:\/\/software-files-a\.cnet\.com\/s\/\w+\/(.*\/.*\.(exe|zip|7z|cab|msi|mru|mri|bz2|gzip|tgz|rar|dmg|apk))\?.*$/) {
	$out = "http://cnet.dokter-squid.com/$1";

# turbobit
} elsif ($url =~ m/^http:\/\/.*\.turbobit\.net:[0-9]+\/download\.php\?name=(.*(exe|zip|7z|cab|msi|mru|mri|bz2|gzip|tgz|rar|dmg|apk)).*/) {
	$out = "http://turbobit.dokter-squid.com/$1";

# music-clips
} elsif ($url =~ m/^http:\/\/.*\.music-clips\.net\/\w+\.php\?(id=[^\&\s]*)/) {
	$out = "http://music-clips.dokter-squid.com/$1";

# zippyshare
} elsif ($url =~ m/^http:\/\/.*\.zippyshare\.com\/d\/\d+\/\d+\/(.*\.(zip|rar|exe|msi|iso|mp3|mp4|bz2|gzip|tgz|7z))/) {
	$out = "http://zippyshare.dokter-squid.com/$1";

# sharebeast
} elsif ($url =~ m/^http:\/\/.*\.sharebeast\.com\/d\/.*\/(.*\.(zip|rar|exe|msi|iso|mp3|mp4|bz2|gzip|tgz|7z))/) {
	$out = "http://sharebeast.dokter-squid.com/$1";

# fileswap
} elsif ($url =~ m/^http:\/\/.*\.fileswap\.com\/download\/\?id=([^\&\s]*).*/) {
	$out = "http://fileswap.dokter-squid.com/$1";

# tusfiles
} elsif ($url =~ m/^http:\/\/.*\.tusfiles\.net\/d\/.*\/(.*\.(zip|rar|exe|msi|iso|mp3|mp4|bz2|gzip|tgz|7z))/) {
	$out = "http://tusfiles.dokter-squid.com/$1";

# depositfiles
} elsif ($url =~ m/^http:\/\/.*\.depositfiles.com\/.*\/.*\/(.*\.(zip|rar|exe|msi|iso|mp3|mp4|bz2|gzip|tgz|7z))/) {
	$out = "http://depositfiles.dokter-squid.com/$1";

# solidfilesusercontent
} elsif ($url =~ m/^https?:\/\/.*\.solidfilesusercontent\.com\/(.*\.(zip|rar|exe|msi|iso|mp3|mp4|bz2|gzip|tgz|7z))/) {
	$out = "http://solidfilesusercontent.dokter-squid.com/$1";

# fm flp
} elsif ($url =~ m/^http:\/\/s[0-9]+\.last\.fm\/flp\/(\d+)\/.*/) {
	$out = "http://fm-flp.dokter-squid.com/$1";

# soundcloud & llnwd
} elsif ($url =~ m/^https?:\/\/.*\.(soundcloud.com|llnwd.net)\/(.*\.mp3)\?.*/) {
	$out = "http://llnwd.dokter-squid.com/$2";

} elsif ($url =~ m/^https?:\/\/.*\.soundcloud\.com\/(audio_performance|audio)\?anonymous_id=([^\&\s]*)/) {
	$out = "http://soundcloud.dokter-squid.com/$2";

} elsif ($url =~ m/^http:\/\/.*\.(aclst|vidtomp3|listentoyoutube)\.com\/(download|dl.php)\/.*\/(.*\.mp3)($|\?.*)/) {
	$out = "http://vidtomp3.dokter-squid.com/$3";

} elsif ($url =~ m/^http:\/\/\d+\.\d+\.\d+\.\d+\/result[0-9]+\/.*\/(.*\.mp3)/) {
	$out = "http://download.dokter-squid.com/$1";

} elsif ($url =~ m/^https?:\/\/cf-media\.sndcdn\.com\/(.*\.(mp3|mp4))\?/) {
	$out = "http://sndcdn.dokter-squid.com/$1";

#eset
} elsif ($url=~ m/^http.*(\/v3-eval-sta\/.*\.nup)/) {
	$out = "http://eset.dokter-squid.com/$1";

# MEDIAFIRE
} elsif ($url =~ m/^https?:\/\/download[0-9]+.mediafire\.com\/.*\/\w+\/(.*)/) {
	$out = "http://mediafire.dokter-squid.com/$1";

# ANDROID PLAYSTORE
} elsif ($url =~ m/^https?:\/\/.*\.c\.android\.clients\.google\.com.*\/GetBinary\/(.*)\?.*/) {
	$out = "http://android.dokter-squid.com/$1";

# googlecontent & blogspot img
} elsif ($url =~ m/^http.*\.(blogspot|googleusercontent)\.com\/(\-[^\/]+\/[^\/]+\/[^\/]+.*\.(jpg|png))/) {
	$out = "http://google.dokter-squid.com/$2";

# youku
} elsif ($url =~ m/^http.*\/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/youku\/[^\/]+\/(.*\.flv\?\&.*)/) {
	$out = "http://youku.dokter-squid.com/$1";

# virtualearth images
} elsif ($url =~ m/^http.*\.(tiles\.virtualearth\.net\/.*\?.*\&n=z)/) {
	$out = "http://virtualearth.dokter-squid.com/$1";

# Speedtest
} elsif ($url =~ m/^https?:\/\/.*\/speedtest\/(.*\.(jpg|txt))\?.*/) {
	$out = "http://speedtest.dokter-squid.com/$2";

# AOL VIDEO
} elsif ($url =~ m/^http:\/\/avideos\.5min\.com\/.*\/(.*)\?.*/) {
	$out = "http://5min.dokter-squid.com/$1";

# dailymotion
} elsif ($url =~ m/^http.*\.(dmcdn\.net|dailymotion\.com)\/[^\/]+((\/frag.*|)\/video\/)\d+\/\d+\/(.*\.(flv|mnft|mp4|ts|3gp|m4v))$/) {
	$out = "http://dailymotion.dokter-squid.com/$2$4";

# vimeo
} elsif ($url =~ m/^http.*(vimeo|vimeocdn)\.com\/[^\/]+\/[^\/]+\/(.*\.(flv|mp3|avi|mp4))\?.*/) {
        $out = "http://vimeo.dokter-squid.com/$2";

# photobucket
} elsif ($url =~ m/^https?:\/\/i[1-9]{3,4}(.photobucket.com.*)/) {
	$out = "http://photobucket.dokter-squid.com/$1";

# break
} elsif ($url =~ m/^http.*\.edgecastcdn\.net\/[^\/]+\/[^\/]+\/media\/[^\/]+\/[^\/]+\/[^\/]+\/(.*\.mp4Seg.*)/) {
	$out = "http://break.dokter-squid.com/$1";

# blip.tv
} elsif ($url =~ m/^http:\/\/.*\.video[0-9]\.blip\.tv\/.*\/(.*)\?.*/) {
	$out = "http://blip.dokter-squid.com/$1";

# vidivodo
} elsif ($url =~ m/^http:\/\/ss[0-9]\.vidivodo\.com\/vidivodo\/vidservers\/server[0-9]*\/videos\/.*\/([a-zA-Z0-9.]*)\?.*/) {
	$out = "http://vidivodo.dokter-squid.com/$1";

# imdb
} elsif ($url =~ m/^http:\/\/video\-http\.media\-imdb\.com\/([a-zA-Z0-9\@\_\-]+\.(mp4|flv|m4v))\?.*/) {
	$out = "http://imdb.dokter-squid.com/$1";

# veoh
} elsif ($url =~ m/^http:\/\/fcache\.veoh\.com\/.*\/.*(l[0-9]*\.(mp4|flv))\?.*/) {
        $out = "http://veoh.dokter-squid.com/$1";

# vube
} elsif ($url =~ m/^http:\/\/video\.thestaticvube\.com\/.*\/(.*)/) {
	$out = "http://vube.dokter-squid.com/$1";

# anghami
} elsif ($url =~ m/^http.*\.anghami\.com\/([^\/]+\/|)(.*\.m4a)\?st\=.*e\=.*/) {
	$out = "http://anghami.dokter-squid.com/$2";

# ospserver
} elsif ($url =~ m/^http.*\-dn\.ospserver\.net\/firmware\/[^\/]+\/[^\/]+\/(.*\.bin)\?px\-.*/) {
	$out = "http://ospserver.dokter-squid.com/$1";

# eamaster
} elsif ($url =~ m/^http.*akamai\.cdn\.ea\.com\/eamaster\/[^\/]+\/shift\/[^\/]+\/(.*\.zip)\?.*/) {
	$out = "http://eamaster.dokter-squid.com/$1";

# videobash
} elsif ($url =~ m/^http:\/\/cdn[0-9]\.videos\.videobash\.com\/.*\/(.*\.(mp4|m4v|flv))\?.*/) {
	$out = "http://videobash.dokter-squid.com/$1";

# starhub
} elsif ($url =~ m/^https?:\/\/.*\.(garenanow|starhub)\.com\/[a-z0-9]+\/[a-z0-9]+\/[a-z0-9]+\/(.*\.exe)\?[0-9]/) {
	$out = "http://starhub.dokter-squid.com/$2";

} elsif ($url =~ m/^https?:\/\/.*\.(garenanow|starhub)\.com\/hon\/[a-z0-9]+\/(.*\.exe)\?[0-9]/) {
        $out = "http://starhub.dokter-squid.com/$2";

# KAV
} elsif ($url =~ m/^http:\/\/dnl-[0-9]{2}\.geo\.kaspersky\.com\/(.*)/) {
	$out = "http://kaspersky.dokter-squid.com/$1";

} elsif ($url =~ m/^http:\/\/dnl-[0-9]{2}.(geo.kaspersky.com.*)/) {
	$out = "http://kaspersky.dokter-squid.com/$1";

# microsoft esd
} elsif ($url =~ m/^http.*\.ws\.microsoft\.com\/dl\/content\/.*\/(.*\.esd)\?.*/) {
	$out = "http://microsoft.dokter-squid.com/$1";

# panet.co.il
} elsif ($url =~ m/^http.*\.panet\.co\.il\/vod\/\d+\/\d+\/(.*\.mp4)\?.*/) {
	$out = "http://panet.dokter-squid.com/$1";

# wartune
} elsif ($url =~ m/^http:\/\/.*\.(wartune\.com.*\.[a-z]+)$/) {
	$out = "http://wartune.dokter-squid.com/$1";

} elsif ($url =~ m/^http:\/\/.*\.(wartune\.com.*\?.*)/) {
	$out = "http://wartune.dokter-squid.com/$1";

# animeindo
} elsif ($url =~ m/^http.*\.aisfile\.com\:182\/[^\/]+\/[^\/]+\/(.*\.(flv|mp4)\?.*)/) {
	$out = "http://animeindo.dokter-squid.com/$1";

# INSTAGRAM
} elsif ($url =~ m/^https?\:\/\/videos\-.*\.instagram\.com\/hphotos[^\/]+\/(.*\.mp4)$/) {
	$out = "http://instagram.dokter-squid.com/$1";

} elsif ($url =~ m/^https?\:\/\/photos.*\.instagram\.com\/h?photo[^\/]+\/(.*\.jpg)/) {
    $out = "http://instagram.dokter-squid.com/$1";

# moborobo
} elsif ($url =~ m/^https?\:\/\/[a-z0-9]+\.moborobo\.com\/android\/soft\/.*\/(.*\.apk)/) {
	$out = "http://moborobo.dokter-squid.com/$1";

# PORN SITE

} elsif ($url =~ m/^https?\:\/\/.*\.xvideos\.com\/videos\/([^\/]+)\/.*\/(xvideos\.com\_.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg)(\;.+)?)\?.*/) {
	$out = "http://xvideos.dokter-squid.com/$2";

} elsif ($url =~ m/^https?:\/\/.*\.pornhub(\.phncdn)?\.com\/videos.*\/([^\_]+\_[^\_]+\_.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg))\?.*/) {
	$out = "http://pornhub.dokter-squid.com/$2";

} elsif ($url =~ m/^https?\:\/\/.*\.yjcontentdelivery\.com\/videos\/.*\/([0-9a-zA-Z]+\-.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg))\?.*/) {
	$out = "http://yjcontentdelivery.dokter-squid.com/$1";

} elsif ($url =~ m/^https?\:\/\/.*\.dmcdn\.net\/video\/.*\/([0-9a-zA-Z]+\_.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg))\?.*/) {
	$out = "http://dmcdn.dokter-squid.com/$1";

} elsif ($url =~ m/^https?\:\/\/.*\.rncdn[0-9]+\.com\/videos\/.*\/([0-9a-zA-Z]+\_.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg))\?.*/) {
	$out = "http://rncdn.dokter-squid.com/$1";

} elsif ($url =~ m/^https?\:\/\/.*\.redtubefiles\.com\/\_videos\_.*\/(.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg))\?st\=.*/) {
	$out = "http://redtube.dokter-squid.com/$1";

} elsif ($url =~ m/^https?\:\/\/.*\.y8\.com\/system\/videos\/(.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg))\?.*/) {
	$out = "http://y8.dokter-squid.com/$1";

} elsif ($url =~ m/^https?\:\/\/.*\.cdn[0-9]+\.com\/.*\/(.*\.(flv|mp4|avi|mkv|mp3|rm|rmvb|m4v|mov|wmv|3gp|mpg|mpeg))\?cdn_creation_time\=.*/) {
	$out = "http://cdn.dokter-squid.com/$1";

# blacksquad
} elsif ($url =~ m/^http:\/\/patch\.gemscool\.com\/.*\/(.*\.npz)\?.*/) {
        $out = "http://gemscool.com/$1";

# ANIME
} elsif ($url =~ m/^http.*\.mp4vid\.com:182\/d\/[a-zA-Z0-9]+\/([\S]+\.mp4)\?start=0/) {
	$out = "http://anime.dokter-squid.com/$1";

} elsif ($url =~ m/^http.*\.mp4vid\.com:182\/d\/[a-zA-Z0-9]+\/([\S]+\.mp4)$/) {
	$out = "http://anime.dokter-squid.com/$1";

} else	{
	$out = "ERR";
}
if ($out =~ m/^http:\/\/.*/) {
	print $dsi, "OK store-id=$out\n";
} else {
	print $dsi, "ERR\n";
}
}

# END STORE-ID

