new upload algorithm

This commit is contained in:
j 2010-12-25 19:24:36 +05:30
parent 87a7112c07
commit 5b93cc7022

View file

@ -181,26 +181,41 @@ class Client(object):
prefix = volumes[name]['path'] prefix = volumes[name]['path']
files = self.files(prefix) files = self.files(prefix)
files['volume'] = name files['volume'] = name
print 'sending list of files'
r = self.api.update(files) r = self.api.update(files)
if r['status']['code'] == 200: if r['status']['code'] == 200:
#backend works on update request asyncronously, wait for it to finish
if r['data']['info']: if 'taskId' in r['data']:
t = self.api.taskStatus(task_id=r['data']['taskId'])
print 'waiting for server'
while t['data']['status'] == 'PENDING':
time.sleep(5)
t = self.api.taskStatus(task_id=r['data']['taskId'])
post = {'info': {}} post = {'info': {}}
r = self.api.update(post)
post = {'info': {}}
if r['data']['info']:
for oshash in r['data']['info']: for oshash in r['data']['info']:
post['info'][oshash] = files['info'][oshash] post['info'][oshash] = files['info'][oshash]
r2 = self.api.update(post) print 'sending info for new files', len(post['info'])
#FIXME: should r2 be merged with r? r = self.api.update(post)
filenames = {} filenames = {}
for f in files['files']: for f in files['files']:
filenames[f['oshash']] = f['path'] filenames[f['oshash']] = f['path']
print 'encoding videos', len(r['data']['data'])
if r['data']['data']: if r['data']['data']:
for oshash in r['data']['data']: for oshash in r['data']['data']:
data = {} data = {}
if oshash in filenames:
filename = filenames[oshash] filename = filenames[oshash]
self.api.uploadVideo(os.path.join(prefix, filename), data, profile) self.api.uploadVideo(os.path.join(prefix, filename), data, profile)
else:
print oshash, "missing"
print 'uploading files', len(r['data']['file'])
if r['data']['file']: if r['data']['file']:
for oshash in r['data']['file']: for oshash in r['data']['file']:
filename = filenames[oshash] filename = filenames[oshash]