nuclear@0: #!/bin/sh nuclear@0: # ------------------------------------------------------------------------- nuclear@0: # lsflv - prints a list (and optionally saves copies of) videos currently nuclear@0: # being played by the adobe flash player browser plugin. nuclear@0: # nuclear@0: # Written by John Tsiombikas nuclear@0: # This script is placed in the public domain, do whatever you want with it. nuclear@0: # ------------------------------------------------------------------------- nuclear@0: nuclear@0: mkcopy=no nuclear@0: play=no nuclear@0: player=${PLAYER:-mpv} nuclear@0: bin=`basename $0` nuclear@0: dir=`pwd` nuclear@0: nuclear@0: # if invoked as cpflv always make a copy (as in -c) nuclear@0: if [ "$bin" = cpflv ]; then nuclear@0: mkcopy=yes nuclear@0: fi nuclear@0: nuclear@0: # if invoked as playflv play the video (as in -p) nuclear@0: if [ "$bin" = playflv ]; then nuclear@0: play=yes nuclear@0: fi nuclear@0: nuclear@0: # process arguments nuclear@0: while [ $# -gt 0 ]; do nuclear@0: case "$1" in nuclear@0: -c) nuclear@0: mkcopy=yes nuclear@0: ;; nuclear@0: -p) nuclear@0: play=yes nuclear@0: ;; nuclear@0: -d) nuclear@0: dir=$2 nuclear@0: shift nuclear@0: ;; nuclear@0: -h) nuclear@0: echo "Usage: $bin [options]" nuclear@0: echo "Options:" nuclear@0: echo " -c make copies of the video files" nuclear@0: echo " -d change the directory used to copy the files to (default: cwd)" nuclear@0: echo " -h print usage and exit" nuclear@0: exit 0 nuclear@0: ;; nuclear@0: esac nuclear@0: shift nuclear@0: done nuclear@0: nuclear@0: nuclear@0: list=`lsof | egrep '(/tmp/Flash|/tmp/mozilla-media-cache)' | awk '{ print $2":"$4 }'` nuclear@0: nuclear@0: num=0 nuclear@0: nuclear@0: for i in $list; do nuclear@0: pid=`echo $i | awk -F: '{ print $1 }'` nuclear@0: fd=`echo $i | awk -F: '{ print $2 }' | sed 's/[a-zA-Z]*//g'` nuclear@0: nuclear@0: if [ -n "$fd" ]; then nuclear@0: path="/proc/$pid/fd/$fd" nuclear@0: nuclear@0: num=`echo "$num + 1" | bc` nuclear@0: target="$dir/vid$num" nuclear@0: nuclear@0: if [ $mkcopy = yes ]; then nuclear@0: echo "copy $path -> $target" nuclear@0: if ! cp $path $target; then nuclear@0: echo "failed to copy $path to $target" >&2 nuclear@0: exit 1 nuclear@0: fi nuclear@0: else nuclear@0: echo "$path" nuclear@0: fi nuclear@0: nuclear@0: if [ $play = yes ]; then nuclear@0: $player $path nuclear@0: fi nuclear@0: fi nuclear@0: done