Skip to content

Add ability to resume file downloading - #18

Open
MikeZhur wants to merge 1 commit into
anijackich:masterfrom
MikeZhur:resume_download
Open

Add ability to resume file downloading#18
MikeZhur wants to merge 1 commit into
anijackich:masterfrom
MikeZhur:resume_download

Conversation

@MikeZhur

Copy link
Copy Markdown

No description provided.

Comment thread kinescope/downloader.py
Comment on lines +70 to +87
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty complicated, what do you think about splitting this inline into parts?

Comment thread kinescope/downloader.py
segment_url: str,
file):
for _ in range(5):
print("segment_url: {segment_url}, file: {file}".format(segment_url = segment_url, file = file))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foramat is not recommended for use. I would suggest you to use f-string or redo the logging system at the root :)

@ic-it ic-it left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after fix comments above

Comment thread kinescope/downloader.py
except ChunkedEncodingError:
pass
except ChunkedEncodingError as e:
print("Error! bytes_readed %s, bytes_remained %s" % (bytes_readed, bytes_to_read))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use different approaches to formatting, why?

Comment thread kinescope/downloader.py
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please install formatter

Comment thread kinescope/downloader.py
)
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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@ilyagp

ilyagp commented Nov 26, 2024

Copy link
Copy Markdown

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.
In addition, it adds verbosity to what the program does. Without it, I had to monitor the resource monitor to understand that the program is alive and downloading traffic. (Files come in segments of ~77 MB, and until the entire segment is downloaded, the program does not show signs of life on the console)
I would be happy if this PR was accepted to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants