Permalink
Browse files

[jwzhacks] update youtubedown

  • Loading branch information...
1 parent 918221f commit 46a7127cea353ee7e94fba8f304282f5e15b13a2 @guns committed Sep 13, 2013
Showing with 37 additions and 6 deletions.
  1. +37 −6 bin/youtubedown
View
@@ -45,8 +45,9 @@ use diagnostics;
use strict;
use Socket;
+my $progname0 = $0;
my $progname = $0; $progname =~ s@.*/@@g;
-my $version = q{ $Revision: 1.209 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
+my $version = q{ $Revision: 1.217 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/;
# Without this, [:alnum:] doesn't work on non-ASCII.
use locale;
@@ -591,6 +592,10 @@ my %ciphers = (
'vflZK4ZYR' => 'w19 w68 s1', # 21 Aug 2013
'vflh9ybst' => 'w48 s3 w37 s2', # 21 Aug 2013
'vflapUV9V' => 's2 w53 r w59 r s2 w41 s3', # 27 Aug 2013
+ 'vflg0g8PQ' => 'w36 s3 r s2', # 28 Aug 2013
+ 'vflHOr_nV' => 'w58 r w50 s1 r s1 r w11 s3', # 30 Aug 2013
+ 'vfluy6kdb' => 'r w12 w32 r w34 s3 w35 w42 s2', # 05 Sep 2013
+ 'vflkuzxcs' => 'w22 w43 s3 r s1 w43', # 10 Sep 2013
);
sub decipher_sig($$$) {
@@ -722,13 +727,37 @@ sub guess_cipher(;$$) {
if ($verbose > 1) {
my $c2 = " '$cipher_id' => '$cipher',";
$c2 = sprintf ("%-52s# %s", $c2, $date);
+ auto_update($c2) if ($selftest_p && $selftest_p == 2);
print STDERR "$progname: current cipher is:\n$c2\n";
}
return $cipher;
}
+# Tired of doing this by hand. Crontabbed self-modifying code!
+#
+sub auto_update($) {
+ my ($cipher_line) = @_;
+
+ open (my $in, '<', $progname0) || error ("$progname0: $!");
+ local $/ = undef; # read entire file
+ my ($body) = <$in>;
+ close $in;
+
+ $body =~ s@(\nmy %ciphers = .*?)(\);)@$1$cipher_line\n$2@s ||
+ error ("auto-update: unable to splice");
+
+ open (my $out, '>', $progname0) || error ("$progname0: $!");
+ print $out $body;
+ close $out;
+ print STDERR "$progname: auto-updated $progname0\n";
+
+ my ($dir) = $ENV{HOME} . '/www/hacks';
+ system ("cd '$dir' && cvs -q commit -m 'cipher auto-update' '$progname'");
+}
+
+
# For verifying that decipher_sig() implements exactly the same transformation
# that the JavaScript implementations do.
#
@@ -794,6 +823,7 @@ sub decipher_selftest() {
'3091D200B71AA36948AC517EC7DB161377428B35.' .
'099E8280F1CD26E4F47F5EBED0422C88CAF6AA84',
+ # This one seems to be used by "content restricted" videos?
'vfl_ymO4Z' . "\t" .
'7272B1BA35548BA3939F9CE39C4E72A98BB78ABB28.' . # 86
'560A7424D42FF070C115935232F8BDB8A1F3E05C05C' =>
@@ -1590,6 +1620,8 @@ sub munge_title($) {
# if ($title !~ m/[[:lower:]]/s); # if it's all upper case
+ $title =~ s/ \(\)//gs;
+
# Don't allow the title to begin with "." or it writes a hidden file.
$title =~ s/^([.,\s])/_$1/gs;
@@ -1708,8 +1740,7 @@ sub download_video_url($$$$$$$) {
# "/...#NNNNN" => "/NNNNN"
$url =~ s@^(https?://([a-z]+\.)?vimeo\.com/)[^\d].*\#(\d+)$@$1$3@s;
- # No https.
- $url =~ s@^https:@http:@s;
+ $url =~ s@^https:@http:@s; # No https.
my ($id, $site, $playlist_p);
@@ -1728,7 +1759,7 @@ sub download_video_url($$$$$$$) {
# Youtube /watch?v= or /watch#!v= or /v/ URLs.
} elsif ($url =~ m@^https?:// (?:[a-z]+\.)?
- (youtube) (?:-nocookie)? (?:\.googleapis)? \.com/
+ (youtube) (?:-nocookie)? (?:\.googleapis)? \.com/+
(?: (?: watch )? (?: \? | \#! ) v= |
v/ |
embed/ |
@@ -1741,7 +1772,7 @@ sub download_video_url($$$$$$$) {
# Youtube "/verify_age" URLs.
} elsif ($url =~
- m@^https?://(?:[a-z]+\.)?(youtube) (?:-nocookie)? \.com/
+ m@^https?://(?:[a-z]+\.)?(youtube) (?:-nocookie)? \.com/+
.* next_url=([^&]+)@sx ||
$url =~ m@^https?://(?:[a-z]+\.)?google\.com/
.* service = (youtube)
@@ -2108,7 +2139,7 @@ sub main() {
if ($expect);
if ($guessp) {
- guess_cipher (undef, $guessp > 1);
+ guess_cipher (undef, $guessp - 1);
exit (0);
}

0 comments on commit 46a7127

Please sign in to comment.