mirror of
https://github.com/ihabunek/toot.git
synced 2024-11-03 04:17:21 -05:00
Support adding description to media
This commit is contained in:
parent
83ca619c14
commit
ec097886d8
@ -2,6 +2,7 @@
|
|||||||
date: TBA
|
date: TBA
|
||||||
changes:
|
changes:
|
||||||
- "Add `--scheduled-at` option to `toot post`, allows scheduling toots"
|
- "Add `--scheduled-at` option to `toot post`, allows scheduling toots"
|
||||||
|
- "Add `--description` option to `toot post`, for adding descriptions to media attachments (thanks @ansuz)"
|
||||||
|
|
||||||
0.27.0:
|
0.27.0:
|
||||||
date: 2020-06-15
|
date: 2020-06-15
|
||||||
|
@ -217,10 +217,11 @@ def anon_tag_timeline_generator(instance, hashtag, local=False, limit=20):
|
|||||||
return _anon_timeline_generator(instance, path, params)
|
return _anon_timeline_generator(instance, path, params)
|
||||||
|
|
||||||
|
|
||||||
def upload_media(app, user, file):
|
def upload_media(app, user, file, description=None):
|
||||||
return http.post(app, user, '/api/v1/media', files={
|
return http.post(app, user, '/api/v1/media',
|
||||||
'file': file
|
data={'description': description},
|
||||||
}).json()
|
files={'file': file}
|
||||||
|
).json()
|
||||||
|
|
||||||
|
|
||||||
def search(app, user, query, resolve):
|
def search(app, user, query, resolve):
|
||||||
|
@ -87,15 +87,20 @@ def post(app, user, args):
|
|||||||
if not args.text and not sys.stdin.isatty():
|
if not args.text and not sys.stdin.isatty():
|
||||||
args.text = sys.stdin.read().rstrip()
|
args.text = sys.stdin.read().rstrip()
|
||||||
|
|
||||||
if args.media:
|
# Match media to corresponding description and upload
|
||||||
media = [_do_upload(app, user, file) for file in args.media]
|
media = args.media or []
|
||||||
media_ids = [m["id"] for m in media]
|
descriptions = args.description or []
|
||||||
else:
|
uploaded_media = []
|
||||||
media = None
|
|
||||||
media_ids = None
|
|
||||||
|
|
||||||
if media and not args.text:
|
for idx, file in enumerate(media):
|
||||||
args.text = "\n".join(m['text_url'] for m in media)
|
description = descriptions[idx].strip() if idx < len(descriptions) else None
|
||||||
|
result = _do_upload(app, user, file, description)
|
||||||
|
uploaded_media.append(result)
|
||||||
|
|
||||||
|
media_ids = [m["id"] for m in uploaded_media]
|
||||||
|
|
||||||
|
if uploaded_media and not args.text:
|
||||||
|
args.text = "\n".join(m['text_url'] for m in uploaded_media)
|
||||||
|
|
||||||
if args.editor:
|
if args.editor:
|
||||||
args.text = editor_input(args.editor, args.text)
|
args.text = editor_input(args.editor, args.text)
|
||||||
@ -210,7 +215,7 @@ def activate(app, user, args):
|
|||||||
|
|
||||||
|
|
||||||
def upload(app, user, args):
|
def upload(app, user, args):
|
||||||
response = _do_upload(app, user, args.file)
|
response = _do_upload(app, user, args.file, args.description)
|
||||||
|
|
||||||
msg = "Successfully uploaded media ID <yellow>{}</yellow>, type '<yellow>{}</yellow>'"
|
msg = "Successfully uploaded media ID <yellow>{}</yellow>, type '<yellow>{}</yellow>'"
|
||||||
|
|
||||||
@ -226,9 +231,9 @@ def search(app, user, args):
|
|||||||
print_search_results(response)
|
print_search_results(response)
|
||||||
|
|
||||||
|
|
||||||
def _do_upload(app, user, file):
|
def _do_upload(app, user, file, description):
|
||||||
print_out("Uploading media: <green>{}</green>".format(file.name))
|
print_out("Uploading media: <green>{}</green>".format(file.name))
|
||||||
return api.upload_media(app, user, file)
|
return api.upload_media(app, user, file, description=description)
|
||||||
|
|
||||||
|
|
||||||
def _find_account(app, user, account_name):
|
def _find_account(app, user, account_name):
|
||||||
|
@ -297,6 +297,12 @@ POST_COMMANDS = [
|
|||||||
"help": "path to the media file to attach (specify multiple "
|
"help": "path to the media file to attach (specify multiple "
|
||||||
"times to attach up to 4 files)"
|
"times to attach up to 4 files)"
|
||||||
}),
|
}),
|
||||||
|
(["-d", "--description"], {
|
||||||
|
"action": "append",
|
||||||
|
"type": str,
|
||||||
|
"help": "plain-text description of the media for accessibility "
|
||||||
|
"purposes, one per attached media"
|
||||||
|
}),
|
||||||
(["-v", "--visibility"], {
|
(["-v", "--visibility"], {
|
||||||
"type": visibility,
|
"type": visibility,
|
||||||
"default": "public",
|
"default": "public",
|
||||||
@ -341,7 +347,11 @@ POST_COMMANDS = [
|
|||||||
(["file"], {
|
(["file"], {
|
||||||
"help": "Path to the file to upload",
|
"help": "Path to the file to upload",
|
||||||
"type": FileType('rb')
|
"type": FileType('rb')
|
||||||
})
|
}),
|
||||||
|
(["-d", "--description"], {
|
||||||
|
"type": str,
|
||||||
|
"help": "plain-text description of the media for accessibility purposes"
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
require_auth=True,
|
require_auth=True,
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user