[57] starting_only option added to mal_season

pull/1227/head
meisnate12 2 years ago
parent a136f4fa34
commit f81645245e

@ -1 +1 @@
1.18.0-develop56 1.18.0-develop57

@ -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. 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 | | Attribute | Description & Values |
|:----------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |:----------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `season` | **Description:** Season to search<br>**Default:** `current`<br>**Values:**<table class="clearTable"><tr><td>`winter`</td><td>For winter season January, February, March</td></tr><tr><td>`spring`</td><td>For spring season April, May, June</td></tr><tr><td>`summer`</td><td>For summer season July, August, September</td></tr><tr><td>`fall`</td><td>For fall season October, November, December</td></tr><tr><td>`current`</td><td>For the current Season</td></tr></table> | | `season` | **Description:** Season to search<br>**Default:** `current`<br>**Values:**<table class="clearTable"><tr><td>`winter`</td><td>For winter season January, February, March</td></tr><tr><td>`spring`</td><td>For spring season April, May, June</td></tr><tr><td>`summer`</td><td>For summer season July, August, September</td></tr><tr><td>`fall`</td><td>For fall season October, November, December</td></tr><tr><td>`current`</td><td>For the current Season</td></tr></table> |
| `year` | **Description:** Year to search<br>**Default:** Current Year<br>**Values:** Number between `1917` and the current year. | | `year` | **Description:** Year to search<br>**Default:** Current Year<br>**Values:** Number between `1917` and the current year. |
| `sort_by` | **Description:** Sort Order<br>**Default:** `members`<br>**Values:**<table class="clearTable"><tr><td>`members`</td><td>Sort by Most Members</td></tr><tr><td>`score`</td><td>Sort by Score</td></tr></table> | | `sort_by` | **Description:** Sort Order<br>**Default:** `members`<br>**Values:**<table class="clearTable"><tr><td>`members`</td><td>Sort by Most Members</td></tr><tr><td>`score`</td><td>Sort by Score</td></tr></table> |
| `limit` | **Description:** Don't return more then this number<br>**Default:** `100`<br>**Values:** Number of Anime to query from MyAnimeList (max: 500) | | `limit` | **Description:** Don't return more then this number<br>**Default:** `100`<br>**Values:** Number of Anime to query from MyAnimeList (max: 500) |
| `starting_only` | **Description:** Return only anime that began airing in the selected season<br>**Default:** `False`<br>**Values:** `True` or `False` |
```yaml ```yaml
collections: collections:

@ -1233,7 +1233,8 @@ class CollectionBuilder:
"season": season, "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), "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), "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": elif method_name == "mal_userlist":
self.builders.append((method_name, { self.builders.append((method_name, {

@ -210,9 +210,9 @@ class MyAnimeList:
self._delay = time.time() self._delay = time.time()
return data return data
def _parse_request(self, url): def _parse_request(self, url, node=False):
data = self._request(url) 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): def _username(self):
return self._request(f"{urls['user']}/@me")["name"] return self._request(f"{urls['user']}/@me")["name"]
@ -221,9 +221,18 @@ class MyAnimeList:
url = f"{urls['ranking']}?ranking_type={ranking_type}&limit={limit}" url = f"{urls['ranking']}?ranking_type={ranking_type}&limit={limit}"
return self._parse_request(url) return self._parse_request(url)
def _season(self, season, year, sort_by, limit): def _season(self, data):
url = f"{urls['season']}/{year}/{season}?sort={sort_by}&limit={limit}" url = f"{urls['season']}/{data['year']}/{data['season']}?sort={data['sort_by']}&limit=500"
return self._parse_request(url) 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): def _suggestions(self, limit):
url = f"{urls['suggestions']}?limit={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])] mal_ids = [mal_data["mal_id"] for mal_data in self._pagination("anime", params=data[0], limit=data[2])]
elif method == "mal_season": 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']]}") 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": elif method == "mal_suggested":
logger.info(f"Processing MyAnimeList Suggested: {data} Anime") logger.info(f"Processing MyAnimeList Suggested: {data} Anime")
mal_ids = self._suggestions(data) mal_ids = self._suggestions(data)

Loading…
Cancel
Save