Downloading Videos in Ubuntu

Posted: March 24, 2012 in Technology
Tags: , ,

Till Ubuntu 9.10, getting a copy of the video you see online to your local HDD was quite easy. Just let the video buffer and copy it from /tmp directory. However with the higher releases of Ubuntu, this is no more the case. Though still your videos get buffered in /tmp directory, but as soon as it is buffered, hard link present in /tmp directory is deleted and the only hard link maintained to this file is present in /proc directory under the PID of the flashplugin process running on your system. However there are scripts which can copy your video to some-else directory before the file is deleted.

#!/bin/bash

args=("$@")

args=`echo $args | sed 's/[/]$//'`

pids=`eval pgrep -f flashplayer`
for pid in $pids
do
lsoutput=$(lsof -p $pid | grep '/tmp/Flash[^ ]*')

IFS=$'\n'
for line in $lsoutput; do
lsout1=`echo $line | awk '{print "/proc/" $2 "/fd/" $4}' | sed 's/[rwu]$//'`
lsout2=`echo $line | awk '{print $9}' | awk -F '/' '{print $3}'`

if [ -n "$args" ];then
if [ -d $args ]; then
echo "Copying $lsout2 to $args/"
eval "cp $lsout1 $args/$lsout2.flv"
else
echo "The directory \"$args\" doesn't exist"
break
fi
else
echo "Copying $lsout2"
eval "cp $lsout1 $lsout2.flv"
fi

done
done

Copy the above script to a file video_copy.sh in your home directory. Open the terminal and enter following commands after your video is buffered in browser:

chmod +x video_copy.sh
./video_copy.sh TARGETDIR

where TARGETDIR is the directory where you want to store your buffered video

To download the video from youtube without doing buffering, download script file from https://raw.github.com/rg3/youtube-dl/2011.02.25c/youtube-dl.
Do a “chmod +x youtube-dl”
and run the script as
“./youtube-dl URL_OF_YOUTUBE_VIDEO”

Advertisements
Comments
  1. Mike says:

    Is this still functional? I have a similar script that stopped working in the last few months.

  2. Kapil Jain says:

    Hi Mike,

    Last I used, first one is still functional not sure about the youtube-dl script. However I don’t us either of these now a days but I use the mozilla add-on “netvideo hunter video downloader” which can detect the videos on the web-page and provides you the download link. You can download it using any download manager.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s