Utilisation d'une session.

This commit is contained in:
Frédéric Tronel
2024-01-06 16:15:47 +01:00
parent 2ea2cf0fc6
commit bded5e8990

View File

@@ -234,10 +234,11 @@ def downloadMovie(url, outputFileName, duration):
exit(-1) exit(-1)
outputFD = output.fileno() outputFD = output.fileno()
session = sessions.Session()
sample = 2. sample = 2.
headers = {'TimeSeekRange.dlna.org': 'npt=0.000-%.03f' % sample} headers = {'TimeSeekRange.dlna.org': 'npt=0.000-%.03f' % sample}
r = requests.get(url, headers=headers) r = session.get(url, headers=headers)
if r.status_code != 200: if r.status_code != 200:
logger.error('Impossible to download first %f seconds: %d' % (sample,r.status_code)) logger.error('Impossible to download first %f seconds: %d' % (sample,r.status_code))
exit(-1) exit(-1)
@@ -269,7 +270,8 @@ def downloadMovie(url, outputFileName, duration):
pb = tqdm(total=estimatedLength, unit='bytes', desc='Download', unit_scale=True, unit_divisor=1024) pb = tqdm(total=estimatedLength, unit='bytes', desc='Download', unit_scale=True, unit_divisor=1024)
nbiters = 0 nbiters = 0
with requests.get(url, stream=True) as r:
with session.get(url, stream=True) as r:
chunks = r.iter_content(chunk_size = 100000) chunks = r.iter_content(chunk_size = 100000)
for chunk in chunks: for chunk in chunks:
output.write(chunk) output.write(chunk)