def upload_video(self, media, media_type, media_category=None, size=None, check_progress=False):
upload_url = '<STR_LIT>'<EOL>if not size:<EOL><INDENT>media.seek(<NUM_LIT:0>, os.SEEK_END)<EOL>size = media.tell()<EOL>media.seek(<NUM_LIT:0>)<EOL><DEDENT>params = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': media_type,<EOL>'<STR_LIT>': size,<EOL>'<STR_LIT>': media_category<EOL>}<EOL>response_init = self.post(upload_url, params=params)<EOL>media_id = response_init['<STR_LIT>']<EOL>segment_index = <NUM_LIT:0><EOL>while True:<EOL><INDENT>data = media.read(<NUM_LIT:1>*<NUM_LIT>*<NUM_LIT>)<EOL>if not data:<EOL><INDENT>break<EOL><DEDENT>media_chunk = BytesIO()<EOL>media_chunk.write(data)<EOL>media_chunk.seek(<NUM_LIT:0>)<EOL>params = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': media_id,<EOL>'<STR_LIT>': segment_index,<EOL>'<STR_LIT>': media_chunk,<EOL>}<EOL>self.post(upload_url, params=params)<EOL>segment_index += <NUM_LIT:1><EOL><DEDENT>params = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': media_id<EOL>}<EOL>response = self.post(upload_url, params=params)<EOL>if check_progress:<EOL><INDENT>params = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': media_id<EOL>}<EOL>try:<EOL><INDENT>processing_state = response.get('<STR_LIT>').get('<STR_LIT:state>')<EOL><DEDENT>except AttributeError:<EOL><INDENT>return response<EOL><DEDENT>if processing_state:<EOL><INDENT>while (processing_state == '<STR_LIT>' or processing_state == '<STR_LIT>') :<EOL><INDENT>check_after_secs = response.get('<STR_LIT>').get('<STR_LIT>')<EOL>if check_after_secs:<EOL><INDENT>sleep(check_after_secs)<EOL>response = self.get(upload_url, params=params)<EOL>processing_state = response.get('<STR_LIT>').get('<STR_LIT:state>')<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return response<EOL>
Uploads video file to Twitter servers in chunks. The file will be available to be attached
        to a status for 60 minutes. To attach to a update, pass a list of returned media ids
        to the :meth:`update_status` method using the ``media_ids`` param.

        Upload happens in 3 stages:
        - INIT call with size of media to be uploaded(in bytes). If this is more than 15mb, twitter will return error.
        - APPEND calls each with media chunk. This returns a 204(No Content) if chunk is received.
        - FINALIZE call to complete media upload. This returns media_id to be used with status update.

        Twitter media upload api expects each chunk to be not more than 5mb. We are sending chunk of 1mb each.

        Docs:
        https://developer.twitter.com/en/docs/media/upload-media/uploading-media/chunked-media-upload