##// END OF EJS Templates
Do not try to none-load youtube URLs. Try to download files only if response was 200
neko259 -
r1801:d819fe10 default
parent child Browse files
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,6 +41,7 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 if response.status_code == HTTP_RESULT_OK:
44 # Download file, stop if the size exceeds limit
45 # Download file, stop if the size exceeds limit
45 size = 0
46 size = 0
46
47
@@ -54,7 +55,6 b' class Downloader:'
54 validate_file_size(size)
55 validate_file_size(size)
55 file.write(chunk)
56 file.write(chunk)
56
57
57 if response.status_code == HTTP_RESULT_OK:
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) or REGEX_YOUTUBE_URL.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 if response_head.status_code == HTTP_RESULT_OK:
92 content_type = response_head.headers[HEADER_CONTENT_TYPE].split(';')[0]
93 content_type = response_head.headers[HEADER_CONTENT_TYPE].split(';')[0]
93 return content_type in TYPE_URL_ONLY
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