MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   suggestion: plugin to remove spaces (https://www.mobileread.com/forums/showthread.php?t=261171)

Toxaris 05-29-2015 02:50 PM

suggestion: plugin to remove spaces
 
What about a plugin to remove spaces in filenames of XHTML and/or images? Or perhaps replacing them by an underscore?

Should not be too difficult I think, but I am not a Python expert. Could be very useful in case of a lot of files...

DiapDealer 05-30-2015 10:40 AM

Are you thinking of an automated "everything in one fell swoop" kind of thing? I only ask because renaming files in the book browser will take care of updating all links to it.

rubeus 05-30-2015 01:09 PM

How to handle these filenames:

chapter 01.html
chapter_01.html

in the same book?

theducks 05-30-2015 02:41 PM

Quote:

Originally Posted by rubeus (Post 3110025)
How to handle these filenames:

chapter 01.html
chapter_01.html

in the same book?

2 steps/passes should do it (but you will lose the names)
Select the Range: Change the names to something generic to avoid clashes

Now rename those to the final sequenced names

BTW the bulk renamer allows you to skip files


sec01
sec02
p01 <not selected
sec03
sec04
p02 <not selected

Toxaris 05-30-2015 02:55 PM

Quote:

Originally Posted by DiapDealer (Post 3109972)
Are you thinking of an automated "everything in one fell swoop" kind of thing? I only ask because renaming files in the book browser will take care of updating all links to it.

Yup. The updating of the links would be the tricky part, especially for the images.

KevinH 05-30-2015 03:13 PM

Actually, this is not easy as it sounds in that you must go through every link/anchor/aside/footnote, etc in every xhtml file looking for changed file names in internal links.

The code to actually do exactly this is built into Sigil in a C++ routine that performs UniversalUpdates and it is run when the epub is first loaded since the paths to the files will change due to being moved into the epub directory structure used by Sigil.

In the end, it might be easier to change the builtin updates routine then to recreate all of that code in a plugin.

KevinH

Toxaris 05-30-2015 07:32 PM

Quote:

Originally Posted by KevinH (Post 3110078)
Actually, this is not easy as it sounds in that you must go through every link/anchor/aside/footnote, etc in every xhtml file looking for changed file names in internal links.

The code to actually do exactly this is built into Sigil in a C++ routine that performs UniversalUpdates and it is run when the epub is first loaded since the paths to the files will change due to being moved into the epub directory structure used by Sigil.

In the end, it might be easier to change the builtin updates routine then to recreate all of that code in a plugin.

KevinH

So it will be core Sigil as of 0.9? :D

Just kidding...:2thumbsup

kovidgoyal 05-31-2015 11:30 PM

Just FYI, this would be five lines of code if you were making a plugin for the calibre editor (not counting the boilerplate for the plugin)

Code:

    from calibre.ebooks.oeb.polish.replace import rename_files
    book = self.current_container
    fmap = {f:f.replace(' ', '_') for f in book.manifest_id_map.itervalues() if ' ' in f}
    if fmap:
        rename_files(book, fmap)

Just replace the call to self.magnify_fonts() with the above code in the demo plugin http://manual.calibre-ebook.com/crea...t-book-plugins

and you are done.

KevinH 06-01-2015 12:12 AM

Hmm ... since all of the real work is done in rename_files for Calibre, that is very true. I think I could do something similar by extending the Sigil launcher interface and have it call the rename file code inside Sigil in a similar manner.

But I still think the easiest Sigil-based solution is to simply take care of that when the epub is first loaded. So if you are in need of a plugin quickly, doing what Kovid recommended in Calibre is probably the way to go until/if we release this feature in future version on Sigil assuming there is demand for it.

Thanks Kovid!
KevinH


All times are GMT -4. The time now is 08:30 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.