]> git.parisson.com Git - telemeta.git/commitdiff
Finally fix corpus import and EPUB3 export for Castellengo's AubioBook project
authorGuillaume Pellerin <yomguy@parisson.com>
Fri, 1 May 2015 01:13:44 +0000 (03:13 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Fri, 1 May 2015 01:13:44 +0000 (03:13 +0200)
telemeta/management/commands/telemeta-import-corpus-from-dir.py
telemeta/views/resource.py

index 539ac87eb5a58d6f6f4cf19ae3a2d1bc48310d42..ee9cf108a98cc594da0e52357e6ae56b79c9e463 100644 (file)
@@ -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):
index 73ea30d0a34b939b2cda41fea9975f9372ad54cd..c54bd2cce2f97003934080642a70b12b11975e14 100644 (file)
@@ -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]))