From 79b96490f9a02b16cb6846028a3ada076cb2e6e0 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 22 Feb 2014 17:50:00 +0530 Subject: [PATCH] fix extract offline, better estimate of remaining time on resume --- bin/pandora_client | 3 ++- pandora_client/__init__.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/pandora_client b/bin/pandora_client index 5c3aaab..86d290c 100755 --- a/bin/pandora_client +++ b/bin/pandora_client @@ -49,7 +49,8 @@ for more information visit https://wiki.0x2620.org/wiki/pandora_client''' % ', ' action = args[0] - offline = action in config or action == 'client' + offline = action in config or action == 'client' or \ + (action == 'extract' and len(args) == 2 and args[1] in ('offline', 'all')) if action == 'client': opts.config = {'url': '', 'cache': '~/.ox/client.sqlite', 'media-cache': '~/.ox/media'} if action == 'config': diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 889501b..3c3665b 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -141,6 +141,7 @@ class Client(object): self._config['url'] = self._config['url'] + '/' self.resolutions = self._config.get('resolutions', [480]) self.format = self._config.get('format', 'webm') + self.importFrames = False if not offline: self.online() @@ -286,6 +287,7 @@ class Client(object): if self.signin(): self.resolutions = list(reversed(sorted(self.api.site['video']['resolutions']))) self.format = self.api.site['video']['formats'][0] + self.importFrames = self.api.site['media'].get('importFrames') self.folderdepth = self._config.get('folderdepth', self.api.site['site'].get('folderdepth', 3)) def signin(self): @@ -566,7 +568,7 @@ class Client(object): if os.path.exists(path): profile = self.profile(info) i = encode(path, self.media_cache(), profile, info, - self.api.site['media'].get('importFrames')) + self.importFrames) break def sync(self, args): @@ -956,6 +958,9 @@ class API(ox.API): if 'offset' in data and data['offset'] < fsize: done = data['offset'] f.seek(done) + resume_offset = done + else: + resume_offset = 0 chunk = f.read(CHUNK_SIZE) fname = os.path.basename(filename) if isinstance(fname, unicode): @@ -964,7 +969,7 @@ class API(ox.API): elapsed = time.mktime(time.localtime()) - start remaining = "" if done: - r = math.ceil((elapsed / (done/fsize) - elapsed)/60) * 60 * 1000 + r = math.ceil((elapsed / (done/(fsize-resume_offset)) - elapsed)/60) * 60 * 1000 r = ox.format_duration(r, milliseconds=False, verbosity=2) if r: remaining = ", %s remaining" % r