Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when the Content-Length header is missing #241

Merged
merged 2 commits into from
Sep 9, 2022

Conversation

woxcab
Copy link
Contributor

@woxcab woxcab commented Sep 8, 2022

hypnotix raises KeyError when a valid playlist response does not have Content-Length header.

I propose to set total_content_size = 0 when Content-Length header is missing.

@@ -161,7 +161,7 @@ def get_playlist(self, provider, refresh=False) -> bool:
# Set downloaded size
downloaded_bytes = 0
# Get total playlist byte size
total_content_size = int(response.headers['content-length'])
total_content_size = int(response.headers.get('content-length', 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered a default of 1 (or 15) instead so at least empty files of failed downloads are not left dangling?

if downloaded_bytes < total_content_size:
print("The file size is incorrect, deleting")
os.remove(provider.path)

Although they shouldn't hurt since at least these will be silently skipped later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. The value 15 seems to be optimal for the prefiltering. Committed.

@mtwebster mtwebster merged commit 3190333 into linuxmint:master Sep 9, 2022
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.

None yet

3 participants