From c9edb4bd7959dcd44adca18d139daa20158f692a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 30 Apr 2013 18:09:15 +0200 Subject: [PATCH] ignore files with errors but still sync --- pandora_client/__init__.py | 64 ++++++++++++++++++++------------------ pandora_client/extract.py | 4 +-- pandora_client/server.py | 4 ++- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 40ddc64..f19ad98 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -312,7 +312,7 @@ class Client(object): if update: info = utils.avinfo(path) if 'error' in info or info['size'] == 0: - print info + #print info return False else: oshash = info['oshash'] @@ -448,12 +448,14 @@ class Client(object): print '\n\t'.join([f[len(path):] for f in unknown]) print '' + ''' if unsupported: files = list(set(files) - set(unsupported)) print 'The following files are in an unsupported format and will not be synced:' print '\t', print '\n\t'.join([f[len(path):] for f in unsupported]) print '' + ''' deleted_files = filter(lambda f: f not in files, known_files) new_files = filter(lambda f: f not in known_files, files) @@ -491,13 +493,14 @@ class Client(object): self.update_encodes() for oshash in files: - for path in self.path(oshash): - if os.path.exists(path): - info = self.info(oshash) - #print path.encode('utf-8') - i = encode(path, self.media_cache(), self.profile, info, - self.api.site['media'].get('importFrames')) - break + info = self.info(oshash) + if not 'error' in info: + for path in self.path(oshash): + if os.path.exists(path): + #print path.encode('utf-8') + i = encode(path, self.media_cache(), self.profile, info, + self.api.site['media'].get('importFrames')) + break def sync(self, args): if not self.user: @@ -624,28 +627,29 @@ class Client(object): print 'encoding and uploading %s videos' % len(data) for oshash in data: data = {} - for path in self.path(oshash): - if os.path.exists(path): - info = self.info(oshash) - if not self.api.uploadVideo(path, - data, self.profile, info): - print 'video upload failed, giving up, please try again' - return - if 'rightsLevel' in self._config: - r = self.api.find({'query': { - 'conditions': [ - {'key': 'oshash', 'value': oshash, 'operator': '=='} - ], - 'keys': ['id'], - 'range': [0, 1] - }}) - if r['data']['items']: - item = r['data']['items'][0]['id'] - r = self.api.edit({ - 'item': item, - 'rightsLevel': self._config['rightsLevel'] - }) - break + info = self.info(oshash) + if not 'error' in info: + for path in self.path(oshash): + if os.path.exists(path): + if not self.api.uploadVideo(path, + data, self.profile, info): + print 'video upload failed, giving up, please try again' + return + if 'rightsLevel' in self._config: + r = self.api.find({'query': { + 'conditions': [ + {'key': 'oshash', 'value': oshash, 'operator': '=='} + ], + 'keys': ['id'], + 'range': [0, 1] + }}) + if r['data']['items']: + item = r['data']['items'][0]['id'] + r = self.api.edit({ + 'item': item, + 'rightsLevel': self._config['rightsLevel'] + }) + break if files: print 'uploading %s files' % len(files) diff --git a/pandora_client/extract.py b/pandora_client/extract.py index 9fde8eb..03f3189 100644 --- a/pandora_client/extract.py +++ b/pandora_client/extract.py @@ -156,7 +156,7 @@ def video_cmd(video, target, profile, info): audiobitrate = '22k' audiochannels = 1 - if 'video' in info and info['video'] and 'display_aspect_ratio' in info['video'][0]: + if info['video'] and 'display_aspect_ratio' in info['video'][0]: dar = AspectRatio(info['video'][0]['display_aspect_ratio']) fps = AspectRatio(info['video'][0]['framerate']) width = int(dar * height) @@ -232,7 +232,7 @@ def video_cmd(video, target, profile, info): else: video_settings = ['-vn'] - if 'audio' in info and info['audio']: + if info['audio']: if video_settings == ['-vn'] or not info['video']: n = 0 else: diff --git a/pandora_client/server.py b/pandora_client/server.py index efde2a9..f28ed6a 100644 --- a/pandora_client/server.py +++ b/pandora_client/server.py @@ -124,10 +124,12 @@ class Server(Resource): self.update_status(oshash, 'done') self.upload.put(oshash) continue + info = self.client.info(oshash) + if 'error' in info: + continue for f in self.client.path(oshash): if os.path.exists(f): response['oshash'] = oshash - info = self.client.info(oshash) url = 'http://%s:%s/get/%s' % (request.host.host, request.host.port, oshash) output = '/tmp/%s.%s' % (oshash, self.client.profile) response['cmd'] = extract.video_cmd(url, output, self.client.profile, info)