Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ebook bad ordering #30

Open
dyskette opened this issue Mar 27, 2017 · 0 comments
Open

Ebook bad ordering #30

dyskette opened this issue Mar 27, 2017 · 0 comments

Comments

@dyskette
Copy link

dyskette commented Mar 27, 2017

I have an ebook that when opened with ebook-viewer ends with files in the wrong order.

You can test it with this epub I created in sigil.

Change the extension to .epub: test.txt

Edit: In the meantime, I did this change using "spine". It works for me™.

diff --git a/src/workers/content_provider.py b/src/workers/content_provider.py
index 691c93b..0fc91b7 100644
--- a/src/workers/content_provider.py
+++ b/src/workers/content_provider.py
@@ -198,11 +198,17 @@ class ContentProvider:
         ncx_file_path = self.__get_ncx_file_path
         metadata = self.__get_metadata
         __files = []
+        __files_id = []
         self.chapter_links = []
         chapter_order = []
         for x in metadata.manifest.item:
             if x.media_type == "application/xhtml+xml":
                 __files.append(x.href)
+                __files_id.append(x.id)
+
+        spine_ids = []
+        for x in metadata.spine.itemref:
+            spine_ids.append(x.idref)
 
         self.titles = []
         if os.access(ncx_file_path, os.R_OK):  # Checks if NCX is accessible
@@ -247,14 +253,12 @@ class ContentProvider:
             for i in range(len(self.titles)):
                 self.titles[i] = [self.titles[i], self.chapter_links[i]]
 
-            # If not all all files are chaptered append them
-            # chater_number = 1;
-            if len(__files) > len(self.chapter_links):
-                for i in range(len(__files)):
-                    if __files[i] not in self.chapter_links:
-                        self.chapter_links.insert(i, __files[i])
-                        # self.titles.insert(i, "Unnamed chapter" + " (" + str(chater_number) + ")")
-                        # chater_number += 1;
+            # Rebuild chapter_links
+            self.chapter_links = []
+            if len(spine_ids) > len(self.chapter_links):
+                for i in range(len(spine_ids)):
+                    if spine_ids[i] in __files_id:
+                        self.chapter_links.append(__files[__files_id.index(spine_ids[i])])
 
             # Print some debug
             print("Files: " + str(__files))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant