From f81645245e5d757566eaf3f06539d9bcd6b9e94a Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Tue, 13 Dec 2022 18:58:44 -0500 Subject: [PATCH] [57] starting_only option added to mal_season --- VERSION | 2 +- docs/metadata/builders/myanimelist.md | 13 +++++++------ modules/builder.py | 3 ++- modules/mal.py | 21 +++++++++++++++------ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/VERSION b/VERSION index 2f94604e..30f6ebbe 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.0-develop56 +1.18.0-develop57 diff --git a/docs/metadata/builders/myanimelist.md b/docs/metadata/builders/myanimelist.md index ff8ca93c..b7e7cb66 100644 --- a/docs/metadata/builders/myanimelist.md +++ b/docs/metadata/builders/myanimelist.md @@ -262,12 +262,13 @@ Gets anime in MyAnimeList's [Seasonal Anime](https://myanimelist.net/anime/seaso The `sync_mode: sync` and `collection_order: custom` Details are recommended since the lists are continuously updated and in a specific order. -| Attribute | Description & Values | -|:----------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `season` | **Description:** Season to search
**Default:** `current`
**Values:**
`winter`For winter season January, February, March
`spring`For spring season April, May, June
`summer`For summer season July, August, September
`fall`For fall season October, November, December
`current`For the current Season
| -| `year` | **Description:** Year to search
**Default:** Current Year
**Values:** Number between `1917` and the current year. | -| `sort_by` | **Description:** Sort Order
**Default:** `members`
**Values:**
`members`Sort by Most Members
`score`Sort by Score
| -| `limit` | **Description:** Don't return more then this number
**Default:** `100`
**Values:** Number of Anime to query from MyAnimeList (max: 500) | +| Attribute | Description & Values | +|:----------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `season` | **Description:** Season to search
**Default:** `current`
**Values:**
`winter`For winter season January, February, March
`spring`For spring season April, May, June
`summer`For summer season July, August, September
`fall`For fall season October, November, December
`current`For the current Season
| +| `year` | **Description:** Year to search
**Default:** Current Year
**Values:** Number between `1917` and the current year. | +| `sort_by` | **Description:** Sort Order
**Default:** `members`
**Values:**
`members`Sort by Most Members
`score`Sort by Score
| +| `limit` | **Description:** Don't return more then this number
**Default:** `100`
**Values:** Number of Anime to query from MyAnimeList (max: 500) | +| `starting_only` | **Description:** Return only anime that began airing in the selected season
**Default:** `False`
**Values:** `True` or `False` | ```yaml collections: diff --git a/modules/builder.py b/modules/builder.py index 9b09ad6d..243a24cb 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -1233,7 +1233,8 @@ class CollectionBuilder: "season": season, "sort_by": util.parse(self.Type, "sort_by", dict_data, methods=dict_methods, parent=method_name, default="members", options=mal.season_sort_options, translation=mal.season_sort_translation), "year": util.parse(self.Type, "year", dict_data, datatype="int", methods=dict_methods, default=self.current_year, parent=method_name, minimum=1917, maximum=self.current_year + 1), - "limit": util.parse(self.Type, "limit", dict_data, datatype="int", methods=dict_methods, default=100, parent=method_name, maximum=500) + "limit": util.parse(self.Type, "limit", dict_data, datatype="int", methods=dict_methods, default=100, parent=method_name, maximum=500), + "starting_only": util.parse(self.Type, "starting_only", dict_data, datatype="bool", methods=dict_methods, default=False, parent=method_name) })) elif method_name == "mal_userlist": self.builders.append((method_name, { diff --git a/modules/mal.py b/modules/mal.py index c388b6f7..94963451 100644 --- a/modules/mal.py +++ b/modules/mal.py @@ -210,9 +210,9 @@ class MyAnimeList: self._delay = time.time() return data - def _parse_request(self, url): + def _parse_request(self, url, node=False): data = self._request(url) - return [d["node"]["id"] for d in data["data"]] if "data" in data else [] + return [d["node"] if node else d["node"]["id"] for d in data["data"]] if "data" in data else [] def _username(self): return self._request(f"{urls['user']}/@me")["name"] @@ -221,9 +221,18 @@ class MyAnimeList: url = f"{urls['ranking']}?ranking_type={ranking_type}&limit={limit}" return self._parse_request(url) - def _season(self, season, year, sort_by, limit): - url = f"{urls['season']}/{year}/{season}?sort={sort_by}&limit={limit}" - return self._parse_request(url) + def _season(self, data): + url = f"{urls['season']}/{data['year']}/{data['season']}?sort={data['sort_by']}&limit=500" + if data["starting_only"]: + url += "&fields=start_season" + results = [] + for anime in self._parse_request(url, node=True): + if data["starting_only"] and (anime["start_season"]["year"] != data["year"] or anime["start_season"]["season"] != data["season"]): + continue + results.append(anime["id"]) + if len(results) == data["limit"]: + break + return results def _suggestions(self, limit): url = f"{urls['suggestions']}?limit={limit}" @@ -299,7 +308,7 @@ class MyAnimeList: mal_ids = [mal_data["mal_id"] for mal_data in self._pagination("anime", params=data[0], limit=data[2])] elif method == "mal_season": logger.info(f"Processing MyAnimeList Season: {data['limit']} Anime from {data['season'].title()} {data['year']} sorted by {pretty_names[data['sort_by']]}") - mal_ids = self._season(data["season"], data["year"], data["sort_by"], data["limit"]) + mal_ids = self._season(data) elif method == "mal_suggested": logger.info(f"Processing MyAnimeList Suggested: {data} Anime") mal_ids = self._suggestions(data)