use config for resolution, only upload frames if enabled

This commit is contained in:
j 2011-12-20 15:59:43 +05:30
parent e68dd56dda
commit 015e76619a

View file

@ -58,6 +58,7 @@ class Client(object):
else: else:
self._config = config self._config = config
self.api = API(self._config['url'], media_cache=self.media_cache()) self.api = API(self._config['url'], media_cache=self.media_cache())
self.api.DEBUG = DEBUG
self.signin() self.signin()
conn, c = self._conn() conn, c = self._conn()
@ -93,6 +94,9 @@ class Client(object):
conn.text_factory = sqlite3.OptimizedUnicode conn.text_factory = sqlite3.OptimizedUnicode
return conn, conn.cursor() return conn, conn.cursor()
def get_profile(self):
return "%sp.webm" % max(self.api._config['video']['resolutions'])
def media_cache(self): def media_cache(self):
return os.path.expanduser(self._config.get('media-cache', default_media_cache)) return os.path.expanduser(self._config.get('media-cache', default_media_cache))
@ -124,6 +128,9 @@ class Client(object):
self.user = False self.user = False
print 'login failed' print 'login failed'
return False return False
r = self.api.init()
if r['status']['code'] == 200:
self.api._config = r['data']['site']
return True return True
def scan_file(self, path): def scan_file(self, path):
@ -195,8 +202,7 @@ class Client(object):
else: else:
volumes[name]['available'] = False volumes[name]['available'] = False
profile = self.api.encodingProfile()['data']['profile'] profile = self.get_profile()
#profile = '480p.webm'
for name in volumes: for name in volumes:
if volumes[name]['available']: if volumes[name]['available']:
prefix = volumes[name]['path'] prefix = volumes[name]['path']
@ -363,23 +369,23 @@ class API(ox.API):
if not i: if not i:
print "failed" print "failed"
return return
print i
#upload frames #upload frames
form = ox.MultiPartForm() if self._config['media']['importPosterFrames']:
form.add_field('action', 'upload') form = ox.MultiPartForm()
form.add_field('id', i['oshash']) form.add_field('action', 'upload')
for key in data: form.add_field('id', i['oshash'])
form.add_field(key, data[key]) for key in data:
for frame in i['frames']: form.add_field(key, data[key])
fname = os.path.basename(frame) for frame in i['frames']:
if os.path.exists(frame): fname = os.path.basename(frame)
form.add_file('frame', fname, open(frame, 'rb')) if os.path.exists(frame):
print self.url form.add_file('frame', fname, open(frame, 'rb'))
r = self._json_request(self.url, form) r = self._json_request(self.url, form)
#upload video
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']
if DEBUG:
print "upload video in chunks", url
ogg = Firefogg(cj=self._cj, debug=True) ogg = Firefogg(cj=self._cj, debug=True)
if not ogg.upload(url, i['video'], data): if not ogg.upload(url, i['video'], data):
if DEBUG: if DEBUG: