Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. video/x-flv
  2.  
  3. #!/usr/bin/python
  4. import urllib2
  5. import mimetypes
  6. import sys
  7.  
  8. if len(sys.argv) != 2:
  9. print 'Usage: getUrl url'
  10. sys.exit()
  11.  
  12.  
  13. #Build the file name
  14. mimetypes.init()
  15. url = sys.argv[1]
  16. inv_types_map = {v: k for k, v in mimetypes.types_map.items()}
  17. u = urllib2.urlopen(url)
  18. content_type = u.info().getheaders("Content-Type")[0].split(';')[0]
  19. file_type = inv_types_map[content_type]
  20. file_name = url.split('/')[-1] + file_type
  21.  
  22. #Download the file
  23. f = open(file_name, 'wb')
  24. block_sz = 8192
  25. while True:
  26. buffer = u.read(block_sz)
  27. if not buffer:
  28. break
  29. f.write(buffer)
  30. f.close()
  31. print file_name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement