Proxymiity / MangaDex.zip

A cursed way to download Manga and Chapters from MangaDex
13 stars 1 forks source link

any way to download by volume? #4

Open IfSheDiesSheDies opened 3 months ago

IfSheDiesSheDies commented 3 months ago

Kind of in between downloading chapters one by one and downloading everything? PS. This project is an absolute life saver

Proxymiity commented 3 months ago

This should be doable, I'll try to look into it when I'm done with other work :)

CaedenWhitaker commented 2 months ago

Minimally, this should get the job done. I added a volume parameter that filters down chapters only to those in the specified volume, if possible, using the same semantics as start and end. Worked locally for me.

Ex: https://mangadex.zip/title/2725e983-81c3-4a62-8e97-5027c5996c2b/jojo-s-bizarre-adventure-part-5-golden-wind?volume=6

Nice to see you again! <3

diff --git a/MangaDexZip/queue/actions.py b/MangaDexZip/queue/actions.py
index 89728ac..efc946c 100644
--- a/MangaDexZip/queue/actions.py
+++ b/MangaDexZip/queue/actions.py
@@ -82,7 +82,7 @@ class ArchiveContentsZIP(ActionBase):
 class AddMangaChapters(ActionBase):
     def __init__(self, data, light=False, language="en",
                  append_titles=False, preferred_groups=None, groups_substitute=True,
-                 start=None, end=None):
+                 start=None, end=None, volume=None):
         self.light = light
         self.language = language
         self.append_titles = append_titles
@@ -90,6 +90,7 @@ class AddMangaChapters(ActionBase):
         self.groups_substitute = groups_substitute
         self.start = start
         self.end = end
+        self.volume = volume
         super().__init__(data)

     def run(self, task):
@@ -138,6 +139,8 @@ class AddMangaChapters(ActionBase):
             chaps = self.filter_start(chaps)
         if self.end:
             chaps = self.filter_end(chaps)
+        if self.volume:
+            chaps = self.filter_volume(chaps)

         if not chaps:
             task.failed = True
@@ -205,6 +208,16 @@ class AddMangaChapters(ActionBase):
             except (ValueError, TypeError):
                 continue
         return filtered
+    
+    def filter_volume(self, chaps):
+        filtered = []
+        for chap in chaps:
+            try:
+                if float(chap.volume) == self.volume:
+                    filtered.append(chap)
+            except (ValueError, TypeError):
+                continue
+        return filtered

     def filter_end(self, chaps):
         filtered = []
diff --git a/MangaDexZip/routes/mangadex.py b/MangaDexZip/routes/mangadex.py
index c90cc1c..d6cfe72 100644
--- a/MangaDexZip/routes/mangadex.py
+++ b/MangaDexZip/routes/mangadex.py
@@ -33,7 +33,8 @@ def add_manga(manga_id: str,
               group: Annotated[Union[list[str], None], Query()] = None,
               group_only: Union[str, None] = None,
               start: Union[float, None] = None,
-              end: Union[float, None] = None) -> RedirectResponse:
+              end: Union[float, None] = None,
+              volume: Union[float, None] = None) -> RedirectResponse:
     """Download a Manga.

     *front-end use only* - For API usage, please refer to the /api/manga endpoint.
@@ -42,7 +43,7 @@ def add_manga(manga_id: str,
     _ = garbage
     task = _add_manga(manga_id, request, light=light, lang=lang, title=title,
                       group=group, group_only=group_only,
-                      start=start, end=end)
+                      start=start, end=end, volume=volume)
     stats.add("manga")

     api_host = f"{request.url.hostname}:{request.url.port}" if request.url.port else request.url.hostname
@@ -64,7 +65,8 @@ def add_manga_api(manga_id: str,
                   group: Annotated[Union[list[str], None], Query()] = None,
                   group_only: Union[str, None] = None,
                   start: Union[float, None] = None,
-                  end: Union[float, None] = None) -> NewTask:
+                  end: Union[float, None] = None,
+                  volume: Union[float, None] = None) -> NewTask:
     """Download a Manga.

     - `manga_id` must be a valid MangaDex Manga (Title).
@@ -78,7 +80,7 @@ def add_manga_api(manga_id: str,
     *developer use only* - For regular usage, please refer to the `/title` endpoint."""
     task = _add_manga(manga_id, request, light=light, lang=lang, title=title,
                       group=group, group_only=group_only,
-                      start=start, end=end)
+                      start=start, end=end, volume=volume)
     stats.add("manga_api")
     return NewTask(task_id=task["task_id"])

@@ -91,7 +93,8 @@ def _add_manga(manga_id: str,
                group: Annotated[Union[list[str], None], Query()] = None,
                group_only: Union[str, None] = None,
                start: Union[float, None] = None,
-               end: Union[float, None] = None):
+               end: Union[float, None] = None,
+               volume: Union[float, None] = None):
     worker = client.select_worker_auto()
     if not worker:
         raise HTTPException(status_code=503, detail="No reachable workers, please try again later")
@@ -103,7 +106,8 @@ def _add_manga(manga_id: str,
         "preferred_groups": group or [],
         "groups_substitute": False if group_only in ("1", "true") else True,
         "start": start or None,
-        "end": end or None
+        "end": end or None,
+        "volume": volume or None
     }
     task = client.append(worker, "manga", manga_id, opt, request.client.host)
     if not task:
diff --git a/MangaDexZip/routes/queue_worker.py b/MangaDexZip/routes/queue_worker.py
index dfed109..856078d 100644
--- a/MangaDexZip/routes/queue_worker.py
+++ b/MangaDexZip/routes/queue_worker.py
@@ -265,7 +265,8 @@ def queue_append(new_task: BackendTaskRequest,
                                                  preferred_groups=new_task.opt_data.get("preferred_groups", []),
                                                  groups_substitute=new_task.opt_data.get("groups_substitute", True),
                                                  start=new_task.opt_data.get("start", None),
-                                                 end=new_task.opt_data.get("end", None)))
+                                                 end=new_task.opt_data.get("end", None),
+                                                 volume=new_task.opt_data.get("volume", None)))
         group = tasks.TaskGroup.get_group(new_task.group)
         group.add_task(task)
         manager.scheduler.add_group(group)