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

This commit is contained in:
Mike Fährmann
2020-03-10 01:07:09 +01:00
parent a45fbc38ea
commit 823fbeaae6
2 changed files with 52 additions and 1 deletions

View File

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

View File

@@ -11,6 +11,7 @@
from .common import Extractor, Message from .common import Extractor, Message
from .. import text, exception from .. import text, exception
from ..cache import cache from ..cache import cache
import itertools
import json import json
@@ -334,3 +335,53 @@ class NewgroundsUserExtractor(NewgroundsExtractor):
(NewgroundsAudioExtractor , base + "audio"), (NewgroundsAudioExtractor , base + "audio"),
(NewgroundsMoviesExtractor, base + "movies"), (NewgroundsMoviesExtractor, base + "movies"),
), ("art",)) ), ("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