Fixes Issue #2 #4

Merged
dafo5502 merged 59 commits from developer into master 2021-10-25 14:41:37 +02:00
Showing only changes of commit cec3fd7781 - Show all commits

View File

@ -6,6 +6,7 @@ import shutil
import requests import requests
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
from requests.sessions import Session
from daisy import DaisyHandler from daisy import DaisyHandler
@ -46,19 +47,25 @@ class Mediasite:
if 'id' in data: if 'id' in data:
mypackage['notification_id'] = data['id'] mypackage['notification_id'] = data['id']
mypackage['thumb'] = self._download(base, data['thumb'], self.auth) with requests.Session() as session:
session.auth = self.auth
session.stream = True
mypackage['thumb'] = self._download(base, data['thumb'], session)
for source in data['sources']: for source in data['sources']:
mysource = {'video': self._download(base, source['video']), mysource = {'video': self._download(base, source['video'], session),
'poster': self._download(base, source['poster'], 'poster': self._download(base, source['poster'], session),
self.auth),
'playAudio': source['playAudio']} 'playAudio': source['playAudio']}
mypackage['sources'].append(mysource) mypackage['sources'].append(mysource)
mypackage['slides'] = [
setattr(elem, 'url', os.path.join(base, self._download(base, elem['url'], session))) for elem in data['slides']
]
return mypackage return mypackage
def _download(self, base, remotefile, auth=None): def _download(self, base, remotefile, session: Session):
localname = remotefile.split('/')[-1] localname = remotefile.split('/')[-1]
localpath = os.path.join(base, localname) localpath = os.path.join(base, localname)
with requests.get(remotefile, stream=True, auth=auth) as r: r = session.get(remotefile)
r.raise_for_status() r.raise_for_status()
with open(localpath, 'xb') as f: with open(localpath, 'xb') as f:
for chunk in r.iter_content(chunk_size=self.chunk_size): for chunk in r.iter_content(chunk_size=self.chunk_size):