#!/bin/mksh # $MirOS: contrib/hosted/tg/unepub,v 1.2 2012/02/07 20:29:33 tg Exp $ #- # Copyright (c) 2011, 2012 # Thorsten Glaser # # Provided that these terms and disclaimer and all copyright notices # are retained or reproduced in an accompanying document, permission # is granted to deal in this work without restriction, including un- # limited rights to use, publicly perform, distribute, sell, modify, # merge, give away, or sublicence. # # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to # the utmost extent permitted by applicable law, neither express nor # implied; without malicious intent or gross negligence. In no event # may a licensor, author or contributor be held liable for indirect, # direct, other damage, loss, or other issues arising in any way out # of dealing in the work, even if advised of the possibility of such # damage or existence of a defect, except proven that it results out # of said person's immediate fault when using the work as intended. #- # Convert args foo.epub, bar.epub, ... to {foo,bar...}/{*,index.htm} # using perl (easy U+00A0 fixup), unzip and xmlstarlet from ports. function ncx2html { local state texts links docTitle="" # I would use xmlstarlet sel, but it seems to be broken, or, # XPath is not obvious to learn <"$1" tr '\n\t' ' ' | sed -e 's/> * '"$docTitle"'

'"$docTitle

' } for fn in "$@"; do dn=${fn%.epub} [[ $dn = "$fn" ]] && dn=$dn.extracted mkdir -p "$dn/tmp" cd "$dn/tmp" unzip "../../$fn" cdir=$(tr -d '\n' ]*full-path="\([^"]*\)".*$/\1/p') cdir=${cdir%/*} mv "$cdir"/* .. cd .. rm -rf tmp for i in *.xhtml; do [[ -e $i ]] || continue mv "$i" "${i%.xhtml}.htm" done perl -pi -e 's/ / /g' toc.ncx *.htm* ncx2html toc.ncx >index.htm cd .. done