From 28462d5f857a091c41e31bb4646112e38b709ee8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 4 Jan 2012 12:31:43 +0530 Subject: [PATCH] better extract and file locating --- bin/pandora_client | 7 ++----- config.example.json | 1 + pandora_client/__init__.py | 28 ++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/bin/pandora_client b/bin/pandora_client index 120c327..d4c119c 100755 --- a/bin/pandora_client +++ b/bin/pandora_client @@ -25,16 +25,13 @@ if __name__ == '__main__': parser.print_help() sys.exit() - actions = ('scan', 'sync', 'upload', 'extract', 'clean', 'cmd') + actions = ('scan', 'sync', 'upload', 'extract', 'extract_offline', 'clean', 'cmd') 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)) action = args[0] - if action == 'extract': - offline = True - else: - offline = False + offline = False c = pandora_client.Client(opts.config, offline) getattr(c, action)(args[1:]) diff --git a/config.example.json b/config.example.json index 5649b32..4ec83a8 100644 --- a/config.example.json +++ b/config.example.json @@ -3,6 +3,7 @@ "profile": "480p.webm", "username": "username", "password": "password", "cache": "~/.ox/client.sqlite", + "media-cache": "~/.ox/media", "volumes": { "my videos": "/home/example/Movies" } diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index efffe06..8860472 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -225,7 +225,28 @@ class Client(object): print "scanned volume %s: %s files, %s new, %s deleted" % ( name, len(files), len(files) - len(known_files), len(deleted_files)) - def extract(self, args): + def extract(self): + if not self.user: + print "you need to login" + return + conn, c = self._conn() + + #send empty list to get updated list of requested info/files/data + post = {'info': {}} + r = self.api.update(post) + + if r['data']['data']: + print 'encoding %s videos' % len(r['data']['data']) + for oshash in r['data']['data']: + data = {} + 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) + break + + def extract_offline(self): conn, c = self._conn() volumes = {} @@ -342,6 +363,7 @@ class Client(object): for path in self.path(oshash): if os.path.exists(path): self.api.uploadData(path, oshash) + break if r['data']['data']: print 'encoding and uploading %s videos' % len(r['data']['data']) @@ -350,10 +372,12 @@ class Client(object): 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): + if not self.api.uploadVideo(path, + data, self.profile, info): if not self.signin(): print "failed to login again" return + break def files(self, prefix): conn, c = self._conn()