Advertisement
sopyanx

store-id.pl

Mar 23rd, 2014
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.22 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # send link from youtube contain >> (ptracking|stream_204|player_204|gen_204) to store-id
  3.  
  4. $|=1;
  5. while (<>) {
  6. @X = split;
  7.  
  8. if ( $X[0] =~ m/^http\:\/\/.*/) {
  9. $x = $X[0];
  10. $_ = $X[0];
  11. $u = $X[0];
  12. } else {
  13. $x = $X[1];
  14. $_ = $X[1];
  15. $u = $X[1];
  16. }
  17.  
  18. if ($x =~ m/^http(|s)\:\/\/.*youtube.*(ptracking|stream_204|player_204|gen_204).*(video_id|docid|v)\=([^\&\s]*).*/){
  19.         $vid = $4 ;
  20.         @cpn = m/[&?]cpn\=([^\&\s]*)/;
  21.         $fn = "/var/log/squid/@cpn";
  22.         unless (-e $fn) {
  23.         open FH,">".$fn ;
  24.         print FH "$vid\n";
  25.         close FH;
  26.         }
  27.         $out=$x . "\n";
  28.  
  29. } elsif ($x =~ m/^http\:\/\/.*(youtube|google).*videoplayback.*/){
  30.         @itag = m/[&?](itag=[0-9]*)/;
  31.         @ids = m/[&?]id\=([^\&\s]*)/;
  32.         @cpn = m/[&?]cpn\=([^\&\s]*)/;
  33.         $fn = "/var/log/squid/@cpn";
  34.         if (-e $fn) {
  35.         open FH,"<".$fn ;
  36.         $id  = <FH>;
  37.         chomp $id ;
  38.         close FH ;
  39.         } else {
  40.         $id = $ids[0] ;
  41.         }
  42.         @range = m/[&?](range=[^\&\s]*)/;
  43.         $out="http://video-srv.youtube.com.SQUIDINTERNAL/id=" . $id . "&@itag@range";
  44.        
  45. } elsif ($x =~ m/^http\:\/\/.*(profile|photo|creative).*\.ak\.fbcdn\.net\/((h|)(profile|photos)-ak-)(snc|ash|prn)[0-9]?(.*)/) {
  46.         $out="http://fbcdn.net.squid.internal/" . $2  . "fb" .  $6  ;
  47.  
  48. } elsif ($x =~ m/^http:\/\/i[1-4]\.ytimg\.com\/(.*)/) {
  49.         $out="http://ytimg.com.squid.internal/" . $1 ;
  50.  
  51. } elsif ($x =~ m/^http:\/\/.*\.dl\.sourceforge\.net\/(.*)/) {
  52.         $out="http://dl.sourceforge.net.squid.internal/" . $1 ;
  53.  
  54.         #Speedtest
  55. } elsif ($x =~ m/^http\:\/\/.*\/speedtest\/(.*\.(jpg|txt)).*/) {
  56.         $out="http://speedtest.squid.internal/" . $1 ;
  57.        
  58.         #Blogspot
  59. } elsif ($x =~ m/^http:\/\/[1-4]\.bp\.(blogspot\.com.*)/) {
  60.         $out="http://blog-cdn." . $1  ;
  61.  
  62.         #Avast
  63. } elsif ($x =~ m/^http:\/\/download[0-9]{3}.(avast.com.*)/) {
  64.         $out="http://avast-cdn." . $1  ;
  65.  
  66.         #Avast
  67. } elsif ($x =~ m/^http:\/\/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\/(iavs.*)/) {
  68.         $out="http://avast-cdn.avast.com/" . $1  ;
  69.  
  70.         #KAV
  71. } elsif ($x =~ m/^http:\/\/dnl-[0-9]{2}.(geo.kaspersky.com.*)/) {
  72.         $out="http://kav-cdn." . $1  ;
  73.  
  74.         #AVG
  75. } elsif ($x =~ m/^http:\/\/update.avg.com/) {
  76.         $out="http://avg-cdn." . $1  ;
  77.  
  78.         #maps.google.com
  79. } elsif ($x =~ m/^http:\/\/(cbk|mt|khm|mlt|tbn)[0-9]?(.google\.co(m|\.uk|\.id).*)/) {
  80.         $out="http://" . $1  . $2 ;
  81.  
  82.         #gstatic and/or wikimapia
  83. } elsif ($x =~ m/^http:\/\/([a-z])[0-9]?(\.gstatic\.com.*|\.wikimapia\.org.*)/) {
  84.         $out="http://" . $1  . $2 ;
  85.  
  86.         #maps.google.com
  87. } elsif ($x =~ m/^http:\/\/(khm|mt)[0-9]?(.google.com.*)/) {
  88.         $out="http://" . $1  . $2 ;
  89.        
  90.         #Google
  91. } elsif ($x =~ m/^http:\/\/www\.google-analytics\.com\/__utm\.gif\?.*/) {
  92.         $out="http://www.google-analytics.com/__utm.gif\n";
  93.  
  94. } elsif ($x =~ m/^http:\/\/(www\.ziddu\.com.*\.[^\/]{3,4})\/(.*?)/) {
  95.         $out="http://" . $1 ;
  96.  
  97.         #cdn, varialble 1st path
  98. } elsif (($x =~ /filehippo/) && (m/^http:\/\/(.*?)\.(.*?)\/(.*?)\/(.*)\.([a-z0-9]{3,4})(\?.*)?/)) {
  99.         @y = ($1,$2,$4,$5);
  100.         $y[0] =~ s/[a-z0-9]{2,5}/cdn./;
  101.         $out="http://" . $y[0] . $y[1] . "/" . $y[2] . "." . $y[3] ;
  102.  
  103.         #rapidshare
  104. } elsif (($x =~ /rapidshare/) && (m/^http:\/\/(([A-Za-z]+[0-9-.]+)*?)([a-z]*\.[^\/]{3}\/[a-z]*\/[0-9]*)\/(.*?)\/([^\/\?\&]{4,})$/)) {
  105.         $out="http://cdn." . $3 . "/squid.internal/" . $5 ;
  106.  
  107.         #for yimg.com video
  108. } elsif ($x =~ m/^http:\/\/(.*yimg.com)\/\/(.*)\/([^\/\?\&]*\/[^\/\?\&]*\.[^\/\?\&]{3,4})(\?.*)?$/) {
  109.         $out="http://cdn.yimg.com/" . $3 ;
  110.        
  111.         #for yimg.com doubled
  112. } elsif ($x =~ m/^http:\/\/(.*?)\.yimg\.com\/(.*?)\.yimg\.com\/(.*?)\?(.*)/) {
  113.         $out="http://cdn.yimg.com/"  . $3 ;
  114.  
  115.         #for yimg.com with &sig=
  116. } elsif ($x =~ m/^http:\/\/([^\.]*)\.yimg\.com\/(.*)/) {
  117.         @y = ($1,$2);
  118.         $y[0] =~ s/[a-z]+([0-9]+)?/cdn/;
  119.         $y[1] =~ s/&sig=.*//;
  120.         $out="http://" . $y[0] . ".yimg.com/"  . $y[1] ;
  121.        
  122. } else {
  123.         $out=$x;
  124.  
  125. }
  126. if ( $X[0] =~ m/^http\:\/\/.*/) {
  127.  print "OK store-id=$out\n" ;
  128. } else {
  129.  print $X[0] . "OK store-id=$out\n" ;
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement