Skip to content

Instantly share code, notes, and snippets.

@yasoob

yasoob/common.py Secret

Last active December 28, 2016 04:38
Show Gist options
  • Save yasoob/9f5528b97dd4522b48e4 to your computer and use it in GitHub Desktop.
Save yasoob/9f5528b97dd4522b48e4 to your computer and use it in GitHub Desktop.
Getting the bytes value.
# The code which i am writing underneath is going to be a part of common.py in extractors folder.
# I am simply declaring a new function. If you have something else in mind then do tell me
def get_bytes(self, url):
"""Partially download the final webpage to get the bytes value."""
request = compat_urllib_request.Request(url)
request.get_method = lambda : 'HEAD'
response = compat_urllib_request.urlopen(request)
return response.info().getheader('Content-Length')
# After this in any info extractor we can call it by:
bytes = self.get_bytes(final_url)
# And then in the info dict we can return:
return [{
'id' : video_id,
'url' : final_url,
'ext' : ext,
'title' : title,
'thumbnail': thumbnail_url,
'length' : bytes,
}]
# What do you say ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment