shellutils

view lsflv @ 0:80fc0c4b11c0

collection of shell scripts
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Apr 2015 13:09:47 +0300
parents
children
line source
1 #!/bin/sh
2 # -------------------------------------------------------------------------
3 # lsflv - prints a list (and optionally saves copies of) videos currently
4 # being played by the adobe flash player browser plugin.
5 #
6 # Written by John Tsiombikas <nuclear@member.fsf.org>
7 # This script is placed in the public domain, do whatever you want with it.
8 # -------------------------------------------------------------------------
10 mkcopy=no
11 play=no
12 player=${PLAYER:-mpv}
13 bin=`basename $0`
14 dir=`pwd`
16 # if invoked as cpflv always make a copy (as in -c)
17 if [ "$bin" = cpflv ]; then
18 mkcopy=yes
19 fi
21 # if invoked as playflv play the video (as in -p)
22 if [ "$bin" = playflv ]; then
23 play=yes
24 fi
26 # process arguments
27 while [ $# -gt 0 ]; do
28 case "$1" in
29 -c)
30 mkcopy=yes
31 ;;
32 -p)
33 play=yes
34 ;;
35 -d)
36 dir=$2
37 shift
38 ;;
39 -h)
40 echo "Usage: $bin [options]"
41 echo "Options:"
42 echo " -c make copies of the video files"
43 echo " -d <dir> change the directory used to copy the files to (default: cwd)"
44 echo " -h print usage and exit"
45 exit 0
46 ;;
47 esac
48 shift
49 done
52 list=`lsof | egrep '(/tmp/Flash|/tmp/mozilla-media-cache)' | awk '{ print $2":"$4 }'`
54 num=0
56 for i in $list; do
57 pid=`echo $i | awk -F: '{ print $1 }'`
58 fd=`echo $i | awk -F: '{ print $2 }' | sed 's/[a-zA-Z]*//g'`
60 if [ -n "$fd" ]; then
61 path="/proc/$pid/fd/$fd"
63 num=`echo "$num + 1" | bc`
64 target="$dir/vid$num"
66 if [ $mkcopy = yes ]; then
67 echo "copy $path -> $target"
68 if ! cp $path $target; then
69 echo "failed to copy $path to $target" >&2
70 exit 1
71 fi
72 else
73 echo "$path"
74 fi
76 if [ $play = yes ]; then
77 $player $path
78 fi
79 fi
80 done