shellutils

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lsflv	Thu Apr 23 13:09:47 2015 +0300
     1.3 @@ -0,0 +1,80 @@
     1.4 +#!/bin/sh
     1.5 +# -------------------------------------------------------------------------
     1.6 +# lsflv - prints a list (and optionally saves copies of) videos currently
     1.7 +# being played by the adobe flash player browser plugin.
     1.8 +#
     1.9 +# Written by John Tsiombikas <nuclear@member.fsf.org>
    1.10 +# This script is placed in the public domain, do whatever you want with it.
    1.11 +# -------------------------------------------------------------------------
    1.12 +
    1.13 +mkcopy=no
    1.14 +play=no
    1.15 +player=${PLAYER:-mpv}
    1.16 +bin=`basename $0`
    1.17 +dir=`pwd`
    1.18 +
    1.19 +# if invoked as cpflv always make a copy (as in -c)
    1.20 +if [ "$bin" = cpflv ]; then
    1.21 +	mkcopy=yes
    1.22 +fi
    1.23 +
    1.24 +# if invoked as playflv play the video (as in -p)
    1.25 +if [ "$bin" = playflv ]; then
    1.26 +	play=yes
    1.27 +fi
    1.28 +
    1.29 +# process arguments
    1.30 +while [ $# -gt 0 ]; do
    1.31 +	case "$1" in
    1.32 +	-c)
    1.33 +		mkcopy=yes
    1.34 +		;;
    1.35 +	-p)
    1.36 +		play=yes
    1.37 +		;;
    1.38 +	-d)
    1.39 +		dir=$2
    1.40 +		shift
    1.41 +		;;
    1.42 +	-h)
    1.43 +		echo "Usage: $bin [options]"
    1.44 +		echo "Options:"
    1.45 +		echo "  -c        make copies of the video files"
    1.46 +		echo "  -d <dir>  change the directory used to copy the files to (default: cwd)"
    1.47 +		echo "  -h        print usage and exit"
    1.48 +		exit 0
    1.49 +		;;
    1.50 +	esac
    1.51 +	shift
    1.52 +done
    1.53 +	
    1.54 +
    1.55 +list=`lsof | egrep '(/tmp/Flash|/tmp/mozilla-media-cache)' | awk '{ print $2":"$4 }'`
    1.56 +
    1.57 +num=0
    1.58 +
    1.59 +for i in $list; do
    1.60 +	pid=`echo $i | awk -F: '{ print $1 }'`
    1.61 +	fd=`echo $i | awk -F: '{ print $2 }' | sed 's/[a-zA-Z]*//g'`
    1.62 +
    1.63 +	if [ -n "$fd" ]; then
    1.64 +		path="/proc/$pid/fd/$fd"
    1.65 +
    1.66 +		num=`echo "$num + 1" | bc`
    1.67 +		target="$dir/vid$num"
    1.68 +
    1.69 +		if [ $mkcopy = yes ]; then
    1.70 +			echo "copy $path -> $target"
    1.71 +			if ! cp $path $target; then
    1.72 +				echo "failed to copy $path to $target" >&2
    1.73 +				exit 1
    1.74 +			fi
    1.75 +		else
    1.76 +			echo "$path"
    1.77 +		fi
    1.78 +
    1.79 +		if [ $play = yes ]; then
    1.80 +			$player $path
    1.81 +		fi
    1.82 +	fi
    1.83 +done