output encoding cmd
This commit is contained in:
parent
5f46806e1b
commit
ed79ad9097
3 changed files with 37 additions and 9 deletions
|
@ -25,7 +25,7 @@ if __name__ == '__main__':
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
actions = ('scan', 'sync', 'upload', 'extract', 'clean')
|
actions = ('scan', 'sync', 'upload', 'extract', '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))
|
||||||
|
|
||||||
|
@ -36,5 +36,5 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
offline = False
|
offline = False
|
||||||
c = pandora_client.Client(opts.config, offline)
|
c = pandora_client.Client(opts.config, offline)
|
||||||
getattr(c, action)()
|
getattr(c, action)(args[1:])
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,16 @@ def encode(filename, prefix, profile, info=None):
|
||||||
'video': video_f
|
'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):
|
class Client(object):
|
||||||
def __init__(self, config, offline=False):
|
def __init__(self, config, offline=False):
|
||||||
if isinstance(config, basestring):
|
if isinstance(config, basestring):
|
||||||
|
@ -170,7 +180,19 @@ class Client(object):
|
||||||
c.execute(u'INSERT OR REPLACE INTO file values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', t)
|
c.execute(u'INSERT OR REPLACE INTO file values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', t)
|
||||||
conn.commit()
|
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 ..."
|
print "checking for new files ..."
|
||||||
for name in self._config['volumes']:
|
for name in self._config['volumes']:
|
||||||
path = self._config['volumes'][name]
|
path = self._config['volumes'][name]
|
||||||
|
@ -203,7 +225,7 @@ 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):
|
def extract(self, args):
|
||||||
conn, c = self._conn()
|
conn, c = self._conn()
|
||||||
|
|
||||||
volumes = {}
|
volumes = {}
|
||||||
|
@ -232,7 +254,7 @@ class Client(object):
|
||||||
print filename.encode('utf-8')
|
print filename.encode('utf-8')
|
||||||
i = encode(filename, self.media_cache(), self.profile, info)
|
i = encode(filename, self.media_cache(), self.profile, info)
|
||||||
|
|
||||||
def sync(self):
|
def sync(self, args):
|
||||||
if not self.user:
|
if not self.user:
|
||||||
print "you need to login"
|
print "you need to login"
|
||||||
return
|
return
|
||||||
|
@ -304,7 +326,7 @@ class Client(object):
|
||||||
print '\ncould upload %s subtitles:\n' % len(files)
|
print '\ncould upload %s subtitles:\n' % len(files)
|
||||||
print '\n'.join(files)
|
print '\n'.join(files)
|
||||||
|
|
||||||
def upload(self):
|
def upload(self, args):
|
||||||
if not self.user:
|
if not self.user:
|
||||||
print "you need to login"
|
print "you need to login"
|
||||||
return
|
return
|
||||||
|
@ -454,9 +476,10 @@ class API(ox.API):
|
||||||
print "\ninterrupted by user."
|
print "\ninterrupted by user."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except:
|
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:
|
if DEBUG:
|
||||||
print uploadUrl
|
print '\n', uploadUrl
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
data = {'result': -1}
|
data = {'result': -1}
|
||||||
|
|
|
@ -58,7 +58,8 @@ def frame(video, target, position):
|
||||||
r = run_command(cmd)
|
r = run_command(cmd)
|
||||||
return r == 0
|
return r == 0
|
||||||
|
|
||||||
def video(video, target, profile, info):
|
def video_cmd(video, target, profile, info):
|
||||||
|
|
||||||
if not os.path.exists(target):
|
if not os.path.exists(target):
|
||||||
ox.makedirs(os.path.dirname(target))
|
ox.makedirs(os.path.dirname(target))
|
||||||
|
|
||||||
|
@ -147,6 +148,10 @@ def video(video, target, profile, info):
|
||||||
+ video_settings \
|
+ video_settings \
|
||||||
+ ['-f','webm', target]
|
+ ['-f','webm', target]
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
def video(video, target, profile, info):
|
||||||
|
cmd = video_cmd(video, target, profile, info)
|
||||||
#r = run_command(cmd, -1)
|
#r = run_command(cmd, -1)
|
||||||
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue