Skip to content

Commit

Permalink
[skeb] add extractor for followed users (#5290)
Browse files Browse the repository at this point in the history
needs 'Authorization' header from browser session
-o headers.Authorization="Bearer ey…"
  • Loading branch information
mikf committed Mar 6, 2024
1 parent ace16f0 commit 6d9e3c0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/supportedsites.md
Expand Up @@ -790,7 +790,7 @@ Consider all listed sites to potentially be NSFW.
<tr>
<td>Skeb</td>
<td>https://skeb.jp/</td>
<td>Followed Users, Posts, Search Results, User Profiles</td>
<td>Followed Creators, Followed Users, Posts, Search Results, User Profiles</td>
<td></td>
</tr>
<tr>
Expand Down
59 changes: 40 additions & 19 deletions gallery_dl/extractor/skeb.py
Expand Up @@ -26,10 +26,10 @@ def __init__(self, match):
def _init(self):
self.thumbnails = self.config("thumbnails", False)
self.article = self.config("article", False)
self.headers = {
"Accept" : "application/json, text/plain, */*",
"Authorization": "Bearer null",
}
self.headers = {"Accept": "application/json, text/plain, */*"}

if "Authorization" not in self.session.headers:
self.headers["Authorization"] = "Bearer null"

def request(self, url, **kwargs):
while True:
Expand All @@ -55,6 +55,12 @@ def items(self):
url = file["file_url"]
yield Message.Url, url, text.nameext_from_url(url, post)

def _items_users(self):
base = self.root + "/@"
for user in self.users():
user["_extractor"] = SkebUserExtractor
yield Message.Queue, base + user["screen_name"], user

def posts(self):
"""Return post number"""

Expand Down Expand Up @@ -83,6 +89,20 @@ def _pagination(self, url, params):
return
params["offset"] += 30

def _pagination_users(self, endpoint, params):
url = "{}/api{}".format(self.root, endpoint)
params["offset"] = 0
params["limit"] = 90

while True:
data = self.request(
url, params=params, headers=self.headers).json()
yield from data

if len(data) < params["limit"]:
return
params["offset"] += params["limit"]

def _get_post_data(self, user_name, post_num):
url = "{}/api/users/{}/works/{}".format(
self.root, user_name, post_num)
Expand Down Expand Up @@ -256,22 +276,23 @@ class SkebFollowingExtractor(SkebExtractor):
pattern = r"(?:https?://)?skeb\.jp/@([^/?#]+)/following_creators"
example = "https://skeb.jp/@USER/following_creators"

def items(self):
for user in self.users():
url = "{}/@{}".format(self.root, user["screen_name"])
user["_extractor"] = SkebUserExtractor
yield Message.Queue, url, user
items = SkebExtractor._items_users

def users(self):
url = "{}/api/users/{}/following_creators".format(
self.root, self.user_name)
params = {"sort": "date", "offset": 0, "limit": 90}
endpoint = "/users/{}/following_creators".format(self.user_name)
params = {"sort": "date"}
return self._pagination_users(endpoint, params)

while True:
data = self.request(
url, params=params, headers=self.headers).json()
yield from data

if len(data) < params["limit"]:
return
params["offset"] += params["limit"]
class SkebFollowingUsersExtractor(SkebExtractor):
"""Extractor for your followed users"""
subcategory = "following-users"
pattern = r"(?:https?://)?skeb\.jp/following_users()"
example = "https://skeb.jp/following_users"

items = SkebExtractor._items_users

def users(self):
endpoint = "/following_users"
params = {}
return self._pagination_users(endpoint, params)
4 changes: 4 additions & 0 deletions scripts/supportedsites.py
Expand Up @@ -273,6 +273,10 @@
"sexcom": {
"pins": "User Pins",
},
"skeb": {
"following" : "Followed Creators",
"following-users": "Followed Users",
},
"smugmug": {
"path": "Images from Users and Folders",
},
Expand Down
8 changes: 8 additions & 0 deletions test/results/skeb.py
Expand Up @@ -82,4 +82,12 @@
"#class" : skeb.SkebFollowingExtractor,
},

{
"#url" : "https://skeb.jp/following_users",
"#category": ("", "skeb", "following-users"),
"#class" : skeb.SkebFollowingUsersExtractor,
"#pattern" : skeb.SkebUserExtractor.pattern,
"#auth" : True,
},

)

0 comments on commit 6d9e3c0

Please sign in to comment.