1
0

Update flashget to pluck Google Chrome Flash videos too

This commit is contained in:
Noah 2015-01-11 17:39:08 -08:00
parent ddde05a9c3
commit 198efae2ba

View File

@ -1,49 +1,68 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# flashget - Download Flash videos from any hosting site. # flashget - Download Flash videos from any hosting site.
# Usage: flashget # Usage: flashget [output directory default $HOME]
# Author: Kirsle # Author: Kirsle
# http://sh.kirsle.net/ # http://sh.kirsle.net/
# This script doesn't care what your flash player is called. It just looks for # This script doesn't care what your flash player is called. It just looks for
# any process that owns a /tmp/Flash####### file and copies it. # any process that owns a /tmp/Flash####### file and copies it. It works for
# both the "old style" Netscape Flash plugin (for Firefox and Chromium) and the
# Pepper API style used in Google Chrome.
use strict; use strict;
use warnings; use warnings;
use File::Copy; use File::Copy;
my $home = defined $ENV{HOME} ? $ENV{HOME} : "."; my $home = shift @ARGV || (defined $ENV{HOME} ? $ENV{HOME} : ".");
print "flashget - Searching for Flash videos to rip. For best results, make sure\n" print "flashget - Searching for Flash videos to rip. For best results, make sure\n"
. "you FULLY BUFFER the video first in your web browser.\n\n"; . "you FULLY BUFFER the video first in your web browser.\n\n";
my $count = 0; my $count = 0;
# First, just do a dumb scan of everything in /proc that we have read-access to
# and look for Flash files belonging to either Chrome or the Firefox-style Flash
# plugin. Note that the Chrome Flash plugin locks us out of its file descriptors
# unless we run with root privileges.
opendir (my $proc, "/proc"); opendir (my $proc, "/proc");
foreach my $pid (sort { $a <=> $b } (grep(/^\d+$/, readdir($proc)))) { foreach my $pid (sort { $a <=> $b } (grep(/^\d+$/, readdir($proc)))) {
# Skip PID's we can't read from. # Skip PID's we can't read from.
next unless -r "/proc/$pid/fd"; next unless -r "/proc/$pid/fd";
# Look for flash videos. # Look for flash videos.
my @fd = `ls -l /proc/$pid/fd`; opendir (my $fd, "/proc/$pid/fd");
foreach my $line (@fd) { foreach my $id (sort(grep(!/^\./, readdir($fd)))) {
chomp $line; my $file = "/proc/$pid/fd/$id"; # Make it an abs path.
$line =~ s/[\x0D\x0A]//g; if (-l $file) {
next unless length $line; my $link = readlink($file);
my @parts = split(/\s+/, $line); # Look for a Flash video link.
my $file = $parts[-2]; $link =~ s/\s*\(deleted\)//g; # Remove the " (deleted)" extensions.
my $id = $parts[-4]; if ($link =~ m{^/tmp/(Flash.*?)$} || $link =~ m{Shockwave Flash/\.(.+?)$}) {
# Copy it.
# Looks like Flash? my $dest = "$home/$1.flv";
if ($file =~ m{^/tmp/(Flash.*?)$}) { print "Recover from PID $pid: $id -> $dest\n";
# Copy it. copy($file, $dest) or print "ERR: Couldn't copy to $dest: $@\n";
my $dest = "$home/$1.flv"; $count++;
print "Recover from PID $pid: $id -> $dest\n"; }
copy("/proc/$pid/fd/$id", $dest) or print "ERR: Couldn't copy to $dest: $@\n";
$count++;
} }
} }
closedir($fd);
} }
closedir ($proc); closedir ($proc);
print "\nRecovered $count Flash video(s).\n"; print "\nRecovered $count Flash video(s).\n";
# Do a quick check for Google Chrome Flash processes that we didn't manage to
# get files from, to notify the user that they may want to re-run as root.
if ($> != 0) {
my $ps = `ps aux | grep ppapi | grep -v grep`;
if ($ps) {
print "I found a few Google Chrome Flash plugins running, but I need\n"
. "root permissions to read those files (unless you saw some files\n"
. "named like 'com.google' above). Run this script as root to get\n"
. "Flash videos out of Google Chrome.\n";
print "$ps\n";
}
}