load defaults from defaults.json if it exists

This commit is contained in:
j 2014-09-19 11:57:11 +02:00
parent 0cbc44bd5e
commit 9b63c03ceb

View file

@ -46,6 +46,20 @@ class Incoming(object):
def import_media(self, f):
filename = os.path.basename(f)
defaults = self.config['defaults']
# try to load default values from tree
folder = os.path.dirname(f)
while len(folder) > len(self.config['folder']):
defaults_json = os.path.join(folder, 'defaults.json')
if os.path.exists(defaults_json):
try:
with open(defaults_json) as fd:
defaults = json.load(fd)
break
except:
pass
folder = os.path.dirname(folder)
# register file with pan.do/ra
info = ox.avinfo(f)
@ -68,7 +82,7 @@ class Incoming(object):
# update item with default metadata
item = r['data']['item']
item_info = {'id': item}
item_info.update(self.config['defaults'])
item_info.update(defaults)
self.api.edit(item_info)
# upload media file