From c74de78b0deac762df764c4e9c866bb71cce9224 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 14 Jan 2010 21:32:12 -0700 Subject: [PATCH] Fix adding books directly to device (broken by send to device template functionality). EPUB Output: Remove tags without src attributes as older versions of ADE apparently choke on them. Remove video articles from Globe and Mail recipe. --- resources/recipes/globe_and_mail.recipe | 8 +++++++- src/calibre/ebooks/epub/output.py | 20 ++++++++++++++------ src/calibre/gui2/add.py | 5 +---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/resources/recipes/globe_and_mail.recipe b/resources/recipes/globe_and_mail.recipe index 1e4fc08e39..d764a9f6ba 100644 --- a/resources/recipes/globe_and_mail.recipe +++ b/resources/recipes/globe_and_mail.recipe @@ -29,7 +29,8 @@ class GlobeAndMail(BasicNewsRecipe): remove_tags_before = dict(id="article-top") remove_tags = [ {'id':['util', 'article-tabs', 'comments', 'article-relations', - 'gallery-controls', 'video', 'galleryLoading','deck','header'] }, + 'gallery-controls', 'video', 'galleryLoading','deck','header', + 'toolsBottom'] }, {'class':['credit','inline-img-caption','tab-pointer'] }, dict(name='div', attrs={'id':'lead-photo'}), dict(name='div', attrs={'class':'right'}), @@ -68,3 +69,8 @@ class GlobeAndMail(BasicNewsRecipe): (u'Auto', u'http://www.theglobeandmail.com/auto/?service=rss') ] + def get_article_url(self, article): + url = BasicNewsRecipe.get_article_url(self, article) + if '/video/' not in url: + return url + diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py index 9ed8bb6255..bffc24ac91 100644 --- a/src/calibre/ebooks/epub/output.py +++ b/src/calibre/ebooks/epub/output.py @@ -264,13 +264,21 @@ class EPUBOutput(OutputFormatPlugin): if body: body = body[0] - # Add id attribute to tags that have name - for x in XPath('//h:a[@name]')(body): - if not x.get('id', False): - x.set('id', x.get('name')) - - # Replace
that are children of as ADE doesn't handle them if hasattr(body, 'xpath'): + # remove tags with empty src elements + bad = [] + for x in XPath('//h:img')(body): + if not x.get('src', '').strip(): + bad.append(x) + for img in bad: + img.getparent().remove(img) + + # Add id attribute to
tags that have name + for x in XPath('//h:a[@name]')(body): + if not x.get('id', False): + x.set('id', x.get('name')) + + # Replace
that are children of as ADE doesn't handle them for br in XPath('./h:br')(body): if br.getparent() is None: continue diff --git a/src/calibre/gui2/add.py b/src/calibre/gui2/add.py index 6058212b38..5419596334 100644 --- a/src/calibre/gui2/add.py +++ b/src/calibre/gui2/add.py @@ -145,10 +145,7 @@ class DBAdder(Thread): else: self.names.append(name) self.paths.append(formats[0]) - self.infos.append({'title':mi.title, - 'authors':', '.join(mi.authors), - 'cover':None, - 'tags':mi.tags if mi.tags else []}) + self.infos.append(mi) return mi.title def add_formats(self, id, formats):