set language on main stream. fix language parsing

This commit is contained in:
j 2014-09-03 14:35:34 +02:00
parent 6bf21fa5c9
commit 6949cab8c6

View file

@ -442,6 +442,16 @@ class File(models.Model):
''' '''
extract audio tracks from direct upload extract audio tracks from direct upload
''' '''
def parse_language(lang):
if lang:
short = ox.iso.langCode3To2(lang.encode('utf-8'))
if not short and ox.iso.codeToLang(lang[:2]):
lang = lang[:2]
else:
lang = short
if not lang:
lang = settings.CONFIG['language']
return lang
audio = self.info.get('audio', []) audio = self.info.get('audio', [])
if self.data and len(audio) > 1: if self.data and len(audio) > 1:
config = settings.CONFIG['video'] config = settings.CONFIG['video']
@ -450,14 +460,14 @@ class File(models.Model):
if ffmpeg == 'ffmpeg': if ffmpeg == 'ffmpeg':
ffmpeg = None ffmpeg = None
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
languages = [settings.CONFIG['language']] if not self.info.get('language'):
self.info['language'] = parse_language(audio[0].get('language'))
self.save()
languages = [self.info['language']]
for i, a in enumerate(audio[1:]): for i, a in enumerate(audio[1:]):
media = self.data.path media = self.data.path
info = ox.avinfo(media) info = ox.avinfo(media)
lang = ox.iso.langCode3To2(a.get('language', u'und').encode('utf-8')) language = parse_language(a.get('language'))
if not lang:
lang = settings.CONFIG['language']
language = lang
n = 2 n = 2
while language in languages: while language in languages:
language = '%s%d' % (lang, n) language = '%s%d' % (lang, n)