- def put(cls, audiobook, path):
- tags = getattr(audiobook, "%s_tags" % cls.ext)
- prefix, slug = tags['url'].rstrip('/').rsplit('/', 1)
- name = tags['name']
- command = UPLOAD_CMD + (u' %s %s %s %s %s %s > output.txt' % (
- pipes.quote(os.path.join(UPLOAD_PATH, os.path.basename(path))),
- pipes.quote(slug),
- pipes.quote(name),
- pipes.quote(audiobook.part_name),
- audiobook.index,
- audiobook.parts_count,
- )).encode('utf-8')
- try:
- api.put(path, UPLOAD_PATH)
- if UPLOAD_SUDO:
- api.sudo(command, user=UPLOAD_SUDO, shell=False)
- else:
- api.run(command)
- disconnect_all()
- except SystemExit as e:
- raise cls.RemoteOperationError
-
- def run(self, aid, publish=True):
+ def put(cls, user, audiobook, path):
+ tags = getattr(audiobook, "get_%s_tags" % cls.prefix)()
+ data = {
+ 'book': tags['url'],
+ 'type': cls.ext,
+ 'name': tags['name'],
+ 'part_name': audiobook.part_name,
+ 'part_index': audiobook.index,
+ 'parts_count': audiobook.parts_count,
+ 'source_sha1': audiobook.source_sha1,
+
+ 'project_description': audiobook.project.get_description(),
+ 'project_icon': audiobook.project.get_icon_url(),
+ }
+ with open(path, 'rb') as f:
+ api_call(user, UPLOAD_URL, data=data, files={
+ "file": f,
+ })
+
+ def run(self, uid, aid, publish=True):