fix extract offline, better estimate of remaining time on resume

This commit is contained in:
j 2014-02-22 17:50:00 +05:30
parent bd2fabf1ed
commit 79b96490f9
2 changed files with 9 additions and 3 deletions

View file

@ -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':

View file

@ -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