2014-02-28 23:42:51 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
# flashget - Download Flash videos from any hosting site.
|
2015-01-12 01:39:08 +00:00
|
|
|
# Usage: flashget [output directory default $HOME]
|
2014-02-28 23:42:51 +00:00
|
|
|
# Author: Kirsle
|
|
|
|
# http://sh.kirsle.net/
|
|
|
|
|
|
|
|
# This script doesn't care what your flash player is called. It just looks for
|
2015-01-12 01:39:08 +00:00
|
|
|
# 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.
|
2014-02-28 23:42:51 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use File::Copy;
|
|
|
|
|
2015-01-12 01:39:08 +00:00
|
|
|
my $home = shift @ARGV || (defined $ENV{HOME} ? $ENV{HOME} : ".");
|
2014-02-28 23:42:51 +00:00
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
my $count = 0;
|
2015-01-12 01:39:08 +00:00
|
|
|
|
|
|
|
# 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.
|
2014-02-28 23:42:51 +00:00
|
|
|
opendir (my $proc, "/proc");
|
|
|
|
foreach my $pid (sort { $a <=> $b } (grep(/^\d+$/, readdir($proc)))) {
|
|
|
|
# Skip PID's we can't read from.
|
|
|
|
next unless -r "/proc/$pid/fd";
|
|
|
|
|
|
|
|
# Look for flash videos.
|
2015-01-12 01:39:08 +00:00
|
|
|
opendir (my $fd, "/proc/$pid/fd");
|
|
|
|
foreach my $id (sort(grep(!/^\./, readdir($fd)))) {
|
|
|
|
my $file = "/proc/$pid/fd/$id"; # Make it an abs path.
|
|
|
|
if (-l $file) {
|
|
|
|
my $link = readlink($file);
|
|
|
|
|
|
|
|
# Look for a Flash video link.
|
|
|
|
$link =~ s/\s*\(deleted\)//g; # Remove the " (deleted)" extensions.
|
2015-06-16 02:23:49 +00:00
|
|
|
if ($link =~ m{^/tmp/((?:Flash|FreshTemp).*?)$} || $link =~ m{Shockwave Flash/\.(.+?)$}) {
|
2015-01-12 01:39:08 +00:00
|
|
|
# Copy it.
|
|
|
|
my $dest = "$home/$1.flv";
|
|
|
|
print "Recover from PID $pid: $id -> $dest\n";
|
|
|
|
copy($file, $dest) or print "ERR: Couldn't copy to $dest: $@\n";
|
|
|
|
$count++;
|
|
|
|
}
|
2014-02-28 23:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-12 01:39:08 +00:00
|
|
|
closedir($fd);
|
2014-02-28 23:42:51 +00:00
|
|
|
}
|
|
|
|
closedir ($proc);
|
|
|
|
|
|
|
|
print "\nRecovered $count Flash video(s).\n";
|
2015-01-12 01:39:08 +00:00
|
|
|
|
|
|
|
# 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";
|
|
|
|
}
|
|
|
|
}
|