diff --git a/dosagelib/comic.py b/dosagelib/comic.py index 84aeb42fe..b31b8e38d 100644 --- a/dosagelib/comic.py +++ b/dosagelib/comic.py @@ -17,12 +17,13 @@ class FetchComicError(IOError): class ComicStrip(object): """A list of comic image URLs.""" - def __init__(self, name, stripUrl, imageUrls, namer): + def __init__(self, name, stripUrl, imageUrls, namer, session): """Store the image URL list.""" self.name = name self.stripUrl = stripUrl self.imageUrls = imageUrls self.namer = namer + self.session = session def getImages(self): """Get a list of image downloaders.""" @@ -35,13 +36,15 @@ class ComicStrip(object): if filename is None: filename = url.rsplit('/', 1)[1] dirname = getDirname(self.name) - return ComicImage(self.name, url, self.stripUrl, dirname, filename) + return ComicImage(self.name, url, self.stripUrl, dirname, filename, self.session) class ComicImage(object): """A comic image downloader.""" - def __init__(self, name, url, referrer, dirname, filename): + ChunkBytes = 1024 * 100 # 100KB + + def __init__(self, name, url, referrer, dirname, filename, session): """Set URL and filename.""" self.name = name self.referrer = referrer @@ -49,11 +52,12 @@ class ComicImage(object): self.dirname = dirname filename = getFilename(filename) self.filename, self.ext = os.path.splitext(filename) + self.session = session def connect(self): """Connect to host and get meta information.""" try: - self.urlobj = getImageObject(self.url, self.referrer) + self.urlobj = getImageObject(self.url, self.referrer, self.session) except IOError as msg: raise FetchComicError('Unable to retrieve URL.', self.url, msg) @@ -100,7 +104,8 @@ class ComicImage(object): try: out.debug('Writing comic to file %s...' % fn) with open(fn, 'wb') as comicOut: - comicOut.write(self.urlobj.content) + for chunk in self.urlobj.iter_content(chunk_size=self.ChunkBytes): + comicOut.write(chunk) self.touch(fn) except Exception: if os.path.isfile(fn): diff --git a/dosagelib/helpers.py b/dosagelib/helpers.py index 17be7372b..9a7a5825c 100644 --- a/dosagelib/helpers.py +++ b/dosagelib/helpers.py @@ -29,9 +29,9 @@ def bounceStarter(url, nextSearch): @classmethod def _starter(cls): """Get bounced start URL.""" - data, baseUrl = getPageContent(url, session=cls.session) + data, baseUrl = getPageContent(url, cls.session) url1 = fetchUrl(url, data, baseUrl, cls.prevSearch) - data, baseUrl = getPageContent(url1, session=cls.session) + data, baseUrl = getPageContent(url1, cls.session) return fetchUrl(url1, data, baseUrl, nextSearch) return _starter @@ -41,6 +41,6 @@ def indirectStarter(url, latestSearch): @classmethod def _starter(cls): """Get indirect start URL.""" - data, baseUrl = getPageContent(url, session=cls.session) + data, baseUrl = getPageContent(url, cls.session) return fetchUrl(url, data, baseUrl, latestSearch) return _starter diff --git a/dosagelib/plugins/clonemanga.py b/dosagelib/plugins/clonemanga.py index b0b6ca272..0305eb86b 100644 --- a/dosagelib/plugins/clonemanga.py +++ b/dosagelib/plugins/clonemanga.py @@ -25,14 +25,14 @@ def add(name, shortName, imageFolder=None, lastStrip=None): @classmethod def _starter(cls): # first, try hopping to previous and next comic - data, _baseUrl = getPageContent(baseUrl, session=cls.session) + data, _baseUrl = getPageContent(baseUrl, cls.session) try: url = fetchUrl(baseUrl, data, _baseUrl, _prevSearch) except ValueError: # no previous link found, try hopping to last comic return fetchUrl(baseUrl, data, _baseUrl, _lastSearch) else: - data, _baseUrl = getPageContent(url, session=cls.session) + data, _baseUrl = getPageContent(url, cls.session) return fetchUrl(url, data, _baseUrl, _nextSearch) attrs = dict( diff --git a/dosagelib/plugins/drunkduck.py b/dosagelib/plugins/drunkduck.py index ec62e1c14..df9b55914 100644 --- a/dosagelib/plugins/drunkduck.py +++ b/dosagelib/plugins/drunkduck.py @@ -26,14 +26,14 @@ def add(name, path): @classmethod def _starter(cls): # first, try hopping to previous and next comic - data, baseUrl = getPageContent(_url, session=cls.session) + data, baseUrl = getPageContent(_url, cls.session) try: url = fetchUrl(_url, data, baseUrl, _prevSearch) except ValueError: # no previous link found, try hopping to last comic return fetchUrl(_url, data, baseUrl, _lastSearch) else: - data, baseUrl = getPageContent(url, session=cls.session) + data, baseUrl = getPageContent(url, cls.session) return fetchUrl(url, data, baseUrl, _nextSearch) globals()[classname] = make_scraper(classname, diff --git a/dosagelib/plugins/smackjeeves.py b/dosagelib/plugins/smackjeeves.py index 392feace4..70586b652 100644 --- a/dosagelib/plugins/smackjeeves.py +++ b/dosagelib/plugins/smackjeeves.py @@ -31,10 +31,10 @@ def add(name, url, description, adult, bounce): def _starter(cls): """Get start URL.""" url1 = modifier(url) - data, baseUrl = getPageContent(url1, session=cls.session) + data, baseUrl = getPageContent(url1, cls.session) url2 = fetchUrl(url1, data, baseUrl, cls.prevSearch) if bounce: - data, baseUrl = getPageContent(url2, session=cls.session) + data, baseUrl = getPageContent(url2, cls.session) url3 = fetchUrl(url2, data, baseUrl, _nextSearch) return modifier(url3) return modifier(url2) diff --git a/dosagelib/plugins/universal.py b/dosagelib/plugins/universal.py index f2d924b06..e886dc08e 100644 --- a/dosagelib/plugins/universal.py +++ b/dosagelib/plugins/universal.py @@ -26,7 +26,7 @@ def add(name, shortname):