mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-22 02:32:33 +01:00
merge #3950: [misskey] add 'favorite' extractor
This commit is contained in:
commit
65a9f4b124
@ -2108,8 +2108,16 @@ Description
|
||||
Also emit metadata for text-only posts without media content.
|
||||
|
||||
|
||||
extractor.[misskey].access-token
|
||||
--------------------------------
|
||||
Type
|
||||
``string``
|
||||
Description
|
||||
Your access token, necessary to fetch favorited notes.
|
||||
|
||||
|
||||
extractor.[misskey].renotes
|
||||
----------------------------
|
||||
---------------------------
|
||||
Type
|
||||
``bool``
|
||||
Default
|
||||
@ -2119,7 +2127,7 @@ Description
|
||||
|
||||
|
||||
extractor.[misskey].replies
|
||||
----------------------------
|
||||
---------------------------
|
||||
Type
|
||||
``bool``
|
||||
Default
|
||||
|
@ -196,6 +196,7 @@
|
||||
"password": null
|
||||
},
|
||||
"misskey": {
|
||||
"access-token": null,
|
||||
"renotes": false,
|
||||
"replies": true
|
||||
},
|
||||
|
@ -1132,19 +1132,19 @@ Consider all sites to be NSFW unless otherwise known.
|
||||
<tr>
|
||||
<td>Misskey.io</td>
|
||||
<td>https://misskey.io/</td>
|
||||
<td>Images from Notes, User Profiles</td>
|
||||
<td>Favorites, Images from Notes, User Profiles</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Lesbian.energy</td>
|
||||
<td>https://lesbian.energy/</td>
|
||||
<td>Images from Notes, User Profiles</td>
|
||||
<td>Favorites, Images from Notes, User Profiles</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Sushi.ski</td>
|
||||
<td>https://sushi.ski/</td>
|
||||
<td>Images from Notes, User Profiles</td>
|
||||
<td>Favorites, Images from Notes, User Profiles</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
"""Extractors for Misskey instances"""
|
||||
|
||||
from .common import BaseExtractor, Message
|
||||
from .. import text
|
||||
from .. import text, exception
|
||||
|
||||
|
||||
class MisskeyExtractor(BaseExtractor):
|
||||
@ -27,6 +27,8 @@ class MisskeyExtractor(BaseExtractor):
|
||||
|
||||
def items(self):
|
||||
for note in self.notes():
|
||||
if "note" in note:
|
||||
note = note["note"]
|
||||
files = note.pop("files") or []
|
||||
renote = note.get("renote")
|
||||
if renote:
|
||||
@ -68,7 +70,7 @@ BASE_PATTERN = MisskeyExtractor.update({
|
||||
},
|
||||
"lesbian.energy": {
|
||||
"root": "https://lesbian.energy",
|
||||
"pattern": r"lesbian\.energy"
|
||||
"pattern": r"lesbian\.energy",
|
||||
},
|
||||
"sushi.ski": {
|
||||
"root": "https://sushi.ski",
|
||||
@ -152,6 +154,21 @@ class MisskeyNoteExtractor(MisskeyExtractor):
|
||||
return (self.api.notes_show(self.item),)
|
||||
|
||||
|
||||
class MisskeyFavoriteExtractor(MisskeyExtractor):
|
||||
"""Extractor for favorited notes"""
|
||||
subcategory = "favorite"
|
||||
pattern = BASE_PATTERN + r"/(?:my|api/i)/favorites"
|
||||
test = (
|
||||
("https://misskey.io/my/favorites"),
|
||||
("https://misskey.io/api/i/favorites"),
|
||||
("https://lesbian.energy/my/favorites"),
|
||||
("https://sushi.ski/my/favorites"),
|
||||
)
|
||||
|
||||
def notes(self):
|
||||
return self.api.i_favorites()
|
||||
|
||||
|
||||
class MisskeyAPI():
|
||||
"""Interface for Misskey API
|
||||
|
||||
@ -164,6 +181,7 @@ class MisskeyAPI():
|
||||
self.root = extractor.root
|
||||
self.extractor = extractor
|
||||
self.headers = {"Content-Type": "application/json"}
|
||||
self.access_token = extractor.config("access-token")
|
||||
|
||||
def user_id_by_username(self, username):
|
||||
endpoint = "/users/show"
|
||||
@ -187,6 +205,13 @@ class MisskeyAPI():
|
||||
data = {"noteId": note_id}
|
||||
return self._call(endpoint, data)
|
||||
|
||||
def i_favorites(self):
|
||||
endpoint = "/i/favorites"
|
||||
if not self.access_token:
|
||||
raise exception.AuthenticationError()
|
||||
data = {"i": self.access_token}
|
||||
return self._pagination(endpoint, data)
|
||||
|
||||
def _call(self, endpoint, data):
|
||||
url = self.root + "/api" + endpoint
|
||||
return self.extractor.request(
|
||||
|
Loading…
Reference in New Issue
Block a user