2016-09-25

Saving Flash Videos (after the plugin deletes them) (revisited)

I'm not sure if I just made a bunch of errors in my previous post or if things have changed. Either is possible. Anyway, it's now necessary to throw away duplicate file descriptor entries. I don't know if more than one thread has an open handle or what the reason is, but if you're fishing deleted flash videos out of the deleted proc file descriptor, something like the following works better than previously posted. First, the lsof command to see what Shockwave Flash stuff is still open:

lsof | grep 'Shockwave Flash'
But that has duplicates, so lets extract the file descriptor number and throw away dupes (and the row that has no parent pid):

lsof | grep 'Shockwave Flash' |
  awk '{printf "%s %s\n",$2,$5}' |
  sort -u |
  grep -v REG | 
  awk '{printf "%d %d\n",$1,$2}'
That will show the pid and file descriptor of what's probably the flv or mpeg. To turn that into a series of copy commands (make sure the things are done downloading, before doing this, btw...):

lsof | grep 'Shockwave Flash' |
  awk '{printf "%s %s\n",$2,$5}' |
  sort -u |
  grep -v REG |
  awk '{printf "cp /proc/%d/fd/%d /tmp/saved-%d.flv\n",$1,$2,$2}'
And if you're feeling brave, run that through bash...

lsof | grep 'Shockwave Flash' |
  awk '{printf "%s %s\n",$2,$5}' |
  sort -u |
  grep -v REG |
  awk '{printf "cp /proc/%d/fd/%d /tmp/saved-%d.flv\n",$1,$2,$2}' |
  bash
Check them with a file command though, they're probably not flv wrapped anymore, likely they're raw ISO/MPEG. So rename (or adjust the command) accordingly. Oh, and for youtube, just use "youtube-dl" it's pretty awesome.