Fix #6757 (News Download of taz Digiabo fails)

This commit is contained in:
Kovid Goyal 2010-09-17 12:02:43 -06:00
parent 466cfa9412
commit 6566014a8b
2 changed files with 34 additions and 27 deletions

View File

@ -8,8 +8,9 @@ __docformat__ = 'restructuredtext de'
''' '''
www.taz.de/digiabo www.taz.de/digiabo
''' '''
import os, urllib2, zipfile, tempfile import os, urllib2, zipfile
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ptempfile import PersistentTemporaryFile
class TazDigiabo(BasicNewsRecipe): class TazDigiabo(BasicNewsRecipe):
@ -26,38 +27,39 @@ class TazDigiabo(BasicNewsRecipe):
} }
def build_index(self): def build_index(self):
if self.username is not None and self.password is not None: domain = "http://www.taz.de"
domain = "http://www.taz.de"
url = domain + "/epub/" url = domain + "/epub/"
auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(realm='TAZ-ABO', auth_handler.add_password(realm='TAZ-ABO',
uri=url, uri=url,
user=self.username, user=self.username,
passwd=self.password) passwd=self.password)
opener = urllib2.build_opener(auth_handler) opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener) urllib2.install_opener(opener)
try: try:
f = urllib2.urlopen(url) f = urllib2.urlopen(url)
except urllib2.HTTPError: except urllib2.HTTPError:
self.report_progress(0,_('Can\'t login to download issue')) self.report_progress(0,_('Can\'t login to download issue'))
raise ValueError('Failed to login, check your username and' raise ValueError('Failed to login, check your username and'
' password') ' password')
tmp = tempfile.TemporaryFile() tmp = PersistentTemporaryFile(suffix='.epub')
self.report_progress(0,_('downloading epub')) self.report_progress(0,_('downloading epub'))
tmp.write(f.read()) tmp.write(f.read())
tmp.close()
zfile = zipfile.ZipFile(tmp, 'r') zfile = zipfile.ZipFile(tmp.name, 'r')
self.report_progress(0,_('extracting epub')) self.report_progress(0,_('extracting epub'))
zfile.extractall(self.output_dir) zfile.extractall(self.output_dir)
tmp.close() tmp.close()
index = os.path.join(self.output_dir, 'content.opf') index = os.path.join(self.output_dir, 'content.opf')
self.report_progress(1,_('epub downloaded and extracted')) self.report_progress(1,_('epub downloaded and extracted'))
return index
return index

View File

@ -10,6 +10,7 @@ import os
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
from calibre.constants import numeric_version from calibre.constants import numeric_version
from calibre import walk
class RecipeDisabled(Exception): class RecipeDisabled(Exception):
pass pass
@ -111,6 +112,10 @@ class RecipeInput(InputFormatPlugin):
if f.endswith('.opf'): if f.endswith('.opf'):
return os.path.abspath(f) return os.path.abspath(f)
for f in walk('.'):
if f.endswith('.opf'):
return os.path.abspath(f)
def postprocess_book(self, oeb, opts, log): def postprocess_book(self, oeb, opts, log):
if self.recipe_object is not None: if self.recipe_object is not None:
self.recipe_object.postprocess_book(oeb, opts, log) self.recipe_object.postprocess_book(oeb, opts, log)