Last active
October 10, 2015 20:38
-
-
Save sequielo/3747458 to your computer and use it in GitHub Desktop.
Copy FLV & MP4 (& other multimedia) files from browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ======================================================================================= | |
# Discoveres all opened FLV files that don't exists on /tmp, and allow to copy to $HOME. | |
# The file must remain open before copying, because the plugin unlinks the filename. | |
# Based on: http://davesource.com/Solutions/20110313.Chrome-linux-hidden-flash-files.html | |
# ======================================================================================= | |
SUDO="sudo " | |
TEMPFILE="/tmp/flvs_$(date +%s)" | |
METHOD=3 | |
if [ $# -eq 1 ] | |
then | |
METHOD=$1 | |
fi | |
case $METHOD in | |
1) | |
$SUDO find /proc |egrep -i "/proc/[0-9]{,5}/fd$" | sed 's/[^0-9]*//g' > $TEMPFILE | |
;; | |
2) | |
$SUDO lsof / | grep -i "flash" > $TEMPFILE | |
;; | |
3) | |
$SUDO lsof -n | grep -i "flash" | grep -v "mem" > $TEMPFILE | |
;; | |
*) | |
echo "Usage: $0 <method-number>" | |
exit 1 | |
;; | |
esac | |
echo " -- Using method #$METHOD" | |
if [ -n "$DEBUG" ] | |
then | |
echo " -- DEBUGGING MODE ON" | |
fi | |
COUNT=$(wc -l $TEMPFILE | awk '{ print $1 }') | |
if [ $COUNT -eq 0 ] | |
then | |
echo " :( nothing detected" | |
exit 1 | |
fi | |
echo " ++ Items: $COUNT" | |
while IFS= read -r ITEM <&3 | |
do | |
PID=$(echo $ITEM | awk '{ print $2 }') | |
FD=$(echo $ITEM | awk '{ gsub(/u$/,"",$4); print $4 }') | |
SIZE=$(echo $ITEM | awk '{ print $7 }') | |
FDPATH="/proc/$PID/fd/$FD" | |
INFO=$($SUDO file -bL "$FDPATH") | |
#MEGAS=$(echo "$SIZE / 2^20" | bc) | |
MEGAS=$($SUDO du -shL "$FDPATH" | awk '{ print $1 }') | |
echo | |
echo " ++ Detected: [FILE=$FDPATH | SIZE=$MEGAS ($SIZE) | INFO=$INFO]" | |
if [ -z "$DEBUG" ] | |
then | |
echo " -- Copy to \$HOME? Enter filename and hit [ENTER]: " | |
read NAME | |
if [ -n "$NAME" ] | |
then | |
OUTPUT="$HOME/$NAME.flv" | |
MYSELF=$(whoami) | |
$SUDO cp "$FDPATH" "$OUTPUT" | |
$SUDO chown "$MYSELF":"$MYSELF" "$OUTPUT" | |
echo " ** Done!" | |
else | |
echo " == Nothing copied" | |
fi | |
fi | |
done 3<$TEMPFILE | |
rm $TEMPFILE | |
echo " == Finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: