diff options
Diffstat (limited to 'gallery_dl/extractor/newgrounds.py')
| -rw-r--r-- | gallery_dl/extractor/newgrounds.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/gallery_dl/extractor/newgrounds.py b/gallery_dl/extractor/newgrounds.py index f9dc886..a6cc5fa 100644 --- a/gallery_dl/extractor/newgrounds.py +++ b/gallery_dl/extractor/newgrounds.py @@ -39,6 +39,7 @@ class NewgroundsExtractor(Extractor): post = self.extract_post(post_url) url = post.get("url") except Exception: + self.log.debug("", exc_info=True) url = None if url: @@ -49,8 +50,8 @@ class NewgroundsExtractor(Extractor): post["_comment"], 'data-smartload-src="', '"'), 1): post["num"] = num post["_index"] = "{}_{:>02}".format(post["index"], num) - text.nameext_from_url(url, post) - yield Message.Url, url, post + url = text.ensure_http_scheme(url) + yield Message.Url, url, text.nameext_from_url(url, post) else: self.log.warning( "Unable to get download URL for '%s'", post_url) @@ -159,6 +160,7 @@ class NewgroundsExtractor(Extractor): if src: src = src.replace("\\/", "/") + fallback = () date = text.parse_datetime(extr( 'itemprop="datePublished" content="', '"')) else: @@ -168,8 +170,9 @@ class NewgroundsExtractor(Extractor): "X-Requested-With": "XMLHttpRequest", "Referer": self.root, } - data = self.request(url, headers=headers).json() - src = data["sources"]["360p"][0]["src"].replace(".360p.", ".") + sources = self.request(url, headers=headers).json()["sources"] + src = sources["360p"][0]["src"].replace(".360p.", ".") + fallback = self._video_fallback(sources) date = text.parse_timestamp(src.rpartition("?")[2]) return { @@ -181,8 +184,16 @@ class NewgroundsExtractor(Extractor): "rating" : extr('class="rated-', '"'), "index" : text.parse_int(index), "_index" : index, + "_fallback" : fallback, } + @staticmethod + def _video_fallback(sources): + sources = list(sources.items()) + sources.sort(key=lambda src: text.parse_int(src[0][:-1]), reverse=True) + for src in sources: + yield src[1][0]["src"] + def _pagination(self, kind): root = self.user_root headers = { @@ -218,7 +229,7 @@ class NewgroundsImageExtractor(NewgroundsExtractor): """Extractor for a single image from newgrounds.com""" subcategory = "image" pattern = (r"(?:https?://)?(?:" - r"(?:www\.)?newgrounds\.com/art/view/([^/?&#]+)/[^/?&#]+" + r"(?:www\.)?newgrounds\.com/art/view/([^/?#]+)/[^/?#]+" r"|art\.ngfiles\.com/images/\d+/\d+_([^_]+)_([^.]+))") test = ( ("https://www.newgrounds.com/art/view/tomfulp/ryu-is-hawt", { |
