One would be surprised to know that Google Chrome does not have extensions that support metalink downloads unlike Firefox. It could be attributed to the decreased granularity of control provided by the Chromium Extensions API in comparison with Firefox’s. However, the recent additions to the Chromium extensions API does provide most of the capabilities to support metalinks-based download. So, here is my post on how I developed a chrome extension in a couple of hours.
Let’s start verifying the requirements for a simple metalink downloader.
- Ability to distinguish metalinks from others
- Ability to save contents to a file in the system.
- Ability to parse the metalink file.
Looking at the requirements, it doesn’t look bad enough. Let’s try to handle them one by one. Firstly, ability to parse the metalink file is the easiest as you have DOM and XSLT at your disposal. With respect to saving the downloaded file to the system, luckily I was able to find chrome experimental downloads API. Now the method that could be used here is chrome.experimental.downloads.download. This takes in as parameters the file that needs to be downloaded and the output file name. For a detailed understanding of the various methods that the download API supports, do take a look at http://code.google.com/chrome/extensions/trunk/experimental.downloads.html.
Lastly, differentiating metalinks from other links should be easy considering metalinks have .metalink extension. So, if the extension has access to all the content in the current page, it can filter out the metalinks from other links easily.
Combining these ideas, I developed my first version of metalink downloader chrome extension. It can be seen in action here.
In essence, the extension does the following
- Detect all metalinks in the current tab – filtered based on <a> tag and .metalink extension
- Based on user selections, download the metalink file using XMLHttpRequest
- Parse the response from XHR and get the file to be downloaded and its source.
- Download the file from the most preferred source and save it.
- In case of errors, redownload the file.
Once I developed a basic version, I wanted to add more features suggested by Metalink founder, Anthony Bryan. So, I tried adding the ability to checksum the entire file and check for errors. In case of errors, the file gets re-downloaded from the next preferred mirror. The latest version of the extension can be downloaded from here :http://bit.ly/chrome-metalink-downloader. If you find bugs with the code or have problems adding the extension to the chrome browser, do let me know.
I’ll try to do my best to get back to you.