No, I see issue.
Code:
apath = os.path.normcase(apath)
For example:
titlemap says "OEBPS/
introducao.xhtml",
but the bookpath says "OEBPS/
Introducao.xhtml".
Since the bookpath in the titlemap is different than the actual name in the EPUB file – the condition is not met and the title is not inserted.
---
Edit: If the xhtml file name is written in lowercase (e.g. toc.xhtml) then the title is inserted because the bookpath matches the titlemap.