I used this for the extension given a URL

For more information you can see this page
http://docs.python.org/2/library/mimetypes.html#mimetypes.guess_type