Fix download not always returning entire requests.response object

This commit is contained in:
croneter 2021-09-24 16:02:32 +02:00
parent 352b36d32b
commit 33ad095080
2 changed files with 12 additions and 12 deletions

View file

@ -223,7 +223,11 @@ class DownloadUtils(object):
if r.status_code != 401: if r.status_code != 401:
self.count_unauthorized = 0 self.count_unauthorized = 0
if r.status_code == 204: if return_response is True:
# return the entire response object
return r
elif r.status_code == 204:
# No body in the response # No body in the response
# But read (empty) content to release connection back to pool # But read (empty) content to release connection back to pool
# (see requests: keep-alive documentation) # (see requests: keep-alive documentation)
@ -257,9 +261,6 @@ class DownloadUtils(object):
elif r.status_code in (200, 201): elif r.status_code in (200, 201):
# 200: OK # 200: OK
# 201: Created # 201: Created
if return_response is True:
# return the entire response object
return r
try: try:
# xml response # xml response
r = utils.etree.fromstring(r.content) r = utils.etree.fromstring(r.content)

View file

@ -357,16 +357,15 @@ class Media(object):
filename, filename,
extension) extension)
response = DU().downloadUrl(url, return_response=True) response = DU().downloadUrl(url, return_response=True)
try: if not response.ok:
response.status_code
except AttributeError:
LOG.error('Could not temporarily download subtitle %s', url) LOG.error('Could not temporarily download subtitle %s', url)
LOG.error('HTTP status: %s, message: %s',
response.status_code, response.text)
return return
else: LOG.debug('Writing temp subtitle to %s', path)
LOG.debug('Writing temp subtitle to %s', path) with open(path, 'wb') as f:
with open(path, 'wb') as f: f.write(response.content)
f.write(response.content) return path
return path
def validate_playurl(self, path, typus, force_check=False, folder=False, def validate_playurl(self, path, typus, force_check=False, folder=False,
omit_check=False): omit_check=False):