From 0b2af37553b41b9e18a7dc798b7ec3c5eb8f7efc Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 13 Mar 2014 10:22:39 +0100 Subject: [PATCH] use addAnnotations --- pandora_client/__init__.py | 39 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 464be8f..0ee4623 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -828,6 +828,9 @@ class Client(object): i.e. pandora_client ABC transcripts /path/to/transcript.srt ''' + if not args: + print 'Usage: pandora_client ABC transcripts /path/to/transcript.srt' + sys.exit(1) item = args[0] layer = args[1] filename = args[2] @@ -835,23 +838,25 @@ class Client(object): if layer not in layers: print "invalid layer name, choices are: ", ', '.join(layers) sys.exit(1) - for s in ox.srt.load(filename): - r = self.api.addAnnotation({ - 'item': item, - 'layer': layer, - 'in': s['in'], - 'out': s['out'], - 'value': s['value'], - }) - if r['status']['code'] == 400: - print 'failed' - sys.exit(1) - if r['status']['code'] == 403: - print 'permission deinied' - sys.exit(1) - elif r['status']['code'] == 404: - print 'item not found' - sys.exit(1) + annotations = [{ + 'in': s['in'], + 'out': s['out'], + 'value': s['value'].replace('\n', '
\n') if layer == 'subtitles' else s['value'], + } for s in ox.srt.load(filename)] + r = self.api.addAnnotations({ + 'item': item, + 'layer': layer, + 'annotations': annotations + }) + if r['status']['code'] == 400: + print 'failed' + sys.exit(1) + if r['status']['code'] == 403: + print 'permission deinied' + sys.exit(1) + elif r['status']['code'] == 404: + print 'item not found' + sys.exit(1) def server(self, args): import server