more output

This commit is contained in:
j 2011-12-28 20:30:17 +05:30
parent 9be69f2568
commit 052fc40e1c
3 changed files with 49 additions and 24 deletions

View file

@ -19,8 +19,8 @@ import extract
import utils import utils
__version__ = '0.1' __version__ = '0.2'
DEBUG = True DEBUG = False
default_media_cache = os.environ.get('oxMEDIA', os.path.expanduser('~/.ox/media')) default_media_cache = os.environ.get('oxMEDIA', os.path.expanduser('~/.ox/media'))
def encode(filename, prefix, profile, info=None): def encode(filename, prefix, profile, info=None):
@ -41,7 +41,6 @@ def encode(filename, prefix, profile, info=None):
frames.append(frame_f) frames.append(frame_f)
video_f = os.path.join(cache, profile) video_f = os.path.join(cache, profile)
if not os.path.exists(video_f): if not os.path.exists(video_f):
print video_f
extract.video(filename, video_f, profile, info) extract.video(filename, video_f, profile, info)
return { return {
'info': info, 'info': info,
@ -116,9 +115,17 @@ class Client(object):
conn, c = self._conn() conn, c = self._conn()
c.execute('SELECT info FROM file WHERE oshash = ?', (oshash, )) c.execute('SELECT info FROM file WHERE oshash = ?', (oshash, ))
for row in c: for row in c:
return json.loads(row[2]) return json.loads(row[0])
return None return None
def path(self, oshash):
conn, c = self._conn()
c.execute('SELECT path FROM file WHERE oshash = ?', (oshash, ))
paths = []
for row in c:
paths.append(row[0])
return paths
def signin(self): def signin(self):
if 'username' in self._config: if 'username' in self._config:
r = self.api.signin(username=self._config['username'], password=self._config['password']) r = self.api.signin(username=self._config['username'], password=self._config['password'])
@ -159,7 +166,7 @@ class Client(object):
conn.commit() conn.commit()
def scan(self): def scan(self):
print "check 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]
path = os.path.normpath(path) path = os.path.normpath(path)
@ -181,12 +188,16 @@ class Client(object):
c.execute('SELECT path FROM file WHERE path LIKE ? AND deleted < 0', ["%s%%"%path]) c.execute('SELECT path FROM file WHERE path LIKE ? AND deleted < 0', ["%s%%"%path])
known_files = [r[0] for r in c.fetchall()] known_files = [r[0] for r in c.fetchall()]
deleted_files = filter(lambda f: f not in files, known_files) deleted_files = filter(lambda f: f not in files, known_files)
if deleted_files: if deleted_files:
deleted = time.mktime(time.localtime()) deleted = time.mktime(time.localtime())
for f in deleted_files: for f in deleted_files:
c.execute('UPDATE file SET deleted=? WHERE path=?', (deleted, f)) c.execute('UPDATE file SET deleted=? WHERE path=?', (deleted, f))
conn.commit() conn.commit()
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):
conn, c = self._conn() conn, c = self._conn()
@ -235,7 +246,6 @@ class Client(object):
else: else:
volumes[name]['available'] = False volumes[name]['available'] = False
profile = self.get_profile()
for name in volumes: for name in volumes:
if volumes[name]['available']: if volumes[name]['available']:
prefix = volumes[name]['path'] prefix = volumes[name]['path']
@ -243,13 +253,13 @@ class Client(object):
post = {} post = {}
post['files'] = files['files'] post['files'] = files['files']
post['volume'] = name post['volume'] = name
print 'sending list of files', len(post['files']) print 'Sending list of files in %s (%s total)' % (name, len(post['files']))
r = self.api.update(post) r = self.api.update(post)
if r['status']['code'] == 200: if r['status']['code'] == 200:
#backend works on update request asyncronously, wait for it to finish #backend works on update request asyncronously, wait for it to finish
if 'taskId' in r['data']: if 'taskId' in r['data']:
t = self.api.taskStatus(task_id=r['data']['taskId']) t = self.api.taskStatus(task_id=r['data']['taskId'])
print 'waiting for server' print 'Waiting for server ...'
while t['data']['status'] == 'PENDING': while t['data']['status'] == 'PENDING':
time.sleep(5) time.sleep(5)
t = self.api.taskStatus(task_id=r['data']['taskId']) t = self.api.taskStatus(task_id=r['data']['taskId'])
@ -261,14 +271,34 @@ class Client(object):
info = r['data']['info'] info = r['data']['info']
max_info = 100 max_info = 100
total = len(info) total = len(info)
print 'Sending info for %s files' % total
for offset in range(0, total, max_info): for offset in range(0, total, max_info):
post = {'info': {}, 'upload': True} post = {'info': {}, 'upload': True}
for oshash in info[offset:offset+max_info]: for oshash in info[offset:offset+max_info]:
if oshash in files['info']: if oshash in files['info']:
post['info'][oshash] = files['info'][oshash] post['info'][oshash] = files['info'][oshash]
if len(post['info']): if len(post['info']):
print 'sending info for new files', len(post['info']), offset, total
r = self.api.update(post) r = self.api.update(post)
if r['data']['data']:
files = []
for f in r['data']['data']:
for path in self.path(f):
if os.path.exists(path):
files.append(path)
break
if files:
print '\nCould encoded and upload %s videos:\n' % len(files)
print '\n'.join(files)
if r['data']['file']:
files = []
for f in r['data']['file']:
for path in self.path(f):
if os.path.exists(path):
files.append(path)
break
if files:
print '\nCould upload %s subtitles:\n' % len(files)
print '\n'.join(files)
def upload(self): def upload(self):
if not self.user: if not self.user:
@ -301,14 +331,14 @@ class Client(object):
post = {'info': {}} post = {'info': {}}
r = self.api.update(post) r = self.api.update(post)
print 'uploading files', len(r['data']['file']) print 'Uploading %s files' % len(r['data']['file'])
if r['data']['file']: if r['data']['file']:
for oshash in r['data']['file']: for oshash in r['data']['file']:
if oshash in filenames: if oshash in filenames:
filename = filenames[oshash] filename = filenames[oshash]
self.api.uploadData(os.path.join(prefix, filename), oshash) self.api.uploadData(os.path.join(prefix, filename), oshash)
print 'encoding videos', len(r['data']['data']) print 'Encoding and uploading %s videos' % len(r['data']['data'])
if r['data']['data']: if r['data']['data']:
for oshash in r['data']['data']: for oshash in r['data']['data']:
data = {} data = {}
@ -384,19 +414,16 @@ class API(ox.API):
r = self._json_request(self.url, form) r = self._json_request(self.url, form)
#upload video #upload video
print "Uploading", filename
if os.path.exists(i['video']): if os.path.exists(i['video']):
url = self.url + 'upload/' + '?profile=' + str(profile) + '&id=' + i['oshash'] url = self.url + 'upload/' + '?profile=' + str(profile) + '&id=' + i['oshash']
ogg = Firefogg(cj=self._cj, debug=True) ogg = Firefogg(cj=self._cj, debug=DEBUG)
if not ogg.upload(url, i['video'], data): if not ogg.upload(url, i['video'], data):
if DEBUG: if DEBUG:
print "failed" print "failed"
return False return False
else: else:
if DEBUG: print "Failed"
print "done"
else:
if DEBUG:
print "failed"
return False return False
return True return True

View file

@ -73,6 +73,7 @@ def video(video, target, profile, info):
bt? bt?
''' '''
profile, format = profile.split('.') profile, format = profile.split('.')
bpp = 0.17
if profile == '720p': if profile == '720p':
height = 720 height = 720
@ -110,7 +111,6 @@ def video(video, target, profile, info):
audiobitrate = '22k' audiobitrate = '22k'
audiochannels = 1 audiochannels = 1
bpp = 0.17
if info['video'] and 'display_aspect_ratio' in info['video'][0]: if info['video'] and 'display_aspect_ratio' in info['video'][0]:
dar = AspectRatio(info['video'][0]['display_aspect_ratio']) dar = AspectRatio(info['video'][0]['display_aspect_ratio'])
fps = AspectRatio(info['video'][0]['framerate']) fps = AspectRatio(info['video'][0]['framerate'])
@ -146,7 +146,6 @@ def video(video, target, profile, info):
+ audio_settings \ + audio_settings \
+ video_settings \ + video_settings \
+ ['-f','webm', target] + ['-f','webm', target]
print cmd
#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)
@ -161,13 +160,12 @@ def video(video, target, profile, info):
try: try:
p.wait() p.wait()
r = p.returncode r = p.returncode
print 'Input:\t', video
print 'Output:\t', target
except KeyboardInterrupt: except KeyboardInterrupt:
r = 1 r = 1
print "\ncleaning up unfinished encoding:\nremoving", target print "\n\ncleanup unfinished encoding:\nremoving", target
print "\n" print "\n"
os.unlink(target) os.unlink(target)
sys.exit(1) sys.exit(1)
print "done"
return r == 0 return r == 0

View file

@ -19,7 +19,7 @@ def get_bzr_version():
setup( setup(
name="pandora_client", name="pandora_client",
version="0.0.%s" % get_bzr_version() , version="0.2.%s" % get_bzr_version() ,
description='''pandora_client - commandline client and python api for pan.do/ra description='''pandora_client - commandline client and python api for pan.do/ra
can be used interact with pan.do/ra instance via its api. can be used interact with pan.do/ra instance via its api.