Add ability to resume file downloading - #18
Conversation
| with self.http.post( | ||
| url=self.kinescope_video.get_clearkey_license_url(), | ||
| headers={'origin': KINESCOPE_BASE_URL}, | ||
| json={ | ||
| 'kids': [ | ||
| b64encode(bytes.fromhex( | ||
| self.mpd_master | ||
| .periods[0] | ||
| .adaptation_sets[0] | ||
| .content_protections[0] | ||
| .cenc_default_kid.replace('-', '') | ||
| )).decode().replace('=', '') | ||
| ], | ||
| 'type': 'temporary' | ||
| } | ||
| ) as post: | ||
| return b64decode(post.json()['keys'][0]['k'] + '==' | ||
| ).hex() if self.mpd_master.periods[0].adaptation_sets[0].content_protections else None |
There was a problem hiding this comment.
Looks pretty complicated, what do you think about splitting this inline into parts?
| segment_url: str, | ||
| file): | ||
| for _ in range(5): | ||
| print("segment_url: {segment_url}, file: {file}".format(segment_url = segment_url, file = file)) |
There was a problem hiding this comment.
Foramat is not recommended for use. I would suggest you to use f-string or redo the logging system at the root :)
| except ChunkedEncodingError: | ||
| pass | ||
| except ChunkedEncodingError as e: | ||
| print("Error! bytes_readed %s, bytes_remained %s" % (bytes_readed, bytes_to_read)) |
There was a problem hiding this comment.
You use different approaches to formatting, why?
| print("segment_url: {segment_url}, file: {file}".format(segment_url = segment_url, file = file)) | ||
| bytes_to_read = 0 | ||
| bytes_readed = 0 | ||
| chunk_size=10 * 1024 |
| ) | ||
| with self.http.get(segment_url, stream=True, headers = {'Range' : "bytes=%s-" % (bytes_readed)}) as get_segment: | ||
| bytes_to_read = int(get_segment.headers['Content-Length']) | ||
| print("Download start from {start_byte}".format(start_byte=bytes_readed)) |
|
Without this fix I couldn't download a single file today. The download was constantly interrupted, and I had to start over. With this fix the files were downloaded, interruptions occurred approximately every 17 MB, but with retries the download progressed steadily. For cases with an unstable network this fix is a must. |
No description provided.