merge #3950: [misskey] add 'favorite' extractor
This commit is contained in:
@@ -2108,8 +2108,16 @@ Description
|
|||||||
Also emit metadata for text-only posts without media content.
|
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
|
extractor.[misskey].renotes
|
||||||
----------------------------
|
---------------------------
|
||||||
Type
|
Type
|
||||||
``bool``
|
``bool``
|
||||||
Default
|
Default
|
||||||
@@ -2119,7 +2127,7 @@ Description
|
|||||||
|
|
||||||
|
|
||||||
extractor.[misskey].replies
|
extractor.[misskey].replies
|
||||||
----------------------------
|
---------------------------
|
||||||
Type
|
Type
|
||||||
``bool``
|
``bool``
|
||||||
Default
|
Default
|
||||||
|
|||||||
@@ -196,6 +196,7 @@
|
|||||||
"password": null
|
"password": null
|
||||||
},
|
},
|
||||||
"misskey": {
|
"misskey": {
|
||||||
|
"access-token": null,
|
||||||
"renotes": false,
|
"renotes": false,
|
||||||
"replies": true
|
"replies": true
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1132,19 +1132,19 @@ Consider all sites to be NSFW unless otherwise known.
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Misskey.io</td>
|
<td>Misskey.io</td>
|
||||||
<td>https://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>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Lesbian.energy</td>
|
<td>Lesbian.energy</td>
|
||||||
<td>https://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>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Sushi.ski</td>
|
<td>Sushi.ski</td>
|
||||||
<td>https://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>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"""Extractors for Misskey instances"""
|
"""Extractors for Misskey instances"""
|
||||||
|
|
||||||
from .common import BaseExtractor, Message
|
from .common import BaseExtractor, Message
|
||||||
from .. import text
|
from .. import text, exception
|
||||||
|
|
||||||
|
|
||||||
class MisskeyExtractor(BaseExtractor):
|
class MisskeyExtractor(BaseExtractor):
|
||||||
@@ -27,6 +27,8 @@ class MisskeyExtractor(BaseExtractor):
|
|||||||
|
|
||||||
def items(self):
|
def items(self):
|
||||||
for note in self.notes():
|
for note in self.notes():
|
||||||
|
if "note" in note:
|
||||||
|
note = note["note"]
|
||||||
files = note.pop("files") or []
|
files = note.pop("files") or []
|
||||||
renote = note.get("renote")
|
renote = note.get("renote")
|
||||||
if renote:
|
if renote:
|
||||||
@@ -68,7 +70,7 @@ BASE_PATTERN = MisskeyExtractor.update({
|
|||||||
},
|
},
|
||||||
"lesbian.energy": {
|
"lesbian.energy": {
|
||||||
"root": "https://lesbian.energy",
|
"root": "https://lesbian.energy",
|
||||||
"pattern": r"lesbian\.energy"
|
"pattern": r"lesbian\.energy",
|
||||||
},
|
},
|
||||||
"sushi.ski": {
|
"sushi.ski": {
|
||||||
"root": "https://sushi.ski",
|
"root": "https://sushi.ski",
|
||||||
@@ -152,6 +154,21 @@ class MisskeyNoteExtractor(MisskeyExtractor):
|
|||||||
return (self.api.notes_show(self.item),)
|
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():
|
class MisskeyAPI():
|
||||||
"""Interface for Misskey API
|
"""Interface for Misskey API
|
||||||
|
|
||||||
@@ -164,6 +181,7 @@ class MisskeyAPI():
|
|||||||
self.root = extractor.root
|
self.root = extractor.root
|
||||||
self.extractor = extractor
|
self.extractor = extractor
|
||||||
self.headers = {"Content-Type": "application/json"}
|
self.headers = {"Content-Type": "application/json"}
|
||||||
|
self.access_token = extractor.config("access-token")
|
||||||
|
|
||||||
def user_id_by_username(self, username):
|
def user_id_by_username(self, username):
|
||||||
endpoint = "/users/show"
|
endpoint = "/users/show"
|
||||||
@@ -187,6 +205,13 @@ class MisskeyAPI():
|
|||||||
data = {"noteId": note_id}
|
data = {"noteId": note_id}
|
||||||
return self._call(endpoint, data)
|
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):
|
def _call(self, endpoint, data):
|
||||||
url = self.root + "/api" + endpoint
|
url = self.root + "/api" + endpoint
|
||||||
return self.extractor.request(
|
return self.extractor.request(
|
||||||
|
|||||||
Reference in New Issue
Block a user