Hack 79. Easily Download Embedded Movies

 < Day Day Up > 

Add a download link next to movies and Flash animations in web pages.

A little-known feature of Firefox is the Page Info dialog (under the Tools menu). Most people who try it can't get past the first tab, which displays geeky technical details of how the page was served. But if you click over to the Media tab, Firefox displays the URLs of all the multimedia objects on the page: images, QuickTime movies, and Flash animations. You can select the URL of a movie, copy it to the clipboard, and then paste it into a download manager or command-line tool to download it to your local computer.

OK, I guess that's still pretty geeky. Here's a simpler solution: this hack adds a download link next to each inline movie. You can right-click the download link and save the movie to your local computer you know, the way the Web is supposed to work.

9.4.1. The Code

This user script runs on all pages. It uses the document.getElementsByTagName function to find movies embedded in the page with an <embed> tag. Then, it creates a download link that points to the embedded object's source file.

Save the following user script as unembed.user.js:

 // ==UserScript== // @name   Unembed // @namespace   http://neugierig.org/software/greasemonkey // @description   Adds a download link to embedded movies // @include   * // ==/UserScript // based on code by Evan Martin // published here with his gracious permission var arEmbed = document.getElementsByTagName('embed'); for (var i = arEmbed.length - 1; i >= 0; i--) { var elmEmbed = arEmbed[i]; var elmLink = document.createElement('a'); elmLink.href = elmEmbed.src; elmLink.appendChild(document.createTextNode('[download]')); elmEmbed.parentNode.insertBefore(elmLink, elmEmbed.nextSibling); } 

9.4.2. Running the Hack

After installing the user script (Tools Install This User Script), go to http://www.kiku.com/electric_samurai/virtual_mongol/four.html. Next to the embedded QuickTime movie is a link titled "[download]," as shown in Figure 9-5. You can right-click the download link and select Save Link As… to save the movie to your local computer.

Figure 9-5. Link to download embedded movie


The script also works for embedded Flash animations. Go to http://www.markfiore.com/animation.html, Mark Fiore's archive of animated political cartoons. Select a cartoon from the list. Next to the cartoon, you will see a link titled "[download]," as shown in Figure 9-6. As with the embedded QuickTime movie, you can right-click the download link and save the Flash animation to your local computer.

Because of the way some Flash animations work, the .swf file you download might not be complete. This is because a Flash file can be a stub: a small file that loads the rest of the animation from another URL. This second URL is embedded within the binary Flash object itself, so it is not easily accessible from JavaScript.

Figure 9-6. Link to download Flash animation


     < Day Day Up > 


    Greasemonkey Hacks
    Greasemonkey Hacks: Tips & Tools for Remixing the Web with Firefox
    ISBN: 0596101651
    EAN: 2147483647
    Year: 2005
    Pages: 168
    Authors: Mark Pilgrim

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net