Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_metadata(url):
"""Get file download metadata
Returns a (size, type, name) from the given download
URL. Will use the network connection to determine the
metadata via the HTTP header fields.
"""
track_fp = util.urlopen(url)
headers = track_fp.info()
filesize = headers['content-length'] or '0'
filetype = headers['content-type'] or 'application/octet-stream'
if 'last-modified' in headers:
filedate = podcastparser.parse_date(headers['last-modified'])
else:
filedate = None
filename = os.path.basename(os.path.dirname(url))
track_fp.close()
return filesize, filetype, filedate, filename