From 3f2ba629ead16c5d9b302d7b92b46ae626bfc5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 16 Oct 2020 01:16:12 +0200 Subject: [PATCH] [newgrounds] provide fallback URLs for video downloads (#1042) --- gallery_dl/extractor/newgrounds.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/gallery_dl/extractor/newgrounds.py b/gallery_dl/extractor/newgrounds.py index 8d0d7d51..3cecee4a 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: @@ -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,13 @@ 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 = [v[1][0]["src"] for v in sorted( + sources.items(), + key=lambda x: text.parse_int(x[0][:-1]), + reverse=True, + )] date = text.parse_timestamp(src.rpartition("?")[2]) return { @@ -181,6 +188,7 @@ class NewgroundsExtractor(Extractor): "rating" : extr('class="rated-', '"'), "index" : text.parse_int(index), "_index" : index, + "_fallback" : fallback, } def _pagination(self, kind):