For anyone using Python 3 and looking for a quick solution using the requests
package:
import requests
response = requests.head(
"https://website.com/yourfile.mp4"), # Example file
allow_redirects=True
)
print(response.headers['Content-Length'])
Note: Not all responses will have a Content-Length
so your application will want to check to see if it exists.
if 'Content-Length' in response.headers:
... # Do your stuff here