cutter: Simplify upload backend interface

Only support iterable of string, not file-like or string.

This is a minor usability loss but we only call this from one place anyway
and it's always an iterable of string.
pull/100/head
Mike Lang 5 years ago
parent f8039028c4
commit 1a177931a6

@ -19,7 +19,7 @@ class UploadBackend(object):
Should have a method upload_video(title, description, tags, data). Should have a method upload_video(title, description, tags, data).
Title, description and tags may have backend-specific meaning. Title, description and tags may have backend-specific meaning.
Tags is a list of string. Tags is a list of string.
Data may be a string, file-like object or iterator of strings. Data is an iterator of strings.
It should return (video_id, video_link). It should return (video_id, video_link).
If the video must undergo additional processing before it's available If the video must undergo additional processing before it's available
@ -156,20 +156,8 @@ class Local(UploadBackend):
'tags': tags, 'tags': tags,
}) + '\n') }) + '\n')
with open(filepath, 'w') as f: with open(filepath, 'w') as f:
if isinstance(data, str): for chunk in data:
# string f.write(chunk)
f.write(data)
elif hasattr(data, 'read'):
# file-like object
CHUNK_SIZE = 16*1024
chunk = data.read(CHUNK_SIZE)
while chunk:
f.write(chunk)
chunk = data.read(CHUNK_SIZE)
else:
# iterable of string
for chunk in data:
f.write(chunk)
if self.url_prefix is not None: if self.url_prefix is not None:
url = self.url_prefix + filename url = self.url_prefix + filename
else: else:

Loading…
Cancel
Save