Revised _update_epub_metadata

This commit is contained in:
GRiker 2011-11-22 06:22:38 -07:00
parent dd8960eeac
commit a4ed02cf0d

View File

@ -2647,7 +2647,7 @@ class ITUNES(DriverBase):
# Refresh epub metadata
with open(fpath,'r+b') as zfo:
# Touch the OPF timestamp
if False:
try:
zf_opf = ZipFile(fpath,'r')
fnames = zf_opf.namelist()
@ -2657,6 +2657,7 @@ class ITUNES(DriverBase):
None,
level=UserFeedback.WARN)
#Touch the OPF timestamp
opf_tree = etree.fromstring(zf_opf.read(opf))
md_els = opf_tree.xpath('.//*[local-name()="metadata"]')
if md_els:
@ -2678,38 +2679,29 @@ class ITUNES(DriverBase):
if DEBUG:
self.log.warning(" missing <metadata> block in OPF file")
self.log.info(" add timestamp: %s" % metadata.timestamp)
# Force the language declaration for iBooks 1.1
#metadata.language = get_lang().replace('_', '-')
# Updates from metadata plugboard (ignoring publisher)
metadata.language = metadata_x.language
if DEBUG:
if metadata.language != metadata_x.language:
self.log.info(" rewriting language: <dc:language>%s</dc:language>" % metadata.language)
zf_opf.close()
# If 'News' in tags, tweak the title/author for friendlier display in iBooks
if _('News') in metadata.tags or \
_('Catalog') in metadata.tags:
if metadata.title.find('[') > 0:
metadata.title = metadata.title[:metadata.title.find('[')-1]
if _('News') in metadata_x.tags or \
_('Catalog') in metadata_x.tags:
if metadata_x.title.find('[') > 0:
metadata_x.title = metadata_x.title[:metadata_x.title.find('[')-1]
date_as_author = '%s, %s %s, %s' % (strftime('%A'), strftime('%B'), strftime('%d').lstrip('0'), strftime('%Y'))
metadata.author = metadata.authors = [date_as_author]
sort_author = re.sub('^\s*A\s+|^\s*The\s+|^\s*An\s+', '', metadata.title).rstrip()
metadata.author_sort = '%s %s' % (sort_author, strftime('%Y-%m-%d'))
metadata_x.author = metadata_x.authors = [date_as_author]
sort_author = re.sub('^\s*A\s+|^\s*The\s+|^\s*An\s+', '', metadata_x.title).rstrip()
metadata_x.author_sort = '%s %s' % (sort_author, strftime('%Y-%m-%d'))
# Remove any non-alpha category tags
for tag in metadata.tags:
for tag in metadata_x.tags:
if not self._is_alpha(tag[0]):
metadata.tags.remove(tag)
metadata_x.tags.remove(tag)
# If windows & series, nuke tags so series used as Category during _update_iTunes_metadata()
if iswindows and metadata.series:
metadata.tags = None
if iswindows and metadata_x.series:
metadata_x.tags = None
set_metadata(zfo, metadata, apply_null=True, update_timestamp=True)
set_metadata(zfo, metadata_x, apply_null=True, update_timestamp=True)
def _update_device(self, msg='', wait=True):
'''
@ -2838,6 +2830,8 @@ class ITUNES(DriverBase):
break
if db_added:
self.log.warning(" waiting for db_added to become writeable ")
time.sleep(1.0)
# If no title_sort plugboard tweak, create sort_name from series/index
if metadata.title_sort == metadata_x.title_sort:
db_added.sort_name.set("%s %s" % (self.title_sorter(metadata_x.series), series_index))
@ -2878,6 +2872,8 @@ class ITUNES(DriverBase):
lb_added.SortName = metadata_x.title_sort
if db_added:
self.log.warning(" waiting for db_added to become writeable ")
time.sleep(1.0)
db_added.Name = metadata_x.title
db_added.Album = metadata_x.title
db_added.Artist = authors_to_string(metadata_x.authors)