Show More
@@ -2,6 +2,7 b' import hashlib' | |||||
2 | import logging |
|
2 | import logging | |
3 | import re |
|
3 | import re | |
4 | import time |
|
4 | import time | |
|
5 | import traceback | |||
5 |
|
6 | |||
6 | import pytz |
|
7 | import pytz | |
7 | from django import forms |
|
8 | from django import forms |
@@ -41,20 +41,20 b' class Downloader:' | |||||
41 | # Get the actual content into memory |
|
41 | # Get the actual content into memory | |
42 | response = requests.get(url, verify=False, stream=True) |
|
42 | response = requests.get(url, verify=False, stream=True) | |
43 |
|
43 | |||
44 | # Download file, stop if the size exceeds limit |
|
44 | if response.status_code == HTTP_RESULT_OK: | |
45 | size = 0 |
|
45 | # Download file, stop if the size exceeds limit | |
46 |
|
46 | size = 0 | ||
47 | # Set a dummy file name that will be replaced |
|
|||
48 | # anyway, just keep the valid extension |
|
|||
49 | filename = 'file.' + content_type.split('/')[1] |
|
|||
50 |
|
47 | |||
51 | file = TemporaryUploadedFile(filename, content_type, 0, None, None) |
|
48 | # Set a dummy file name that will be replaced | |
52 | for chunk in response.iter_content(FILE_DOWNLOAD_CHUNK_BYTES): |
|
49 | # anyway, just keep the valid extension | |
53 | size += len(chunk) |
|
50 | filename = 'file.' + content_type.split('/')[1] | |
54 | validate_file_size(size) |
|
|||
55 | file.write(chunk) |
|
|||
56 |
|
51 | |||
57 | if response.status_code == HTTP_RESULT_OK: |
|
52 | file = TemporaryUploadedFile(filename, content_type, 0, None, None) | |
|
53 | for chunk in response.iter_content(FILE_DOWNLOAD_CHUNK_BYTES): | |||
|
54 | size += len(chunk) | |||
|
55 | validate_file_size(size) | |||
|
56 | file.write(chunk) | |||
|
57 | ||||
58 | return file |
|
58 | return file | |
59 |
|
59 | |||
60 |
|
60 | |||
@@ -85,12 +85,15 b' class YouTubeDownloader(Downloader):' | |||||
85 | class NothingDownloader(Downloader): |
|
85 | class NothingDownloader(Downloader): | |
86 | @staticmethod |
|
86 | @staticmethod | |
87 | def handles(url: str) -> bool: |
|
87 | def handles(url: str) -> bool: | |
88 |
if REGEX_MAGNET.match(url) |
|
88 | if REGEX_MAGNET.match(url): | |
89 | return True |
|
89 | return True | |
90 |
|
90 | |||
91 | response_head = requests.head(url, verify=False) |
|
91 | response_head = requests.head(url, verify=False) | |
92 | content_type = response_head.headers[HEADER_CONTENT_TYPE].split(';')[0] |
|
92 | if response_head.status_code == HTTP_RESULT_OK: | |
93 | return content_type in TYPE_URL_ONLY |
|
93 | content_type = response_head.headers[HEADER_CONTENT_TYPE].split(';')[0] | |
|
94 | return content_type in TYPE_URL_ONLY | |||
|
95 | else: | |||
|
96 | return True | |||
94 |
|
97 | |||
95 | @staticmethod |
|
98 | @staticmethod | |
96 | def download(url: str): |
|
99 | def download(url: str): |
General Comments 0
You need to be logged in to leave comments.
Login now