[newgrounds] add 'favorite' extractor (#394)

pull/644/head
Mike Fährmann 5 years ago
parent a45fbc38ea
commit 823fbeaae6
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -146,7 +146,7 @@ Turboimagehost https://www.turboimagehost.com/ individual Images
.. |hentaifoundry-C| replace:: Favorites, individual Images, Popular Images, Recent Images, Scraps, User Profiles
.. |imgur-C| replace:: Albums, Favorites, Galleries, individual Images, Subreddits, User Profiles
.. |instagram-C| replace:: Channels, individual Images, Stories, Tag-Searches, User Profiles
.. |newgrounds-C| replace:: Art, Audio, individual Images, Media Files, Movies, User Profiles
.. |newgrounds-C| replace:: Art, Audio, Favorites, individual Images, Media Files, Movies, User Profiles
.. |nijie-C| replace:: Doujin, Favorites, individual Images, User Profiles
.. |pixiv-C| replace:: Favorites, Follows, pixiv.me Links, Rankings, Search Results, User Profiles, individual Images
.. |reddit-C| replace:: individual Images, Submissions, Subreddits, User Profiles

@ -11,6 +11,7 @@
from .common import Extractor, Message
from .. import text, exception
from ..cache import cache
import itertools
import json
@ -334,3 +335,53 @@ class NewgroundsUserExtractor(NewgroundsExtractor):
(NewgroundsAudioExtractor , base + "audio"),
(NewgroundsMoviesExtractor, base + "movies"),
), ("art",))
class NewgroundsFavoriteExtractor(NewgroundsExtractor):
"""Extractor for posts favorited by a newgrounds user"""
subcategory = "favorite"
directory_fmt = ("{category}", "{user}", "Favorites")
pattern = (r"(?:https?://)?([^.]+)\.newgrounds\.com"
r"/favorites(?:/(art|audio|movies))?/?")
test = (
("https://tomfulp.newgrounds.com/favorites/art", {
"range": "1-10",
"count": ">= 10",
}),
("https://tomfulp.newgrounds.com/favorites/audio"),
("https://tomfulp.newgrounds.com/favorites/movies"),
("https://tomfulp.newgrounds.com/favorites/"),
)
def __init__(self, match):
NewgroundsExtractor.__init__(self, match)
self.kind = match.group(2)
def posts(self):
if self.kind:
return self._pagination(self.kind)
return itertools.chain.from_iterable(
self._pagination(k) for k in ("art", "audio", "movies")
)
def _pagination(self, kind):
num = 1
headers = {
"Accept": "application/json, text/javascript, */*; q=0.01",
"X-Requested-With": "XMLHttpRequest",
"Referer": self.user_root,
}
while True:
url = "{}/favorites/{}/{}".format(self.user_root, kind, num)
response = self.request(url, headers=headers)
if response.history:
return
favs = list(text.extract_iter(
response.text, 'href="//www.newgrounds.com', '"'))
for path in favs:
yield self.root + path
if len(favs) < 24:
return
num += 1

Loading…
Cancel
Save