Skip to content

Commit

Permalink
[fanbox] add 'home' and 'supporting' extractors (#5138)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Feb 14, 2024
1 parent 04e4ffc commit c97b92c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ Consider all listed sites to potentially be NSFW.
<tr>
<td>pixivFANBOX</td>
<td>https://www.fanbox.cc/</td>
<td>Creators, Posts</td>
<td>Creators, Home Feed, Posts, Pixiv Redirects, Supported User Feed</td>
<td><a href="https://github.com/mikf/gallery-dl#cookies">Cookies</a></td>
</tr>
<tr>
Expand Down
29 changes: 26 additions & 3 deletions gallery_dl/extractor/fanbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from ..cache import memcache
import re

BASE_PATTERN = (
BASE_PATTERN = r"(?:https?://)?(?:www\.)?fanbox\.cc"
USER_PATTERN = (
r"(?:https?://)?(?:"
r"(?!www\.)([\w-]+)\.fanbox\.cc|"
r"(?:www\.)?fanbox\.cc/@([\w-]+))"
Expand Down Expand Up @@ -290,7 +291,7 @@ def _process_embed(self, post, embed):
class FanboxCreatorExtractor(FanboxExtractor):
"""Extractor for a Fanbox creator's works"""
subcategory = "creator"
pattern = BASE_PATTERN + r"(?:/posts)?/?$"
pattern = USER_PATTERN + r"(?:/posts)?/?$"
example = "https://USER.fanbox.cc/"

def __init__(self, match):
Expand All @@ -305,7 +306,7 @@ def posts(self):
class FanboxPostExtractor(FanboxExtractor):
"""Extractor for media from a single Fanbox post"""
subcategory = "post"
pattern = BASE_PATTERN + r"/posts/(\d+)"
pattern = USER_PATTERN + r"/posts/(\d+)"
example = "https://USER.fanbox.cc/posts/12345"

def __init__(self, match):
Expand All @@ -316,6 +317,28 @@ def posts(self):
return (self._get_post_data(self.post_id),)


class FanboxHomeExtractor(FanboxExtractor):
"""Extractor for your Fanbox home feed"""
subcategory = "home"
pattern = BASE_PATTERN + r"/?$"
example = "https://fanbox.cc/"

def posts(self):
url = "https://api.fanbox.cc/post.listHome?limit=10"
return self._pagination(url)


class FanboxSupportingExtractor(FanboxExtractor):
"""Extractor for your supported Fanbox users feed"""
subcategory = "supporting"
pattern = BASE_PATTERN + r"/home/supporting"
example = "https://fanbox.cc/home/supporting"

def posts(self):
url = "https://api.fanbox.cc/post.listSupporting?limit=10"
return self._pagination(url)


class FanboxRedirectExtractor(Extractor):
"""Extractor for pixiv redirects to fanbox.cc"""
category = "fanbox"
Expand Down
9 changes: 3 additions & 6 deletions scripts/supportedsites.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"art" : "Art",
"audio" : "Audio",
"doujin" : "Doujin",
"home" : "Home Feed",
"image" : "individual Images",
"index" : "Site Index",
"issue" : "Comic Issues",
Expand Down Expand Up @@ -192,15 +193,15 @@
"watch-posts": "",
},
"fanbox": {
"redirect": "",
"supporting": "Supported User Feed",
"redirect" : "Pixiv Redirects",
},
"fapello": {
"path": "Videos, Trending Posts, Popular Videos, Top Models",
},
"hatenablog": {
"archive": "Archive",
"entry" : "Individual Posts",
"home" : "Home Feed",
},
"hentaifoundry": {
"story": "",
Expand Down Expand Up @@ -256,14 +257,10 @@
"gifs": "",
},
"raddle": {
"home" : "Home Feed",
"usersubmissions": "User Profiles",
"post" : "Individual Posts",
"shorturl" : "",
},
"reddit": {
"home": "Home Feed",
},
"redgifs": {
"collections": "",
},
Expand Down
17 changes: 17 additions & 0 deletions test/results/fanbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@
"#sha1_url": "c92ddd06f2efc4a5fe30ec67e21544f79a5c4062",
},

{
"#url" : "https://fanbox.cc/",
"#category": ("", "fanbox", "home"),
"#class" : fanbox.FanboxHomeExtractor,
"#auth" : True,
"#range" : "1-10",
"#count" : 10,
},

{
"#url" : "https://fanbox.cc/home/supporting",
"#category": ("", "fanbox", "supporting"),
"#class" : fanbox.FanboxSupportingExtractor,
"#auth" : True,
"#count" : 0,
},

{
"#url" : "https://www.pixiv.net/fanbox/creator/52336352",
"#category": ("", "fanbox", "redirect"),
Expand Down

0 comments on commit c97b92c

Please sign in to comment.