The easiest way to download Youtube videos in Linux :)
Have you ever wondered to write an application to download a youtube video in linux ?? If you are too geeky , u can do something so complex like , use awk ( which is string processor ) to download you tube videos ( refer this ) . But i am in no position to learn awk just to download youtube videos.So i happened to get to my /tmp folder and realised that a cp command would do the job
Lemme first point out that this method would work for any video that you can watch on your firefox browser ( or any other browser for that matter ) .
All i am gonna do is use a cp command to download youtube videos. Some times things are so simple in Linux you see.
Say you are watching a youtube video in firefox and want to download , you need to do the following .( Donot close the page that hosts the video )
1. Let the video to load completely .
2. Once the video gets loaded completely, open your terminal and do the following :
a=`ls /tmp/Flash*` && cp $a ~/Desktop/1.flv
Voila !!! Thats it .. you are done.. You would find the video in your desktop . Basically when your browser plays the video , it maintains a temporary copy of it in /tmp folder with a name Flash followed by some string . So in case you wanna download , all you have to do is , before closing the site from which you are viewing the video , copy it on to your hard disk
. So simple isnt it ??
In case you have more than one video files in the tmp directory , do the following
for i in `ls /tmp/Flash*`
do
cp $i ~/Desktop/$(basename $i).flv
done
And tht should copy all Flash video files into your desktop.
Leave any simpler ways to do if so in the comments
. Also if the above method fails in any case…
Tuxventure – Online Linux Event at Pragyan 2009
Writing about this takes me back to a year ago when i made my second post about Pengufest at Pragyan 2008
. I was then new to Linux and now looking back , its all nostalgic
.
Tuxventure is an online Linux event , that me and couple of my friends thought of having it for this edition of pragyan. We initially thought of making the event on-site , but owing to technical difficulties , we made the whole thing online. The prelims will be held on February 1st and the Final is to be held on Feb 8th . The prelims will be of MCQ s to test Linux fundamentals and the finals will concentrate on design and shellscripting . So i am hoping to see a great couple of days ahead. Not to forget the days i spent preparing the questions. I hope the participants enjoy the questions
. It was a great venture for me to sit with hari and prepare the ques
And to add to the awesomeness i had an awesome poster designed by eskay for the event .

If you havent yet registered for the prelims do so before Jan 31st. The prelims can be taken any time on Feb 1st .
Site : http://www.pragyan.org/09/home/events/encipher/tux_venture/
Using mencoder to convert Videos in Linux
Have you ever wondered bothering to check on why windows has so many video converters ( of course the pirated ones
) . If you have gone to that extent , you would have realised that the backend for almost all of them is a command line utility called “mencoder”(Its not “men”coder
. Its “m”-encoder
) . There is actually lots to tell about this mencoder . There is also command line player called mplayer which is the counter part of the encoding utility mencoder . mplayer can play all your music in command line and it has support for managing playlist and everything .
To remind you, mencoder was realeased under the GNU GPL and hence as you would expect , there should me more utilities based on mencoder on Linux than Windows. But sadly i exhausted all my resources to finding a suitable GUI for video conversion in Linux . All that i found were small ones that could not handle the full capacity of mencoder. And so was i fed up with this searching process and started to realise why i hadnt tried using mencoder from CLI. I had earlier used mplayer in some occasions . I had this movie which was in VOB format and i wanted to convert it to avi format to reduce the space . I couldnt find any useful repo for video conversion . (If any good ones please let me know ) .
Usually anything you use on Linux is well documented and i would go for the man pages. But i actually cursed myself for typing “man mencoder”. This mecnoder is “WELL” documented that there are 6287 lines of documentation . And thats when i realised the actual power of mencoder . You can almost do anything with a video or audio using mencoder . I could find options for mirroring , rotating the screen and almost conversion from any format to anyother format. But the catch was you will have to do this all in CLI .
So i sat down , scanned through the man pages and foung my exact options for converting from VOB to avi . I would suggest you do this before trying out mencoder .
man -t mencoder > mencoder.ps && ps2pdf mencoder.ps .
This should get you the man pages of mencoder and mplayer in pdf file so that you can read it comfortably .
I cant going into details of mencoder usage because its so big to explain and I havent tried out even 1% of its full options. I am posting below two screen shots of the conversion process .
I executed the following command to convert from VOB to avi .
mencoder ./Mahanadhi/VTS_1.VOB -o ./Mahanadhi/1.avi -of avi -oac copy lavc -lavcopts vcodec=mpeg4Below you can see a screenshot of the conversion process
.

