There was an error in this gadget

+1

Monday, March 21, 2011

How to download Flash Files : No Flash files in /tmp ?

Firstly, we have our facebook page now, you will find a link to like this page in the right column, please like this page and keep yourself updated about new post(s) on Linux on Desktop.


First a disclaimer,it might be illegal to download flash file,it depends upon the website's TOS and I encourage you to go through them before attempting to download flash file, if it is illegal I will NOT recommend that you download flash file.


There are different ways to download flash file, there are plugins that you can install in firefox, there are scripts that allow you to do so, however,one of the better ways that I have used for years( at least more than a year) is copying FlashXXX files from /tmp and renaming them appropriately.

Whenever flash played any media file in the browser, it downloaded Flash file locally in /tmp and deleted it when you closed the page. This had many advantages, for instance if you find something interesting and have already watched it in browser, you do not have to download it again using some plugin, or for instance you could only play part of file by seeking it appropriately and the relevant section is only downloaded in /tmp.

However, I found after updating my system, I no longer had FlashXXX files stored in /tmp , I looked frantically on net to find out reasons for this and found that this has to do with Adobe Flash Player being updated, which no longer saves Files temporarily in /tmp. I further looked up different forums on the Internet and found Flash indeed saved file on the system locally, it was just bit more difficult to access them.

In this post I would try to demonstrate how to retrieve flash files stored locally in the system while it is being played in the web-browser when they are not saved in /tmp. This works with Mozilla Firefox, I haven't tried this with other browsers, though it can work.

One approach to solve this problem would be to downgrade your flash to earlier version, but this is not recommended as updates fix many critical security vulnerabilities and further have performance improvements.

The key to finding flash is the fact that on POSIX based systems, or for instance GNU/Linux all the information about processes running on the system is stored in "/proc" directory were each running process is identified with Process ID and there is a directory corresponding to PID in /proc. Further, all the open File descriptors are maintained here i.e in a lyaman all the information about files opened by process is here.

So if we can find process ID corresponding to the instance of flash player and find the fd corresponding to opened flash file we can easily copy the file and this is the approach that is followed by this script ( I am not the original author of this script) :

Open your favorite text editor and copy the following script, and rename it to something like - findflash.sh

#!/usr/bin/env bash

for flashpid in $(pgrep -f flashplayer.so); do
cd "/proc/$flashpid/fd"
for video in $(file * | grep '/tmp/Flash' | sed 's/\(^[0-9]*\).*/\1/g'); do
echo "/proc/$flashpid/fd/$video"
done
done
Now, open your favorite flash(ensure it is legal to copy) file in web-browser, and in terminal window execute this file by issuing command :

bash findflash.sh
This should print the fd corresponding to all the flash files currently playing, copy them using conventional UNIX command and rename it to meaningful name.

The screen shot below illustrates this -

We had opened a video in Firefox, then we executed findflash.sh script, which gave us file descriptors of opened flash video, we copied and renamed this to some meaningful file name and played it using mplayer.



Article Written by : Ambuj Varshney (blogambuj@gmail.com)
For Linux on Desktop Blog , http://linuxondesktop.blogspot.com
(C) 2011 , Ambuj Varshney

5 comments:

dougz said...

Thanks for the post. You saved me a lot of time researching the issue. Your method worked for me with Chromium 10.0.648.151 under Arch Linux, using the built-in Flash support.

One usage note: use the "cp" command in a terminal rather than trying to copy the file with a file manager. Thunar, at least, can't follow the link to make a copy. However, invoking VLC against the link in Thunar worked fine.

Here's what the link looks like --
[rms@archbang scripts]$ bash findflash.sh
/proc/13078/fd/28
[rms@archbang scripts]$ ls -l /proc/13078/fd/28
lr-x------ 1 rms users 64 Mar 21 17:47 /proc/13078/fd/28 -> /tmp/FlashXXhqthjL (deleted)
[fdz@archbang scripts]$

[No, I,m not rms, but I don't think he would mind!]

Ambuj said...

@dougz : I am glad you liked this post, I have used cp here in the screen shot. thanks for the tip :D

Kath said...

Thanks for this - I will try it. Here's another way: When I couldn't find the flash files in /tmp anymore, I researched and found that the files can be found in your Firefox cache. This is a bit harder to find, and you have to enable "Show Hidden Files" in the "View" menu. I also had to enlarge the cache size - I changed it to about 1000 mb. Then, if you sort the files in the cache by size, the flash files are usually at the end, because they're the largest. Just copy them, or even cut and paste, to the folder you want to keep them in and rename them to something meaningful.

kunlej said...

Great! Debian Squeeze(beta) had the old way /tmp for flash files. However the new Crunchbang (based on debian squeeze stable) is already with new flash player.

I'd just add to your .sh one line before the 'done':

cp "/proc/$flashpid/fd/$video" /tmp

in this way, with a 'single click', all flash instances at a time are copied to /tmp, which I find more flexible to manage afterwards. And you don't need terminal at all for that - just double click on .sh file from let's say desktop.

Thanks a lot
Cheers

voltron said...

thank you so much! Works perfect, but I sure miss the easy way of just copying straight from the tmp folder.

Post a Comment