diff options
| author | 2021-08-13 17:45:31 -0400 | |
|---|---|---|
| committer | 2021-08-13 17:45:31 -0400 | |
| commit | d50ba9cfe80f00e02ca9a4714f75699c00e67128 (patch) | |
| tree | 01fe7b46370d5068b8c692ae5ea95cab4d734bd8 /gallery_dl/extractor/newgrounds.py | |
| parent | 873d9a628e9412a79bdc64cd962470749de3425b (diff) | |
New upstream version 1.18.3.upstream/1.18.3
Diffstat (limited to 'gallery_dl/extractor/newgrounds.py')
| -rw-r--r-- | gallery_dl/extractor/newgrounds.py | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/gallery_dl/extractor/newgrounds.py b/gallery_dl/extractor/newgrounds.py index 4fdfac9..a699401 100644 --- a/gallery_dl/extractor/newgrounds.py +++ b/gallery_dl/extractor/newgrounds.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2018-2020 Mike Fährmann +# Copyright 2018-2021 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -31,9 +31,13 @@ class NewgroundsExtractor(Extractor): self.user_root = "https://{}.newgrounds.com".format(self.user) 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): self.login() - yield Message.Version, 1 for post_url in self.posts(): try: @@ -59,7 +63,7 @@ class NewgroundsExtractor(Extractor): def posts(self): """Return urls of all relevant image pages""" - return self._pagination(self.subcategory) + return self._pagination(self._path) def login(self): username, password = self._get_auth_info() @@ -176,8 +180,23 @@ class NewgroundsExtractor(Extractor): "Referer": self.root, } 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]) return { @@ -193,11 +212,13 @@ class NewgroundsExtractor(Extractor): } @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 _video_fallback(formats): + if isinstance(formats, dict): + formats = list(formats.items()) + formats.sort(key=lambda fmt: text.parse_int(fmt[0].rstrip("p")), + reverse=True) + for fmt in formats: + yield fmt[1][0]["src"] def _pagination(self, kind): root = self.user_root @@ -322,7 +343,13 @@ class NewgroundsMediaExtractor(NewgroundsExtractor): ("https://www.newgrounds.com/portal/view/161181/format/flash", { "pattern": r"https://uploads\.ungrounded\.net/161000" 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): @@ -336,7 +363,7 @@ class NewgroundsMediaExtractor(NewgroundsExtractor): class NewgroundsArtExtractor(NewgroundsExtractor): """Extractor for all images of a newgrounds user""" - subcategory = "art" + subcategory = _path = "art" pattern = r"(?:https?://)?([\w-]+)\.newgrounds\.com/art/?$" test = ("https://tomfulp.newgrounds.com/art", { "pattern": NewgroundsImageExtractor.pattern, @@ -346,7 +373,7 @@ class NewgroundsArtExtractor(NewgroundsExtractor): class NewgroundsAudioExtractor(NewgroundsExtractor): """Extractor for all audio submissions of a newgrounds user""" - subcategory = "audio" + subcategory = _path = "audio" pattern = r"(?:https?://)?([\w-]+)\.newgrounds\.com/audio/?$" test = ("https://tomfulp.newgrounds.com/audio", { "pattern": r"https://audio.ngfiles.com/\d+/\d+_.+\.mp3", @@ -356,7 +383,7 @@ class NewgroundsAudioExtractor(NewgroundsExtractor): class NewgroundsMoviesExtractor(NewgroundsExtractor): """Extractor for all movies of a newgrounds user""" - subcategory = "movies" + subcategory = _path = "movies" pattern = r"(?:https?://)?([\w-]+)\.newgrounds\.com/movies/?$" test = ("https://tomfulp.newgrounds.com/movies", { "pattern": r"https://uploads.ungrounded.net(/alternate)?/\d+/\d+_.+", |