Using “at” command to schedule jobs in Linux
Everything has a strong motivation behind it and the reason i am writing on this is because it made downloading from torrents easy for me during the off-charge hours. I usually had to stay awake till 2 am in the morning and put it for download and then have to get up again at morning 8 to switch it off.I was too lazy to do something and at came to my rescue.And last month i usually dont get up by 8 in the morning and i used to overshoot my 1.5GB download limit.
You can always do the following using cron, but again at has its own speciality. While in case of cron , the job runs at the scheduled frame of time on everyday , at can be used to schedule jobs which dont happen regularly. Like my case, i didnt want to download everyday so had to put the download only whn i am at home
.
So at command works like this
sathya@Phoenix:~$ at 11:30AMwarning: commands will be executed using /bin/shat> echo "I was executed at 11:30AM" > ~/Desktop/tempat> <EOT>job 30 at Sun Jan 18 11:30:00 2009sathya@Phoenix:~$
All the above command does is ,it prints the line “”I was executed at 11:30AM” at 11:30 AM . Since the command is run with a shell of its own, to see any sort of output displayed to the stdout , i redirect it to a file of my choice (~/Desktop/temp).There are many ways to specify the time for the at command . For a complete list on the date day , time formats chk /usr/share/doc/at-3.1.8/timespec which contains the exact definition of the time specifications.
You can now do a simple cat ~/Desktop/temp to read the output after 11:30 AM
.
Now coming to options for at .
Use atq to know the current jobs in queue. Jobs that are running have a status as” =” and jobs to be scheduled have a status “a” .The displayed output is the format <job-id> <Time > <jobstatus> <user>. Each scheduled job has a unique ID usually numbered from 0
sathya@sathya@Phoenix:~$ atq 30 Sun Jan 18 11:30:00 2009 a sathya sathya@Phoenix:~$ Phoenix:~$
To know the command to be executed corresponding to a job id , use the following option of at -c <job-ID> . This displays all the details for the job including the variables used for the shell to be invoked for this job . And hence wht u see mostlty would be junk except for the last line which has the command to be executed. So use a tail option to read tht one alone.
sathya@Phoenix:~$ at -c 30 | tail -2 echo "I was executed at 11:30AM" > ~/Desktop/temp sathya@Phoenix:~$
To delete a job use atrm <job-ID> .
Now for ex ,sathya@Phoenix:~$ at 11:58AM warning: commands will be executed using /bin/sh at> gnome-terminal at> <EOT> job 31 at Sun Jan 18 11:58:00 2009 sathya@Phoenix:~$
The above command as expected is supposed to open a terminal for u at 11:58 . But it doesnt . Because at by default does only console applications. To make GUI apps , all u need to do is a small modification ( thanks to akhil for pointing this out ).
sathya@Phoenix:~$ at 11:59AM warning: commands will be executed using /bin/sh at> DISPLAY=:0 gnome-terminal at> <EOT>job 32 at Sun Jan 18 11:59:00 2009 sathya@Phoenix:~$
At command reads usually the commands from stdin but using the -f option allows us to read from a file.All variables except the $DISPLAY and $TERM are retained from the time the command was put into queue. All these variables and their associated values can be viewed using at -c <job-ID>.In case of using non console applications , u need to specify the $DISPLAY manually as shown above .
Ok so the final thing i ll be doing to start my “transmission bit torrent” at 2.00 am and stop it at 8.00 am is the following
sathya@Phoenix:~$ at 2.00AM warning: commands will be executed using /bin/sh at> DISPLAY=:0 transmission at> <EOT> job 35 at Mon Jan 19 02:00:00 2009 sathya@Phoenix:~$ at 8.00AM warning: commands will be executed using /bin/sh at> killall -r transmission at> <EOT> job 36 at Mon Jan 19 08:00:00 2009 sathya@Phoenix:~$
This solves the job of taking care of my downloads.And for a GUI version of this, use Ktimer. But u will have to kill yourself if u r gonna use it after having something cool “at” you
. Any suggestions or improvements or new approaches can be put in comments
My Microsoft interns interview questions
Thought it wub be useful if i put it down here. There was only one panel. No HR
. The questions were easy .
Before he started the questions, he discussed my written paper. I had made a mistake in the complexity of one of the problem and he asked me to explain and then he went on to ask questions. First one seemed really stupid. When i was asked this question i was wondering what the interviewer had in mind. So here goes the question ” Given an array A of n unique elements from X to X+n , sort them ” . I told him the most obvious O(n) soln of putting the (X+i)th number at the position i . But he asked for some other better solution . This is where i began to doubt if i was making a mistake in understanding the problem. This couldnt be done less than O(n) . So i told the same solution in a diff way .. I said start from i=0 and put the value of a[i] at a[i]-X and put the value of a[a[i]-X] at the corresponding postion and keep doing the same. He was satisfied with this solution though both were same .
The second question was better.Given a cycle of n nodes. Each node has a money Bi and each edge of the cycle has a cost Ci.Now whn i am at a node, i acquire the money at the node and if i have to move to the next node in the cycle , i have to pay a cost corresponding to tht edge. Now the cycle is unidirectional and we define a trip as starting from a node and coming back to it. After explaining this question , he asked me to asnwer for the following.
1. Give a necessary and sufficient condition for a trip to exist.
2. Given 1, give an algorithm to find the start node.
I took some time .. Figured out the necessary and sufficient condition and gave first the brute force O(n²) . And i told him i need some more time to think of better solution. And then i made some reductions and converted it another porblem with linear array and gave a O(n) solution . He then asked me to write a prog for the same. And was looking happy and was thinking for abt 5 mins about my solution and noted down something in his laptop.
The third question was again simple one. He asked me to write a cpp program to insert into a sorted double linked list. I happily gave the code and came out. All those guys who went in after me had come out long ago and were queued up for second round. Most of them were asked some linked list operation or string operations like reversing , concatination. And in the end me and nr, who again was interviewed for some one hour , were sent off telling there were no second round for us. I could see that they were running out of time .
New Year at Theoretical Comp-Sci Lab
2008 ended with a bang for me . With results declared on new year eve , i was delighted to see a 9.64 GPA with all the efforts i put in ( refer this ) .Lots of guys were actually not happy with results coming out on new year eve .The next thing i was happy was succesfully downloading the Ubuntu 8.10 repository using deb mirror from the IIT M Mirror . I had downloaded some 24.8 GB of data in some 2 hours . I am planning to set up the repository back at coll so that we have a local mirror (seperate post on using debmirror coming up ) . With this the new year eve ended on a high and i had made some working solutions for the research problem at hand. It was a overwhleming farewell gift of 2008
.



