Permalink
Browse files

Implemented more book metadata: producer, title sort, isbn, etc.

  • Loading branch information...
1 parent cfe192a commit 6daf3132f6d392f25b1c3d69cdc98f0794e1b527 @bkidwell committed Dec 3, 2011
Showing with 61 additions and 27 deletions.
  1. +1 −1 TODO.md
  2. +1 −1 mdepub/__init__.py
  3. +35 −21 mdepub/actions/epub.py
  4. +24 −4 sample/Alice in Wonderland/options.yaml
View
@@ -1,8 +1,8 @@
# Todo
-* mdepub.actions.epub: more metadata attributes
* add checks for error conditions (missing source file, etc.)
* add action to insert/update epub file in Calibre
* add action to extract epub file from Calibre
* finalize template css file
* implement create action
+* handle 'require mdepub version' option
View
@@ -17,7 +17,7 @@
options = yaml.load(open("options.yaml"))
#print yaml.dump(options)
#print options.keys()
- if not 'filename' in options:
+ if not options.get('filename'):
options['filename'] = filename.clean(options['title'])
log.debug("Filename: %s", options['filename'])
else:
View
@@ -8,6 +8,7 @@
from zipfile import ZipFile
from BeautifulSoup import BeautifulSoup
from mdepub.filename import getFN
+import uuid
log = logging.getLogger('epub')
@@ -37,24 +38,41 @@ def run():
# Get description html from markdown
- description = shell.pipe(["pandoc"], options['description'])
+ if 'description' in options:
+ description = shell.pipe(["pandoc"], options['description'])
+ else:
+ description = ""
# Setup ebook-convert args
+ if not 'title' in options: raise "No title given in options.yaml"
args = [
"ebook-convert",
'"' + getFN("html") + '"',
'"' + getFN("epub") + '"',
- "--authors=\"%s\"" % quote(options['authors']),
- "--author-sort=\"%s\"" % quote(options['author sort']),
- "--pubdate=\"%s\"" % options['publication date'],
- "--title=\"%s\"" % quote(options['title']),
- "--tags=\"%s\"" % quote(','.join(options['tags'])),
- "--comments=\"%s\"" % quote(description)
+ "--title=\"%s\"" % quote(options['title'])
]
- args.append("--chapter=\"//h:h%s\"" % options['chapter head level'])
+ for a, b in (
+ ('author-sort', 'author sort'),
+ ('authors', 'authors'),
+ ('book-producer', 'book producer'),
+ ('isbn', 'isbn'),
+ ('language', 'language'),
+ ('pubdate', 'publication date'),
+ ('publisher', 'publisher'),
+ ('rating', 'rating'),
+ ('series', 'series'),
+ ('series-index', 'series index'),
+ ('title-sort', 'title sort'),
+ ):
+ if options.get(b): args.append("--%s=\"%s\"" % (a, options[b]))
+
+ if options.get("tags"):
+ args.append( "--tags=\"%s\"" % quote(','.join(options['tags'])) )
+
+ args.append("--chapter=\"//h:h%s\"" % (options.get('chapter head level') or 2))
tmp = []
- for i in range(options['chapter head level']):
+ for i in range(options.get('chapter head level') or 2):
if len(tmp) > 0: tmp.append("or")
tmp.append("name()='h%s'" % str(i + 1))
args.append(
@@ -70,13 +88,14 @@ def run():
if cover_filename:
args.append("--cover=%s" % cover_filename)
- if not options['stretch cover image']:
+ if not options.get('stretch cover image'):
args.append("--preserve-cover-aspect-ratio")
- for i in ['top', 'left', 'right', 'bottom']:
- if options['margin'][i] is not None:
- args.append("--margin-%s" % i)
- args.append(str(options['margin'][i]))
+ if options.get('margin'):
+ for i in ['top', 'left', 'right', 'bottom']:
+ if options['margin'].get(i) is not None:
+ args.append("--margin-%s" % i)
+ args.append(str(options['margin'][i]))
# Run ebook-convert
@@ -94,11 +113,6 @@ def run():
#metadata = zip.read("content.opf")
soup = BeautifulSoup(metadata)
id = soup.find(id="uuid_id")
- id.contents[0].replaceWith(options['uuid'])
- print soup
+ id.contents[0].replaceWith(options.get('uuid') or uuid.uuid4())
+ #print soup
zip.writestr("content.opf", str(soup))
-
-#TODO: series, series-index
-#TODO: publisher
-#TODO: language
-#TODO: rating
@@ -1,14 +1,35 @@
-require version: "0.1" # Require at least this version of mdepub
+# mdepub options file
+#
+# Specify missing or unknown values with the tilde (~) character, for example:
+# title sort: ~
+# Some missing values such as 'title sort' and 'filename' will be determined
+# automatically. Long strings containing punctuation should be enclosed in
+# double quotes. All values are optional except for 'title'.
+
+require mde version: "0.1" # Require at least this version of mdepub
title: "Alice's Adventures in Wonderland"
+title sort: ~
authors: "Lewis Carroll"
author sort: "Carroll, Lewis"
publication date: "26 Nov 1865" # must be a string D MMM YYYY
-tags: [children, fiction, fantasy]
+publisher: ~
+book producer: Brendan Kidwell
+isbn: ~
+language: English
+rating: ~ # personal rating
+series: ~ # name of the series
+series index: ~ # ordinal number within a series
uuid: 8220b2f8-0f38-11e1-962f-889ffa5498bb
+# Tags: give a list of tag names enclosed in square brackets and separated by
+# commas. For consistency, use all lowercase and give multiple word tags with
+# hyphens instead of spaces. For example:
+# [fiction, historical-fiction, boston]
+tags: [children, fiction, fantasy]
+
# Uncomment this to customize the base filename ($filename.md, $filename.html, etc.)
-# filename: "Alices Adventures in Wonderland"
+filename: ~
# Book description using Markdown syntax.
description: |
@@ -27,4 +48,3 @@ margin:
left: 8
right: 8
bottom: ~
-

0 comments on commit 6daf313

Please sign in to comment.