Dienstag, 11. Dezember 2012

[Bash] Play Flash-video with mplayer

Just a little script I made to play flash-videos from Firefox using mplayer.
Some flash-player put the video at
/proc/$pid/fd/$filedescriptor
That one can be played with using e.g. mplayer or vlc.
The script tries to find the right $pid and $fd and plays it.



Here it is:
http://paste.kde.org/623894/ )
#!/bin/sh
pid=`pgrep -f flashplayer.so`
echo "$pid"
for p in $pid
do
    echo "ls -l1 /proc/$p/fd/ | grep deleted"
    deles=`ls -l1 /proc/$p/fd/ | grep deleted`
    echo "deles: $deles"
    wcDeles=`echo $deles | wc -w`
    wlDeles=`ls -l1 /proc/$p/fd/ | grep -c deleted`
    echo "WC: $wcDeles"
    echo "WL: $wlDeles"

    wPerLine=`expr $wcDeles / $wlDeles`
    echo $wPerLine
    offset=3
    i=1
    dval=""
    for d in $deles
    do
        dval=$d
        for numLine in `seq 1 $wlDeles`
        do
            pos=`expr $wPerLine \* $numLine - $offset`
            #echo "expr $wPerLine \* $numLine - $offset"
            #echo "P: $pos"
            if [ $i -eq $pos ]
            then
                #echo "V: $dval"
                echo "playing /proc/$pid/fd/$dval"
                mplayer /proc/$pid/fd/$dval
            fi
        done
        i=`expr $i + 1`
    done
done