2009 had a great beginning too.It was much of a surprise . After wishing everybody a happy new year , i was off to lab . I hadnt been doing much of work this winter , so i thought of not wasting the new year day. Also there was supposed to be a class on randomised algorithms by Prof C. Pandurangan which i didnt want to miss . So I reached lab around 10 in the morning . And then I discussed my solution for Private Matching with Prof and Phd students and finally i had some meaningful outcome for my brief winter stay at Theoretical Comp Sci Lab ( i think i have been to lab only for some 10 days in total ).So I finally got a green signal to write my kutti results and i should soon be sending it for a journal publication soon
. Hope it goes on well . I was exited with the new year beginning on a good note .

More fun came when the guys here at lab decided to cut a cake and celebrate new year. So they got 2 cakes ( eggless becos prof is strictly vegetarian) , some snacks and two big bottles of Cool Drinks to lab and soon prof joined us for the celebrations , giving his wishes .We put the camera to a good use and also took pics group wise ( perfect security , provable security , graph theory , game theory ) with professor. It was all fun. The atmosphere was unbeleivable .Something i cant get back in my coll and i enjoyed it completely here . Suddenly people started asking prof for his birthday treat. The guys here actually celebrate 4 birthdays of prof . One his actual birthday , his star birthday , the one in his pass port, and the one in his official records
. And apart from this they also celebrate all transitive closure events of each other’s birthday
. (Looks like its more fun doing research
) .
Soon we were headed to Cafe Coffee Day (yeah CCD
) here, with prof and we were around 20 people . Formed a big circle over there in CCD and the rest is all wht usually happens in any treat
. After the treat we again took pics . In all it was a memorable new year . It was followed by a lecture on Randomised algorithms ( which i am planning to blog on soon ) . No one who sits in Pandurangan sir’s class leaves without getting inspired by the subject that he takes. And so was I.
In all this new year was entirely opposite previous one. On the eve of the 2008 new year , me and my dad met with an accident and we were in CMC Hospital . My dad had a minor fracture in his right shoulder and we came back home only on Jan 1st morning after spending the whole night at hospital .So i am really thrilled with this new year beginning on a high .
Mirroring the Linux Repositories for Ubuntu
I wanted to mirror the ubuntu repositories back in my coll . So i needed to download the required packages for Intrepid Ibex . Ususally the download would take place in NIT Trichy itself but this time because of frequent power cuts , we were not able to run debmirror . Debmirror is a perl script that helps us in downloading the packages for specifc distribution. Debmirror runs a script so a powerfailure would actually stop the download . But say u lost ur internet connection in between , it restore automatically if the script is still running .
Earlier I had planned to get the repos from Hari who said he would get it from his office . But recently i found that the repos he gave was missing the multiverse components in it . So it was missing quite a lot of packages ( about 3 GB) . I couldnt run a wget because this multiverse component had to be inserted into lots of places and had to be gathered from a large pool selectively . So ftp falied me too since i couldnt select the packages for the 8.10 distro alone.
Suren suggested apt-mirror and i had some issues with it and again it failed miserably. And then i did some calculations and thought why not download the whole repository again . According to my calc , it should take me about 7 hours from the local site at IIT M. So Hari guided me on debmirror and after few intial glitches i managed to download the complete repository and i was amazed at the speed of download . It was close to 3Mbps ( Look at screen shot below) . The entire download took just 2 hours and i was all ready . I had to ignore verifying the gpg key of the packages while downloading since that was again causing some problems . I am giving the screen shots below ..and i am also including the script for debmirror .
#!/bin/bash
export GNUPGHOME=/home/mirrorkeyring
arch=i386section=main,restricted,universe,multiverse
release=intrepid,intrepid-security,intrepid-updates
# this was the local iitm mirror behind my proxy
server=10.65.0.42inPath=/ubuntu
# u can use an ftp too if u want
proto=http# this is the place where u need the repos to be stored whn downlaoded
outPath=/media/Sathya-Maxtor/temp# Start script
# i added –ignore-release-gpg to skip the key verification
debmirror -a $arch \
–no-source \
-s $section \
-h $server \
-d $release \
-r $inPath \
–progress \
-e $proto \
–ignore-release-gpg \
$outPath#### End script to automate building of Ubuntu mirror ####
And here is the screen shot of my terminal after the download

if u dont have debmirror run sudo apt-get install debmirror . I had to change my sources.list to point to 10.65.0.42 to download the debmirror and then use it to download the repos from 10.65.0.42. U can do it as per ur requirement. But downloading from internet is gonna take quite few days