-
-
Save yasoob/9f5528b97dd4522b48e4 to your computer and use it in GitHub Desktop.
Getting the bytes value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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