Answers.Body: <p>Possible solution (which worked for me):</p>
  <ul>
  <li>generate calibre's ToC(as html) from correct toc.ncx (if not arleady exist)</li>
  <li>unpack epub</li>
  <li>re-import only html toc,</li>
  <li>convert result to epub</li>
  <li>if order is incorrect yet again - check Calibre's HTML-ZIP importer depth-first/breadth first mode</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-12T08:13:54.640Z
Answers.LastActivityDate: 2020-10-12T08:13:54.640Z
Answers.UserDisplayName: Tauri
Body: <p>I do have epub2 book with wrong spine (files in it are also in wrong order).
  I was able semi-automatically to fix correct order and create correct toc.ncx.
  Each file contains one or zero chapters linked from toc.ncx, they mostly have correct title tags</p>
  <p>It would be very difficult to do reordering manually in Calibre or Sigil(book have a lot of files) so I'm looking to automated/semiautomated solution.</p>
  <p>How to change spine (and, preferable,order of files in epub) to be in toc.ncx order?
  How to at least rename chapter files from index_&lt;random_digits&gt; to their real titles so manual re-ordering would be easier?</p>
  <p>If there is no existing tools - which python libraries can be used to get access to toc.ncx and to perform reordering?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-09T18:00:06.503Z
Comments.Text: Could you attach a link to such file?
Comments.UserDisplayName: olha
Tags: <epub>
Title: fix spine order and file names based on toc.ncx
UserDisplayName: Tauri
ThreadText: # fix spine order and file names based on toc.ncx
  
  (Asked by: username_0 on 2020-10-03)
  
  I do have epub2 book with wrong spine (files in it are also in wrong order).
  I was able semi-automatically to fix correct order and create correct toc.ncx.
  Each file contains one or zero chapters linked from toc.ncx, they mostly have correct title tags
  
  It would be very difficult to do reordering manually in Calibre or Sigil(book have a lot of files) so I'm looking to automated/semiautomated solution.
  
  How to change spine (and, preferable,order of files in epub) to be in toc.ncx order?
  How to at least rename chapter files from index\_ to their real titles so manual re-ordering would be easier?
  
  If there is no existing tools - which python libraries can be used to get access to toc.ncx and to perform reordering?
  
  **Tags:** epub
  
  > **Comments:**
  > **username_1**: Could you attach a link to such file?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-10-12. Score: 0
  
  Possible solution (which worked for me):
  
  * generate calibre's ToC(as html) from correct toc.ncx (if not arleady exist)
  * unpack epub
  * re-import only html toc,
  * convert result to epub
  * if order is incorrect yet again - check Calibre's HTML-ZIP importer depth-first/breadth first mode
  
  
  ---
  
  