From: Guillaume Pellerin Date: Fri, 1 May 2015 01:13:44 +0000 (+0200) Subject: Finally fix corpus import and EPUB3 export for Castellengo's AubioBook project X-Git-Tag: 1.6a~4^2~92^2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5801fa9391175b4f602ae0e7c2b473c6d50bf412;p=telemeta.git Finally fix corpus import and EPUB3 export for Castellengo's AubioBook project --- diff --git a/telemeta/management/commands/telemeta-import-corpus-from-dir.py b/telemeta/management/commands/telemeta-import-corpus-from-dir.py index 539ac87e..ee9cf108 100644 --- a/telemeta/management/commands/telemeta-import-corpus-from-dir.py +++ b/telemeta/management/commands/telemeta-import-corpus-from-dir.py @@ -79,13 +79,16 @@ class Command(BaseCommand): for root, dirs, files in os.walk(chapter_dir): for media_file in files: path = os.path.join(root, media_file) - - if ' ' in media_file: - new_media_file = media_file.replace(' ', '_') + print path + new_media_file = slugify(unicode(media_file.decode('utf8'))) + if new_media_file[-3] != '.': + new_media_file = new_media_file[:-3] + '.' + new_media_file[-3:] + print new_media_file + if new_media_file != media_file: new_media_path = os.path.join(root, new_media_file) os.rename(path, new_media_path) media_file = new_media_file - print media_file + print 'renaming: ' + media_file media_name = os.path.splitext(media_file)[0] media_ext = os.path.splitext(media_file)[1][1:] @@ -119,11 +122,12 @@ class Command(BaseCommand): item.save() title = data[0].split('.') - item.title = title[0] + item.title = title[0].replace('\n', '') print data - item.track = data[1].replace('\n', '') + if len(data) > 1: + item.track = data[1].replace('\n', '') if len(title) > 1: - item.comment = '. '.join(title[1:]) + item.comment = '. '.join(title[1:]) item.save() for related_file in os.listdir(root): diff --git a/telemeta/views/resource.py b/telemeta/views/resource.py index 73ea30d0..c54bd2cc 100644 --- a/telemeta/views/resource.py +++ b/telemeta/views/resource.py @@ -398,7 +398,9 @@ class CorpusEpubView(View): id = item.old_code.split('.')[1] else: id = item.old_code - id = id.replace('a', '.1').replace('b', '.2') + for c in id: + if c.isalpha(): + id = id.replace(c, '.' + str(ord(c)-96)) items[item] = float(id) items = OrderedDict(sorted(items.items(), key=lambda t: t[1]))