[newgrounds] add 'format' option (closes #1729)
This commit is contained in:
@@ -1361,6 +1361,21 @@ Description
|
|||||||
Download original Adobe Flash animations instead of pre-rendered videos.
|
Download original Adobe Flash animations instead of pre-rendered videos.
|
||||||
|
|
||||||
|
|
||||||
|
extractor.newgrounds.format
|
||||||
|
---------------------------
|
||||||
|
Type
|
||||||
|
``string``
|
||||||
|
Default
|
||||||
|
``"original"``
|
||||||
|
Example
|
||||||
|
``"720p"``
|
||||||
|
Description
|
||||||
|
Selects the preferred format for video downloads.
|
||||||
|
|
||||||
|
If the selected format is not available,
|
||||||
|
the next smaller one gets chosen.
|
||||||
|
|
||||||
|
|
||||||
extractor.newgrounds.include
|
extractor.newgrounds.include
|
||||||
----------------------------
|
----------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -158,6 +158,7 @@
|
|||||||
"username": null,
|
"username": null,
|
||||||
"password": null,
|
"password": null,
|
||||||
"flash": true,
|
"flash": true,
|
||||||
|
"format": "original",
|
||||||
"include": "art"
|
"include": "art"
|
||||||
},
|
},
|
||||||
"nijie":
|
"nijie":
|
||||||
|
|||||||
@@ -31,6 +31,11 @@ class NewgroundsExtractor(Extractor):
|
|||||||
self.user_root = "https://{}.newgrounds.com".format(self.user)
|
self.user_root = "https://{}.newgrounds.com".format(self.user)
|
||||||
self.flash = self.config("flash", True)
|
self.flash = self.config("flash", True)
|
||||||
|
|
||||||
|
fmt = self.config("format", "original")
|
||||||
|
self.format = (True if not fmt or fmt == "original" else
|
||||||
|
fmt if isinstance(fmt, int) else
|
||||||
|
text.parse_int(fmt.rstrip("p")))
|
||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
self.login()
|
self.login()
|
||||||
|
|
||||||
@@ -175,8 +180,23 @@ class NewgroundsExtractor(Extractor):
|
|||||||
"Referer": self.root,
|
"Referer": self.root,
|
||||||
}
|
}
|
||||||
sources = self.request(url, headers=headers).json()["sources"]
|
sources = self.request(url, headers=headers).json()["sources"]
|
||||||
src = sources["360p"][0]["src"].replace(".360p.", ".")
|
|
||||||
fallback = self._video_fallback(sources)
|
if self.format is True:
|
||||||
|
src = sources["360p"][0]["src"].replace(".360p.", ".")
|
||||||
|
formats = sources
|
||||||
|
else:
|
||||||
|
formats = []
|
||||||
|
for fmt, src in sources.items():
|
||||||
|
width = text.parse_int(fmt.rstrip("p"))
|
||||||
|
if width <= self.format:
|
||||||
|
formats.append((width, src))
|
||||||
|
if formats:
|
||||||
|
formats.sort(reverse=True)
|
||||||
|
src, formats = formats[0][1][0]["src"], formats[1:]
|
||||||
|
else:
|
||||||
|
src = ""
|
||||||
|
|
||||||
|
fallback = self._video_fallback(formats)
|
||||||
date = text.parse_timestamp(src.rpartition("?")[2])
|
date = text.parse_timestamp(src.rpartition("?")[2])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -192,11 +212,13 @@ class NewgroundsExtractor(Extractor):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _video_fallback(sources):
|
def _video_fallback(formats):
|
||||||
sources = list(sources.items())
|
if isinstance(formats, dict):
|
||||||
sources.sort(key=lambda src: text.parse_int(src[0][:-1]), reverse=True)
|
formats = list(formats.items())
|
||||||
for src in sources:
|
formats.sort(key=lambda fmt: text.parse_int(fmt[0].rstrip("p")),
|
||||||
yield src[1][0]["src"]
|
reverse=True)
|
||||||
|
for fmt in formats:
|
||||||
|
yield fmt[1][0]["src"]
|
||||||
|
|
||||||
def _pagination(self, kind):
|
def _pagination(self, kind):
|
||||||
root = self.user_root
|
root = self.user_root
|
||||||
@@ -321,7 +343,13 @@ class NewgroundsMediaExtractor(NewgroundsExtractor):
|
|||||||
("https://www.newgrounds.com/portal/view/161181/format/flash", {
|
("https://www.newgrounds.com/portal/view/161181/format/flash", {
|
||||||
"pattern": r"https://uploads\.ungrounded\.net/161000"
|
"pattern": r"https://uploads\.ungrounded\.net/161000"
|
||||||
r"/161181_ddautta_mask__550x281_\.swf\?f1081628129",
|
r"/161181_ddautta_mask__550x281_\.swf\?f1081628129",
|
||||||
})
|
}),
|
||||||
|
# format selection (#1729)
|
||||||
|
("https://www.newgrounds.com/portal/view/758545", {
|
||||||
|
"options": (("format", "720p"),),
|
||||||
|
"pattern": r"https://uploads\.ungrounded\.net/alternate/1482000"
|
||||||
|
r"/1482860_alternate_102516\.720p\.mp4\?\d+",
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, match):
|
def __init__(self, match):
|
||||||
|
|||||||
Reference in New Issue
Block a user