ujiajah1

try error script for youtube with html5 object

Jan 4th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.15 KB | None | 0 0
  1. # =================================================================================================== #
  2. # ################################ addon script to squid.conf #########################################
  3. # =================================================================================================== #
  4. acl rewriteyoutube url_regex ^https?\:\/\/.*youtube\.com\/watch\?.*
  5. url_rewrite_access allow rewriteyoutube
  6. url_rewrite_program /etc/squid/youtubeplay.pl
  7. url_rewrite_children 32 startup=0 idle=1 concurrency=100
  8. redirector_bypass on
  9.  
  10. acl youtubeplay url_regex ^https?\:\/\/.*youtube\.com\/watch\?.*
  11. cache deny youtubeplay
  12. store_id_access deny youtubeplay
  13.  
  14.  
  15. # =================================================================================================== #
  16. ########################## INPUT SCRIPT touch youtube.pl at squid directory /etc/squid/ ###############
  17. # =================================================================================================== #
  18. # copy script
  19. #!/usr/bin/perl
  20.  
  21. #### var
  22. use IO::File;
  23. $|=1;
  24. STDOUT->autoflush(1);
  25. $debug=1;        ## recommended:0
  26. $bypassallrules=0;    ## recommended:0
  27. $sucks="";        ## unused
  28. $sucks="sucks" if ($debug>=1);
  29. $timenow="";
  30. $printtimenow=1;      ## print timenow: 0|1
  31. my $logfile = '/tmp/urlrewrite.log';
  32.  
  33. open my $logfh, '>>', $logfile
  34.     or die "Couldn't open $logfile for appending: $!\n" if $debug;
  35. $logfh->autoflush(1) if $debug;
  36.  
  37.  
  38. while () {
  39. $timenow=time()." " if ($printtimenow);
  40. #print $logfh "$timenow"."in : $_" if ($debug>=1);
  41. #print $logfh "in : $_" if ($debug>=1);
  42. chop; ## strip eol
  43. my $urlku = $_;
  44. #@X = split;
  45. @X = split(" ",$urlku);
  46. $a = $X[0]; ## chanel
  47. $b = $X[1]; ## url
  48. $c = $X[2]; ## ip
  49. $u = $b; ## url
  50.  
  51. print $logfh "in : $_\n" if ($debug>=1);
  52.  
  53. if ($bypassallrules){
  54.  $out="$u";    ## map 1:1
  55.  
  56. #utmgif
  57. } elsif ($u=~ m/^https?\:\/\/.*youtube\.com\/watch\?.*/) {
  58.     $out="OK rewrite-url=$u&html5=1";
  59.  
  60.  
  61.  
  62.  
  63. } else {
  64. $out="ERR";
  65. }
  66. print $logfh "out: $a $out\n" if ($debug>=1);
  67. print "$a $out\n";
  68. }
  69. close $logfh if ($debug);
  70.  
  71. # =================================================================================================== #
Add Comment
Please, Sign In to add comment