output encoding cmd

This commit is contained in:
j 2012-01-02 18:02:15 +05:30
parent 5f46806e1b
commit ed79ad9097
3 changed files with 37 additions and 9 deletions

View File

@ -25,7 +25,7 @@ if __name__ == '__main__':
parser.print_help()
sys.exit()
actions = ('scan', 'sync', 'upload', 'extract', 'clean')
actions = ('scan', 'sync', 'upload', 'extract', '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))
@ -36,5 +36,5 @@ if __name__ == '__main__':
else:
offline = False
c = pandora_client.Client(opts.config, offline)
getattr(c, action)()
getattr(c, action)(args[1:])

View File

@ -49,6 +49,16 @@ def encode(filename, prefix, profile, info=None):
'video': video_f
}
def encode_cmd(filename, prefix, profile, info):
if not info:
info = utils.avinfo(filename)
if not 'oshash' in info:
return None
oshash = info['oshash']
cache = os.path.join(prefix, os.path.join(*utils.hash_prefix(oshash)))
video_f = os.path.join(cache, profile)
return extract.video_cmd(filename, video_f, profile, info)
class Client(object):
def __init__(self, config, offline=False):
if isinstance(config, basestring):
@ -170,7 +180,19 @@ class Client(object):
c.execute(u'INSERT OR REPLACE INTO file values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', t)
conn.commit()
def scan(self):
def cmd(self, args):
filename = args[0]
if len(filename) == 16:
path = self.paths(filename)
else:
path = [filename]
for p in path:
if os.path.exists(p):
cmd = encode_cmd(p, self.media_cache(), self.profile, None)
cmd = [' ' in c and '"%s"' % c or c for c in cmd]
print ' '.join(cmd)
def scan(self, args):
print "checking for new files ..."
for name in self._config['volumes']:
path = self._config['volumes'][name]
@ -203,7 +225,7 @@ 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):
def extract(self, args):
conn, c = self._conn()
volumes = {}
@ -232,7 +254,7 @@ class Client(object):
print filename.encode('utf-8')
i = encode(filename, self.media_cache(), self.profile, info)
def sync(self):
def sync(self, args):
if not self.user:
print "you need to login"
return
@ -304,7 +326,7 @@ class Client(object):
print '\ncould upload %s subtitles:\n' % len(files)
print '\n'.join(files)
def upload(self):
def upload(self, args):
if not self.user:
print "you need to login"
return
@ -454,9 +476,10 @@ class API(ox.API):
print "\ninterrupted by user."
sys.exit(1)
except:
print "uploading chunk failed, will try again in 5 seconds"
print "uploading chunk failed, will try again in 5 seconds\r",
sys.stdout.flush()
if DEBUG:
print uploadUrl
print '\n', uploadUrl
import traceback
traceback.print_exc()
data = {'result': -1}

View File

@ -58,7 +58,8 @@ def frame(video, target, position):
r = run_command(cmd)
return r == 0
def video(video, target, profile, info):
def video_cmd(video, target, profile, info):
if not os.path.exists(target):
ox.makedirs(os.path.dirname(target))
@ -147,6 +148,10 @@ def video(video, target, profile, info):
+ video_settings \
+ ['-f','webm', target]
return cmd
def video(video, target, profile, info):
cmd = video_cmd(video, target, profile, info)
#r = run_command(cmd, -1)
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
'''