mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2025-12-06 08:52:55 +01:00
Ended up modifying the removeEntities function to do a weird decode/encode step on the text passed in. This seems to at least stop things from crashing..
542 lines
16 KiB
Python
542 lines
16 KiB
Python
# -*- coding: utf-8 -*-
|
||
|
||
CSS = '''body { margin-left: 5%; margin-right: 5%; margin-top: 5%; margin-bottom: 5%; text-align: justify; }
|
||
pre { font-size: x-small; }
|
||
sml { font-size: small; }
|
||
h1 { text-align: center; }
|
||
h2 { text-align: center; }
|
||
h3 { text-align: center; }
|
||
h4 { text-align: center; }
|
||
h5 { text-align: center; }
|
||
h6 { text-align: center; }
|
||
h7 { text-align: left; font-size: large; font-weight: bold; }
|
||
.CI {
|
||
text-align:center;
|
||
margin-top:0px;
|
||
margin-bottom:0px;
|
||
padding:0px;
|
||
}
|
||
.center {text-align: center;}
|
||
.cover {text-align: center;}
|
||
.full {width: 100%; }
|
||
.quarter {width: 25%; }
|
||
.smcap {font-variant: small-caps;}
|
||
.u {text-decoration: underline;}
|
||
.bold {font-weight: bold;}
|
||
'''
|
||
|
||
MIMETYPE = '''application/epub+zip'''
|
||
|
||
TITLE_HEADER = '''<?xml version="1.0" encoding="utf-8"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||
<title>%s - %s</title><link href="stylesheet.css" type="text/css" charset="UTF-8" rel="stylesheet"/></head><body>
|
||
<p><h7 id="lnks"><b><a id="StoryLink" href="%s">%s</a></b> by <b><a id="AuthorLink" href="%s">%s</a></b></h7></p>
|
||
<table class="full">
|
||
'''
|
||
|
||
TITLE_ENTRY = '''<tr><td><b>%s</b></td><td>%s</td></tr>
|
||
'''
|
||
|
||
TITLE_FOOTER = '''</table>
|
||
<p><b>Summary:</b><br />%s</p>
|
||
</body></html>
|
||
'''
|
||
|
||
CONTAINER = '''<?xml version="1.0" encoding="utf-8"?>
|
||
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
|
||
<rootfiles>
|
||
<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
|
||
</rootfiles>
|
||
</container>
|
||
'''
|
||
|
||
CONTENT_START = '''<?xml version="1.0" encoding="utf-8"?>
|
||
<package version="2.0" xmlns="http://www.idpf.org/2007/opf"
|
||
unique-identifier="fanficdownloader-uuid">
|
||
<metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||
xmlns:dcterms="http://purl.org/dc/terms/"
|
||
xmlns:opf="http://www.idpf.org/2007/opf"
|
||
xmlns:calibre="http://calibre.kovidgoyal.net/2009/metadata">
|
||
<dc:identifier id="fanficdownloader-uuid">BookID-Epub-%s</dc:identifier>
|
||
<dc:title>%s</dc:title>
|
||
<dc:creator opf:role="aut">%s</dc:creator>
|
||
<dc:contributor opf:role="bkp">fanficdownloader [http://fanficdownloader.googlecode.com]</dc:contributor>
|
||
<dc:language>%s</dc:language>
|
||
<dc:rights></dc:rights>
|
||
<dc:date opf:event="publication">%s</dc:date>
|
||
<dc:date opf:event="creation">%s</dc:date>
|
||
<dc:date opf:event="modification">%s</dc:date>
|
||
<meta name="calibre:timestamp" content="%s"/>
|
||
<dc:description>%s</dc:description>
|
||
'''
|
||
|
||
CONTENT_END_METADATA = ''' <dc:publisher>%s</dc:publisher>
|
||
<dc:identifier id="BookId">%s</dc:identifier>
|
||
<dc:identifier opf:scheme="URL">%s</dc:identifier>
|
||
<dc:source>%s</dc:source>
|
||
<dc:type>FanFiction</dc:type>
|
||
<meta name="calibre:rating" content="%s"/>
|
||
</metadata>
|
||
<manifest>
|
||
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
|
||
<item id="style" href="stylesheet.css" media-type="text/css" />
|
||
'''
|
||
|
||
CONTENT_SUBJECT = ''' <dc:subject>%s</dc:subject>
|
||
'''
|
||
|
||
CONTENT_ITEM = ''' <item id="%s" href="%s" media-type="application/xhtml+xml" />
|
||
'''
|
||
|
||
CONTENT_END_MANIFEST = ''' </manifest>
|
||
<spine toc="ncx">
|
||
'''
|
||
|
||
CONTENT_ITEMREF = ''' <itemref idref="%s" />
|
||
'''
|
||
|
||
CONTENT_END = ''' </spine>
|
||
</package>
|
||
'''
|
||
|
||
TOC_START = '''<?xml version="1.0" encoding="UTF-8"?>
|
||
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
|
||
<head>
|
||
<meta name="dtb:uid" content="%s"/>
|
||
<meta name="dtb:depth" content="1"/>
|
||
<meta name="dtb:totalPageCount" content="0"/>
|
||
<meta name="dtb:maxPageNumber" content="0"/>
|
||
</head>
|
||
<docTitle>
|
||
<text>%s</text>
|
||
</docTitle>
|
||
<navMap>
|
||
'''
|
||
|
||
TOC_ITEM = '''<navPoint id="%s" playOrder="%d">
|
||
<navLabel>
|
||
<text>%s</text>
|
||
</navLabel>
|
||
<content src="%s"/>
|
||
</navPoint>
|
||
'''
|
||
|
||
TOC_END = '''</navMap>
|
||
</ncx>
|
||
'''
|
||
|
||
XHTML_START = '''<?xml version="1.0" encoding="UTF-8"?>
|
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
<head>
|
||
<title>%s</title>
|
||
<link href="stylesheet.css" type="text/css" rel="stylesheet" />
|
||
</head>
|
||
<body>
|
||
<div>
|
||
<h3>%s</h3>
|
||
'''
|
||
|
||
XHTML_END = '''</div>
|
||
</body>
|
||
</html>
|
||
'''
|
||
|
||
acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area', 'b', 'big',
|
||
'blockquote', 'br', 'center', 'cite', 'code', 'col',
|
||
'colgroup', 'dd', 'del', 'dfn', 'dir', 'dl', 'dt', 'em',
|
||
'font', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i',
|
||
'ins', 'kbd', 'label', 'li', 'ol',
|
||
'p', 'pre', 'q', 's', 'samp', 'small', 'span', 'strike',
|
||
'strong', 'sub', 'sup', 'u', 'ul']
|
||
|
||
acceptable_attributes = ['href']
|
||
|
||
# entity list from http://code.google.com/p/doctype/wiki/CharacterEntitiesConsistent
|
||
entities = { 'á' : 'á',
|
||
'Á' : 'Á',
|
||
'Á' : 'Á',
|
||
'á' : 'á',
|
||
'â' : 'â',
|
||
'Â' : 'Â',
|
||
'Â' : 'Â',
|
||
'â' : 'â',
|
||
'´' : '´',
|
||
'´' : '´',
|
||
'Æ' : 'Æ',
|
||
'æ' : 'æ',
|
||
'Æ' : 'Æ',
|
||
'æ' : 'æ',
|
||
'à' : 'à',
|
||
'À' : 'À',
|
||
'À' : 'À',
|
||
'à' : 'à',
|
||
'ℵ' : 'ℵ',
|
||
'α' : 'α',
|
||
'Α' : 'Α',
|
||
'&' : '&',
|
||
'&' : '&',
|
||
'&' : '&',
|
||
'&' : '&',
|
||
'∧' : '∧',
|
||
'∠' : '∠',
|
||
'å' : 'å',
|
||
'Å' : 'Å',
|
||
'Å' : 'Å',
|
||
'å' : 'å',
|
||
'≈' : '≈',
|
||
'ã' : 'ã',
|
||
'Ã' : 'Ã',
|
||
'Ã' : 'Ã',
|
||
'ã' : 'ã',
|
||
'ä' : 'ä',
|
||
'Ä' : 'Ä',
|
||
'Ä' : 'Ä',
|
||
'ä' : 'ä',
|
||
'„' : '„',
|
||
'β' : 'β',
|
||
'Β' : 'Β',
|
||
'¦' : '¦',
|
||
'¦' : '¦',
|
||
'•' : '•',
|
||
'∩' : '∩',
|
||
'ç' : 'ç',
|
||
'Ç' : 'Ç',
|
||
'Ç' : 'Ç',
|
||
'ç' : 'ç',
|
||
'¸' : '¸',
|
||
'¸' : '¸',
|
||
'¢' : '¢',
|
||
'¢' : '¢',
|
||
'χ' : 'χ',
|
||
'Χ' : 'Χ',
|
||
'ˆ' : 'ˆ',
|
||
'♣' : '♣',
|
||
'≅' : '≅',
|
||
'©' : '©',
|
||
'©' : '©',
|
||
'©' : '©',
|
||
'©' : '©',
|
||
'↵' : '↵',
|
||
'∪' : '∪',
|
||
'¤' : '¤',
|
||
'¤' : '¤',
|
||
'†' : '†',
|
||
'‡' : '‡',
|
||
'↓' : '↓',
|
||
'⇓' : '⇓',
|
||
'°' : '°',
|
||
'°' : '°',
|
||
'δ' : 'δ',
|
||
'Δ' : 'Δ',
|
||
'♦' : '♦',
|
||
'÷' : '÷',
|
||
'÷' : '÷',
|
||
'é' : 'é',
|
||
'É' : 'É',
|
||
'É' : 'É',
|
||
'é' : 'é',
|
||
'ê' : 'ê',
|
||
'Ê' : 'Ê',
|
||
'Ê' : 'Ê',
|
||
'ê' : 'ê',
|
||
'è' : 'è',
|
||
'È' : 'È',
|
||
'È' : 'È',
|
||
'è' : 'è',
|
||
'∅' : '∅',
|
||
' ' : ' ',
|
||
' ' : ' ',
|
||
'ε' : 'ε',
|
||
'Ε' : 'Ε',
|
||
'≡' : '≡',
|
||
'η' : 'η',
|
||
'Η' : 'Η',
|
||
'ð' : 'ð',
|
||
'Ð' : 'Ð',
|
||
'Ð' : 'Ð',
|
||
'ð' : 'ð',
|
||
'ë' : 'ë',
|
||
'Ë' : 'Ë',
|
||
'Ë' : 'Ë',
|
||
'ë' : 'ë',
|
||
'€' : '€',
|
||
'∃' : '∃',
|
||
'ƒ' : 'ƒ',
|
||
'∀' : '∀',
|
||
'½' : '½',
|
||
'½' : '½',
|
||
'¼' : '¼',
|
||
'¼' : '¼',
|
||
'¾' : '¾',
|
||
'¾' : '¾',
|
||
'⁄' : '⁄',
|
||
'γ' : 'γ',
|
||
'Γ' : 'Γ',
|
||
'≥' : '≥',
|
||
'>' : '>',
|
||
'>' : '>',
|
||
'>' : '>',
|
||
'>' : '>',
|
||
'↔' : '↔',
|
||
'⇔' : '⇔',
|
||
'♥' : '♥',
|
||
'…' : '…',
|
||
'í' : 'í',
|
||
'Í' : 'Í',
|
||
'Í' : 'Í',
|
||
'í' : 'í',
|
||
'î' : 'î',
|
||
'Î' : 'Î',
|
||
'Î' : 'Î',
|
||
'î' : 'î',
|
||
'¡' : '¡',
|
||
'¡' : '¡',
|
||
'ì' : 'ì',
|
||
'Ì' : 'Ì',
|
||
'Ì' : 'Ì',
|
||
'ì' : 'ì',
|
||
'ℑ' : 'ℑ',
|
||
'∞' : '∞',
|
||
'∫' : '∫',
|
||
'ι' : 'ι',
|
||
'Ι' : 'Ι',
|
||
'¿' : '¿',
|
||
'¿' : '¿',
|
||
'∈' : '∈',
|
||
'ï' : 'ï',
|
||
'Ï' : 'Ï',
|
||
'Ï' : 'Ï',
|
||
'ï' : 'ï',
|
||
'κ' : 'κ',
|
||
'Κ' : 'Κ',
|
||
'λ' : 'λ',
|
||
'Λ' : 'Λ',
|
||
'«' : '«',
|
||
'«' : '«',
|
||
'←' : '←',
|
||
'⇐' : '⇐',
|
||
'⌈' : '⌈',
|
||
'“' : '“',
|
||
'≤' : '≤',
|
||
'⌊' : '⌊',
|
||
'∗' : '∗',
|
||
'◊' : '◊',
|
||
'‎' : '',
|
||
'‹' : '‹',
|
||
'‘' : '‘',
|
||
'<' : '<',
|
||
'<' : '<',
|
||
'<' : '<',
|
||
'<' : '<',
|
||
'¯' : '¯',
|
||
'¯' : '¯',
|
||
'—' : '—',
|
||
'µ' : 'µ',
|
||
'µ' : 'µ',
|
||
'·' : '·',
|
||
'·' : '·',
|
||
'−' : '−',
|
||
'μ' : 'μ',
|
||
'Μ' : 'Μ',
|
||
'∇' : '∇',
|
||
' ' : ' ',
|
||
' ' : ' ',
|
||
'–' : '–',
|
||
'≠' : '≠',
|
||
'∋' : '∋',
|
||
'¬' : '¬',
|
||
'¬' : '¬',
|
||
'∉' : '∉',
|
||
'⊄' : '⊄',
|
||
'ñ' : 'ñ',
|
||
'Ñ' : 'Ñ',
|
||
'Ñ' : 'Ñ',
|
||
'ñ' : 'ñ',
|
||
'ν' : 'ν',
|
||
'Ν' : 'Ν',
|
||
'ó' : 'ó',
|
||
'Ó' : 'Ó',
|
||
'Ó' : 'Ó',
|
||
'ó' : 'ó',
|
||
'ô' : 'ô',
|
||
'Ô' : 'Ô',
|
||
'Ô' : 'Ô',
|
||
'ô' : 'ô',
|
||
'Œ' : 'Œ',
|
||
'œ' : 'œ',
|
||
'ò' : 'ò',
|
||
'Ò' : 'Ò',
|
||
'Ò' : 'Ò',
|
||
'ò' : 'ò',
|
||
'‾' : '‾',
|
||
'ω' : 'ω',
|
||
'Ω' : 'Ω',
|
||
'ο' : 'ο',
|
||
'Ο' : 'Ο',
|
||
'⊕' : '⊕',
|
||
'∨' : '∨',
|
||
'ª' : 'ª',
|
||
'ª' : 'ª',
|
||
'º' : 'º',
|
||
'º' : 'º',
|
||
'ø' : 'ø',
|
||
'Ø' : 'Ø',
|
||
'Ø' : 'Ø',
|
||
'ø' : 'ø',
|
||
'õ' : 'õ',
|
||
'Õ' : 'Õ',
|
||
'Õ' : 'Õ',
|
||
'õ' : 'õ',
|
||
'⊗' : '⊗',
|
||
'ö' : 'ö',
|
||
'Ö' : 'Ö',
|
||
'Ö' : 'Ö',
|
||
'ö' : 'ö',
|
||
'¶' : '¶',
|
||
'¶' : '¶',
|
||
'∂' : '∂',
|
||
'‰' : '‰',
|
||
'⊥' : '⊥',
|
||
'φ' : 'φ',
|
||
'Φ' : 'Φ',
|
||
'π' : 'π',
|
||
'Π' : 'Π',
|
||
'ϖ' : 'ϖ',
|
||
'±' : '±',
|
||
'±' : '±',
|
||
'£' : '£',
|
||
'£' : '£',
|
||
'′' : '′',
|
||
'″' : '″',
|
||
'∏' : '∏',
|
||
'∝' : '∝',
|
||
'ψ' : 'ψ',
|
||
'Ψ' : 'Ψ',
|
||
'"' : '"',
|
||
'"' : '"',
|
||
'"' : '"',
|
||
'"' : '"',
|
||
'√' : '√',
|
||
'»' : '»',
|
||
'»' : '»',
|
||
'→' : '→',
|
||
'⇒' : '⇒',
|
||
'⌉' : '⌉',
|
||
'”' : '”',
|
||
'ℜ' : 'ℜ',
|
||
'®' : '®',
|
||
'®' : '®',
|
||
'®' : '®',
|
||
'®' : '®',
|
||
'⌋' : '⌋',
|
||
'ρ' : 'ρ',
|
||
'Ρ' : 'Ρ',
|
||
'‏' : '',
|
||
'›' : '›',
|
||
'’' : '’',
|
||
'‚' : '‚',
|
||
'š' : 'š',
|
||
'Š' : 'Š',
|
||
'⋅' : '⋅',
|
||
'§' : '§',
|
||
'§' : '§',
|
||
'­' : '', # strange optional hyphenation control character, not just a dash
|
||
'­' : '',
|
||
'σ' : 'σ',
|
||
'Σ' : 'Σ',
|
||
'ς' : 'ς',
|
||
'∼' : '∼',
|
||
'♠' : '♠',
|
||
'⊂' : '⊂',
|
||
'⊆' : '⊆',
|
||
'∑' : '∑',
|
||
'¹' : '¹',
|
||
'¹' : '¹',
|
||
'²' : '²',
|
||
'²' : '²',
|
||
'³' : '³',
|
||
'³' : '³',
|
||
'⊃' : '⊃',
|
||
'⊇' : '⊇',
|
||
'ß' : 'ß',
|
||
'ß' : 'ß',
|
||
'τ' : 'τ',
|
||
'Τ' : 'Τ',
|
||
'∴' : '∴',
|
||
'θ' : 'θ',
|
||
'Θ' : 'Θ',
|
||
'ϑ' : 'ϑ',
|
||
' ' : ' ',
|
||
'þ' : 'þ',
|
||
'Þ' : 'Þ',
|
||
'Þ' : 'Þ',
|
||
'þ' : 'þ',
|
||
'˜' : '˜',
|
||
'×' : '×',
|
||
'×' : '×',
|
||
'™' : '™',
|
||
'ú' : 'ú',
|
||
'Ú' : 'Ú',
|
||
'Ú' : 'Ú',
|
||
'ú' : 'ú',
|
||
'↑' : '↑',
|
||
'⇑' : '⇑',
|
||
'û' : 'û',
|
||
'Û' : 'Û',
|
||
'Û' : 'Û',
|
||
'û' : 'û',
|
||
'ù' : 'ù',
|
||
'Ù' : 'Ù',
|
||
'Ù' : 'Ù',
|
||
'ù' : 'ù',
|
||
'¨' : '¨',
|
||
'¨' : '¨',
|
||
'ϒ' : 'ϒ',
|
||
'υ' : 'υ',
|
||
'Υ' : 'Υ',
|
||
'ü' : 'ü',
|
||
'Ü' : 'Ü',
|
||
'Ü' : 'Ü',
|
||
'ü' : 'ü',
|
||
'℘' : '℘',
|
||
'ξ' : 'ξ',
|
||
'Ξ' : 'Ξ',
|
||
'ý' : 'ý',
|
||
'Ý' : 'Ý',
|
||
'Ý' : 'Ý',
|
||
'ý' : 'ý',
|
||
'¥' : '¥',
|
||
'¥' : '¥',
|
||
'ÿ' : 'ÿ',
|
||
'Ÿ' : 'Ÿ',
|
||
'ÿ' : 'ÿ',
|
||
'ζ' : 'ζ',
|
||
'Ζ' : 'Ζ',
|
||
'‍' : '', # strange spacing control character, not just a space
|
||
'‌' : '', # strange spacing control character, not just a space
|
||
}
|
||
|
||
FB2_PROLOGUE = '<FictionBook>'
|
||
FB2_DESCRIPTION = '''<description>
|
||
<title-info>
|
||
<genre>fanfiction</genre>
|
||
<author>
|
||
<first-name></first-name>
|
||
<middle-name></middle-name>
|
||
<last-name>%s</last-name>
|
||
</author>
|
||
<book-title>%s</book-title>
|
||
<lang>eng</lang>
|
||
</title-info>
|
||
<document-info>
|
||
<author>
|
||
<nickname>sgzmd</nickname>
|
||
</author>
|
||
<date value="%s">%s</date>
|
||
<id>sgzmd_%s</id>
|
||
<version>2.0</version>
|
||
</document-info>
|
||
</description>'''
|
||
|
||
HTML_ESC_Definitions = 'HTML_Escape.def'
|