From bfe27b3848ff7b7fa633b0875eb496fcb26ab6cb Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 23 Aug 2011 21:20:16 +0200 Subject: [PATCH] more options --- bin/pandora_client | 2 +- pandora_client/__init__.py | 80 +++++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/bin/pandora_client b/bin/pandora_client index 2b6d0dc..8ccd639 100755 --- a/bin/pandora_client +++ b/bin/pandora_client @@ -25,7 +25,7 @@ if __name__ == '__main__': parser.print_help() sys.exit() - actions = ('scan', 'extract', 'sync', 'clean') + actions = ('scan', 'sync', 'upload', 'extract', 'clean') if not args or args[0] not in actions: parser.error('you must specify a valid action. \n\t\tknown actions are: %s' % ', '.join(actions)) diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index f44b0a2..1911dcb 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -263,41 +263,57 @@ class Client(object): if len(post['info']): print 'sending info for new files', len(post['info']), offset, total r = self.api.update(post) - - #send empty list to get updated list of requested info/files/data - post = {'info': {}} - r = self.api.update(post) - filenames = {} - for f in files['files']: - filenames[f['oshash']] = f['path'] - - print 'uploading files', len(r['data']['file']) - if r['data']['file']: - for oshash in r['data']['file']: - if oshash in filenames: - filename = filenames[oshash] - self.api.uploadData(os.path.join(prefix, filename), oshash) + def upload(self): + if not self.user: + print "you need to login" + return + conn, c = self._conn() - print 'encoding videos', len(r['data']['data']) - if r['data']['data']: - for oshash in r['data']['data']: - data = {} - if oshash in filenames: - filename = filenames[oshash] - info = files['info'][oshash] - if not self.api.uploadVideo(os.path.join(prefix, filename), - data, profile, info): - if not self.signin(): - print "failed to login again" - return + volumes = {} + for name in self._config['volumes']: + path = self._config['volumes'][name] + path = os.path.normpath(path) - else: - pass - #print oshash, "missing" - else: - print "updating volume", name, "failed" - print r + volumes[name] = {} + volumes[name]['path'] = path + if os.path.exists(path): + volumes[name]['available'] = True + else: + volumes[name]['available'] = False + + profile = self.api.encodingProfile()['data']['profile'] + for name in volumes: + if volumes[name]['available']: + prefix = volumes[name]['path'] + files = self.files(prefix) + + filenames = {} + for f in files['files']: + filenames[f['oshash']] = f['path'] + #send empty list to get updated list of requested info/files/data + post = {'info': {}} + r = self.api.update(post) + + print 'uploading files', len(r['data']['file']) + if r['data']['file']: + for oshash in r['data']['file']: + if oshash in filenames: + filename = filenames[oshash] + self.api.uploadData(os.path.join(prefix, filename), oshash) + + print 'encoding videos', len(r['data']['data']) + if r['data']['data']: + for oshash in r['data']['data']: + data = {} + if oshash in filenames: + filename = filenames[oshash] + info = files['info'][oshash] + if not self.api.uploadVideo(os.path.join(prefix, filename), + data, profile, info): + if not self.signin(): + print "failed to login again" + return def files(self, prefix): conn, c = self._conn()