[newgrounds] provide fallback URLs for video downloads (#1042)

This commit is contained in:
Mike Fährmann
2020-10-16 01:16:12 +02:00
parent a3ca2f6080
commit 3f2ba629ea

View File

@@ -39,6 +39,7 @@ class NewgroundsExtractor(Extractor):
post = self.extract_post(post_url) post = self.extract_post(post_url)
url = post.get("url") url = post.get("url")
except Exception: except Exception:
self.log.debug("", exc_info=True)
url = None url = None
if url: if url:
@@ -159,6 +160,7 @@ class NewgroundsExtractor(Extractor):
if src: if src:
src = src.replace("\\/", "/") src = src.replace("\\/", "/")
fallback = ()
date = text.parse_datetime(extr( date = text.parse_datetime(extr(
'itemprop="datePublished" content="', '"')) 'itemprop="datePublished" content="', '"'))
else: else:
@@ -168,8 +170,13 @@ class NewgroundsExtractor(Extractor):
"X-Requested-With": "XMLHttpRequest", "X-Requested-With": "XMLHttpRequest",
"Referer": self.root, "Referer": self.root,
} }
data = self.request(url, headers=headers).json() sources = self.request(url, headers=headers).json()["sources"]
src = data["sources"]["360p"][0]["src"].replace(".360p.", ".") 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]) date = text.parse_timestamp(src.rpartition("?")[2])
return { return {
@@ -181,6 +188,7 @@ class NewgroundsExtractor(Extractor):
"rating" : extr('class="rated-', '"'), "rating" : extr('class="rated-', '"'),
"index" : text.parse_int(index), "index" : text.parse_int(index),
"_index" : index, "_index" : index,
"_fallback" : fallback,
} }
def _pagination(self, kind): def _pagination(self, kind):