From 000df8d1fafb0e3ed08e251d21a9d34f979c584e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 12 Jul 2016 12:06:17 +0200 Subject: [PATCH] add 'encoding' argument for Extractor.request --- gallery_dl/extractor/common.py | 11 ++++------- gallery_dl/extractor/imagebam.py | 5 ++--- gallery_dl/extractor/khinsider.py | 6 +++--- gallery_dl/extractor/powermanga.py | 4 +--- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index abea3b12..11d48eee 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -32,13 +32,10 @@ class Extractor(): yield Message.Version, 1 return - def request(self, url, *args, **kwargs): - return safe_request(self.session, url, *args, **kwargs) - - def enable_useragent(self): - self.session.headers["User-Agent"] = ( - "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0" - ) + def request(self, url, encoding=None, *args, **kwargs): + response = safe_request(self.session, url, *args, **kwargs) + response.encoding = encoding + return response class AsynchronousExtractor(Extractor): diff --git a/gallery_dl/extractor/imagebam.py b/gallery_dl/extractor/imagebam.py index 3bd65dbd..c0df1ae4 100644 --- a/gallery_dl/extractor/imagebam.py +++ b/gallery_dl/extractor/imagebam.py @@ -36,9 +36,8 @@ class ImagebamExtractor(AsynchronousExtractor): def get_job_metadata(self): """Collect metadata for extractor-job""" - response = self.request(self.url_base + "/gallery/" + self.gkey) - response.encoding = "utf-8" - page = response.text + url = self.url_base + "/gallery/" + self.gkey + page = self.request(url, encoding="utf-8").text data = { "category": self.category, "gallery-key": self.gkey, diff --git a/gallery_dl/extractor/khinsider.py b/gallery_dl/extractor/khinsider.py index acf6e8be..8803ea1c 100644 --- a/gallery_dl/extractor/khinsider.py +++ b/gallery_dl/extractor/khinsider.py @@ -24,7 +24,7 @@ class KhinsiderExtractor(AsynchronousExtractor): def items(self): url = "http://downloads.khinsider.com/game-soundtracks/album/" + self.album - page = self.request(url).text + page = self.request(url, encoding="utf-8").text data = self.get_job_metadata(page) yield Message.Version, 1 yield Message.Directory, data @@ -44,8 +44,8 @@ class KhinsiderExtractor(AsynchronousExtractor): def get_album_tracks(self, page): pos = page.index("Download all songs at once:") num = 0 - for url in text.extract_iter(page, '\r\n\t\t\r\n\t\t", "") url , pos = text.extract(page, '

', '') manga , pos = text.extract(page, 'title="', '"', pos) chapter , pos = text.extract(page, '">', '', pos)