My old shell scripts that have been retired from my dotfiles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.3 KiB

  1. #!/usr/bin/perl -w
  2. # flashget - Download Flash videos from any hosting site.
  3. # Usage: flashget [output directory default $HOME]
  4. # Author: Kirsle
  5. # http://sh.kirsle.net/
  6. # This script doesn't care what your flash player is called. It just looks for
  7. # any process that owns a /tmp/Flash####### file and copies it. It works for
  8. # both the "old style" Netscape Flash plugin (for Firefox and Chromium) and the
  9. # Pepper API style used in Google Chrome.
  10. use strict;
  11. use warnings;
  12. use File::Copy;
  13. my $home = shift @ARGV || (defined $ENV{HOME} ? $ENV{HOME} : ".");
  14. print "flashget - Searching for Flash videos to rip. For best results, make sure\n"
  15. . "you FULLY BUFFER the video first in your web browser.\n\n";
  16. my $count = 0;
  17. # First, just do a dumb scan of everything in /proc that we have read-access to
  18. # and look for Flash files belonging to either Chrome or the Firefox-style Flash
  19. # plugin. Note that the Chrome Flash plugin locks us out of its file descriptors
  20. # unless we run with root privileges.
  21. opendir (my $proc, "/proc");
  22. foreach my $pid (sort { $a <=> $b } (grep(/^\d+$/, readdir($proc)))) {
  23. # Skip PID's we can't read from.
  24. next unless -r "/proc/$pid/fd";
  25. # Look for flash videos.
  26. opendir (my $fd, "/proc/$pid/fd");
  27. foreach my $id (sort(grep(!/^\./, readdir($fd)))) {
  28. my $file = "/proc/$pid/fd/$id"; # Make it an abs path.
  29. if (-l $file) {
  30. my $link = readlink($file);
  31. # Look for a Flash video link.
  32. $link =~ s/\s*\(deleted\)//g; # Remove the " (deleted)" extensions.
  33. if ($link =~ m{^/tmp/((?:Flash|FreshTemp).*?)$} || $link =~ m{Shockwave Flash/\.(.+?)$}) {
  34. # Copy it.
  35. my $dest = "$home/$1.flv";
  36. print "Recover from PID $pid: $id -> $dest\n";
  37. copy($file, $dest) or print "ERR: Couldn't copy to $dest: $@\n";
  38. $count++;
  39. }
  40. }
  41. }
  42. closedir($fd);
  43. }
  44. closedir ($proc);
  45. print "\nRecovered $count Flash video(s).\n";
  46. # Do a quick check for Google Chrome Flash processes that we didn't manage to
  47. # get files from, to notify the user that they may want to re-run as root.
  48. if ($> != 0) {
  49. my $ps = `ps aux | grep ppapi | grep -v grep`;
  50. if ($ps) {
  51. print "I found a few Google Chrome Flash plugins running, but I need\n"
  52. . "root permissions to read those files (unless you saw some files\n"
  53. . "named like 'com.google' above). Run this script as root to get\n"
  54. . "Flash videos out of Google Chrome.\n";
  55. print "$ps\n";
  56. }
  57. }