Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[misskey] add my favorites extractor #3950

Merged
merged 2 commits into from
May 25, 2023
Merged

[misskey] add my favorites extractor #3950

merged 2 commits into from
May 25, 2023

Conversation

03AaN
Copy link
Contributor

@03AaN 03AaN commented Apr 23, 2023

This will saves images from favorites. Saving favorites requires access token with "View your list of favorites" permission.

@enduser420
Copy link
Contributor

diff --git a/gallery_dl/extractor/misskey.py b/gallery_dl/extractor/misskey.py
index 7e5ef799..26b7f194 100644
--- a/gallery_dl/extractor/misskey.py
+++ b/gallery_dl/extractor/misskey.py
@@ -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:
@@ -157,26 +159,12 @@ class MisskeyMyFavoritesExtractor(MisskeyExtractor):
     subcategory = "favorites"
     pattern = BASE_PATTERN + r"(/my/favorites|/api/i/favorites)"
     test = (
-        ("https://misskey.io/my/favorites",),
-        ("https://misskey.io/api/i/favorites",),
+        ("https://misskey.io/my/favorites"),
+        ("https://misskey.io/api/i/favorites"),
     )
 
-    def items(self):
-        for fav in self.api.i_favorites():
-            note = fav.get("note")
-            note["instance"] = self.instance
-            note["instance_remote"] = note["user"]["host"]
-            note["count"] = len(note["files"])
-            note["date"] = text.parse_datetime(
-                note["createdAt"], "%Y-%m-%dT%H:%M:%S.%f%z")
-
-            yield Message.Directory, note
-            for note["num"], file in enumerate(note["files"], 1):
-                file["date"] = text.parse_datetime(
-                    file["createdAt"], "%Y-%m-%dT%H:%M:%S.%f%z")
-                note["file"] = file
-                url = file["url"]
-                yield Message.Url, url, text.nameext_from_url(url, note)
+    def notes(self):
+        return self.api.i_favorites()
 
 
 class MisskeyAPI():
@@ -217,10 +205,9 @@ class MisskeyAPI():
 
     def i_favorites(self):
         endpoint = "/i/favorites"
-        data = {}
         if not self.access_token:
             raise exception.AuthenticationError()
-        data["i"] = self.access_token
+        data = {"i": self.access_token}
         return self._pagination(endpoint, data)
 
     def _call(self, endpoint, data):

mikf added a commit that referenced this pull request May 25, 2023
@mikf mikf merged commit f9b7a03 into mikf:master May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants