better extract and file locating

This commit is contained in:
j 2012-01-04 12:31:43 +05:30
parent ed79ad9097
commit 28462d5f85
3 changed files with 29 additions and 7 deletions

View file

@ -25,15 +25,12 @@ if __name__ == '__main__':
parser.print_help() parser.print_help()
sys.exit() 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: 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)) parser.error('you must specify a valid action. \n\t\tknown actions are: %s' % ', '.join(actions))
action = args[0] action = args[0]
if action == 'extract':
offline = True
else:
offline = False offline = False
c = pandora_client.Client(opts.config, offline) c = pandora_client.Client(opts.config, offline)
getattr(c, action)(args[1:]) getattr(c, action)(args[1:])

View file

@ -3,6 +3,7 @@
"profile": "480p.webm", "profile": "480p.webm",
"username": "username", "password": "password", "username": "username", "password": "password",
"cache": "~/.ox/client.sqlite", "cache": "~/.ox/client.sqlite",
"media-cache": "~/.ox/media",
"volumes": { "volumes": {
"my videos": "/home/example/Movies" "my videos": "/home/example/Movies"
} }

View file

@ -225,7 +225,28 @@ class Client(object):
print "scanned volume %s: %s files, %s new, %s deleted" % ( print "scanned volume %s: %s files, %s new, %s deleted" % (
name, len(files), len(files) - len(known_files), len(deleted_files)) 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() conn, c = self._conn()
volumes = {} volumes = {}
@ -342,6 +363,7 @@ class Client(object):
for path in self.path(oshash): for path in self.path(oshash):
if os.path.exists(path): if os.path.exists(path):
self.api.uploadData(path, oshash) self.api.uploadData(path, oshash)
break
if r['data']['data']: if r['data']['data']:
print 'encoding and uploading %s videos' % len(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): for path in self.path(oshash):
if os.path.exists(path): if os.path.exists(path):
info = self.info(oshash) 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(): if not self.signin():
print "failed to login again" print "failed to login again"
return return
break
def files(self, prefix): def files(self, prefix):
conn, c = self._conn() conn, c = self._conn()