[10] update anilist_userlist

pull/779/head
meisnate12 3 years ago
parent 206e38a264
commit 54383bafb0

@ -1 +1 @@
1.16.1-develop9 1.16.1-develop10

@ -12,8 +12,8 @@ No configuration is required for these builders.
| [`anilist_relations`](#anilist-relations) | Finds the anime specified by the AniList ID and every relation in its relation tree except Character and Other relations | ✅ | ✅ | ❌ | | [`anilist_relations`](#anilist-relations) | Finds the anime specified by the AniList ID and every relation in its relation tree except Character and Other relations | ✅ | ✅ | ❌ |
| [`anilist_studio`](#anilist-studio) | Finds all anime specified by the AniList Studio ID | ✅ | ✅ | ❌ | | [`anilist_studio`](#anilist-studio) | Finds all anime specified by the AniList Studio ID | ✅ | ✅ | ❌ |
| [`anilist_id`](#anilist-id) | Finds the anime specified by the AniList ID | ✅ | ✅ | ❌ | | [`anilist_id`](#anilist-id) | Finds the anime specified by the AniList ID | ✅ | ✅ | ❌ |
| [`anilist_userlist`](#anilist-userlist) | Finds the anime in AniList User's Anime list the options are detailed below | ✅ | ✅ | ✅ |
| [`anilist_search`](#anilist-search) | Finds the anime specified by the AniList search parameters provided | ✅ | ✅ | ✅ | | [`anilist_search`](#anilist-search) | Finds the anime specified by the AniList search parameters provided | ✅ | ✅ | ✅ |
| [`anilist_userlist`](#anilist-userlist) | Finds anime in AniList User's Anime list the options are detailed below | ✅ | ✅ | ✅ |
## AniList Top Rated Anime ## AniList Top Rated Anime
@ -99,6 +99,31 @@ collections:
anilist_id: 23, 219 anilist_id: 23, 219
``` ```
## AniList UserList
Gets anime in AniList User's Anime list. The different sub-attributes are detailed below.
Both `username` and `list_name` are required.
The `sync_mode: sync` and `collection_order: custom` Details are recommended since the lists are continuously updated and in a specific order.
| Attribute | Description |
|:------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `username` | **Description:** A user's AniList Username |
| `list_name` | **Description:** A user's AniList List Name |
| `sort_by` | **Description:** Sort Order to return<br>**Default:** `score`<br>**Values:**<table class="clearTable"><tr><td>`score`</td><td>Sort by User Score</td></tr><tr><td>`popularity`</td><td>Sort by Popularity</td></tr><tr><td>`status`</td><td>Sort by Status</td></tr><tr><td>`progress`</td><td>Sort by Progress</td></tr><tr><td>`last_updated`</td><td>Sort by Last Updated</td></tr><tr><td>`last_added`</td><td>Sort by Last Added</td></tr><tr><td>`start_date`</td><td>Sort by Start Date</td></tr><tr><td>`completed_date`</td><td>Sort by Completed Date</td></tr></table> |
```yaml
collections:
Currently Watching Anime:
anilist_userlist:
username: Username
list_name: Watching
sort_by: score
collection_order: custom
sync_mode: sync
```
## AniList Search ## AniList Search
Finds the anime specified by the AniList Search the options are detailed below. Finds the anime specified by the AniList Search the options are detailed below.
@ -229,28 +254,4 @@ collections:
sort_by: popular sort_by: popular
collection_order: custom collection_order: custom
sync_mode: sync sync_mode: sync
``` ```
## AniList UserList
Gets anime in AniList User's Anime list. The different sub-attributes are detailed below. The only required attribute is `username`
The `sync_mode: sync` and `collection_order: custom` Details are recommended since the lists are continuously updated and in a specific order.
| Attribute | Description |
|:-----------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `username` | **Description:** A user's AniList Username |
| `status` | **Description:** Status to search for<br>**Default:** `watching`<br>**Values:**<table class="clearTable"><tr><td>`watching`</td><td>Currently Watching List</td></tr><tr><td>`completed`</td><td>Completed List</td></tr><tr><td>`paused`</td><td>Paused List</td></tr><tr><td>`dropped`</td><td>Dropped List</td></tr><tr><td>`planning`</td><td>Planning</td></tr></table> |
| `sort_by` | **Description:** Sort Order to return<br>**Default:** `score`<br>**Values:**<table class="clearTable"><tr><td>`score`</td><td>Sort by Score</td></tr><tr><td>`last_updated`</td><td>Sort by Last Updated</td></tr><tr><td>`title`</td><td>Sort by Anime Title</td></tr><tr><td>`start_date`</td><td>Sort by Start Date</td></tr></table> |
```yaml
collections:
Currently Watching Anime:
anilist_userlist:
username: "Username"
status: watching
sort_by: score
collection_order: custom
sync_mode: sync
```

@ -5,11 +5,11 @@ from modules.util import Failed
logger = util.logger logger = util.logger
builders = ["anilist_id", "anilist_popular", "anilist_trending", "anilist_relations", "anilist_studio", "anilist_top_rated", "anilist_search", "anilist_userlist"] builders = ["anilist_id", "anilist_popular", "anilist_trending", "anilist_relations", "anilist_studio", "anilist_top_rated", "anilist_search", "anilist_userlist"]
pretty_names = { pretty_names = {"score": "Average Score", "popular": "Popularity", "trending": "Trending"}
"score": "Average Score", "popular": "Popularity", "trending": "Trending", "CURRENT": "Currently Watching", pretty_user = {
"COMPLETED": "Completed", "PAUSED": "Paused", "DROPPED": "Dropped", "PLANNING": "Planning", "SCORE": "Score", "status": "Status", "score": "User Score", "progress": "Progress", "last_updated": "Last Updated",
"UPDATED_TIME": "Updated Time", "STARTED_ON": "Start Date", "MEDIA_TITLE_NATIVE": "Title" "last_added": "Last Added", "start_date": "Start Date", "completed_date": "Completed Date", "popularity": "Popularity"
} }
attr_translation = { attr_translation = {
"year": "seasonYear", "adult": "isAdult", "start": "startDate", "end": "endDate", "tag_category": "tagCategory", "year": "seasonYear", "adult": "isAdult", "start": "startDate", "end": "endDate", "tag_category": "tagCategory",
"score": "averageScore", "min_tag_percent": "minimumTagRank", "country": "countryOfOrigin", "score": "averageScore", "min_tag_percent": "minimumTagRank", "country": "countryOfOrigin",
@ -24,16 +24,10 @@ mod_searches = [
no_mod_searches = ["search", "season", "year", "adult", "min_tag_percent", "limit", "sort_by", "source", "country"] no_mod_searches = ["search", "season", "year", "adult", "min_tag_percent", "limit", "sort_by", "source", "country"]
searches = mod_searches + no_mod_searches searches = mod_searches + no_mod_searches
sort_options = {"score": "SCORE_DESC", "popular": "POPULARITY_DESC", "trending": "TRENDING_DESC"} sort_options = {"score": "SCORE_DESC", "popular": "POPULARITY_DESC", "trending": "TRENDING_DESC"}
userlist_sort_options = ["score", "last_updated", "title", "start_date"] userlist_sort_options = {
userlist_sort_translation = { "score": "SCORE_DESC", "status": "STATUS_DESC", "progress": "PROGRESS_DESC",
"score": "SCORE", "last_updated": "UPDATED_TIME", "last_updated": "UPDATED_TIME_DESC", "last_added": "ADDED_TIME_DESC", "start_date": "STARTED_ON_DESC",
"title": "MEDIA_TITLE_NATIVE", "start_date": "STARTED_ON" "completed_date": "FINISHED_ON_DESC", "popularity": "MEDIA_POPULARITY_DESC"
}
userlist_status = ["watching", "completed", "paused", "dropped", "planning"]
userlist_status_translation = {
"watching": "CURRENT", "completed": "COMPLETED",
"paused": "PAUSED", "dropped" :"DROPPED",
"planning": "PLANNING"
} }
media_season = {"winter": "WINTER", "spring": "SPRING", "summer": "SUMMER", "fall": "FALL"} media_season = {"winter": "WINTER", "spring": "SPRING", "summer": "SUMMER", "fall": "FALL"}
media_format = {"tv": "TV", "short": "TV_SHORT", "movie": "MOVIE", "special": "SPECIAL", "ova": "OVA", "ona": "ONA", "music": "MUSIC"} media_format = {"tv": "TV", "short": "TV_SHORT", "movie": "MOVIE", "special": "SPECIAL", "ova": "OVA", "ona": "ONA", "music": "MUSIC"}
@ -225,16 +219,43 @@ class AniList:
return anilist_ids, ignore_ids, name return anilist_ids, ignore_ids, name
def _userlist(self, username, status, sort_by): def _userlist(self, username, list_name, sort_by):
query = "query ($userName: String, $status: MediaListStatus) {MediaListCollection (userName: $userName, status: $status, type: ANIME) {lists {status entries {media{id title{romaji english}}}}}}" query = """
variables = {"userName": username, "status": status, "sort": sort_by} query ($user: String, $sort: MediaListStatus) {
MediaListCollection (userName: $user, sort: $sort, type: ANIME) {
lists {
name
entries {
media{id}
}
}
}
}
"""
variables = {"user": username, "sort": userlist_sort_options[sort_by]}
for alist in self._request(query, variables)["data"]["MediaListCollection"]["lists"]:
if alist["name"] == list_name:
return [m["media"]["id"] for m in alist["entries"]]
return []
def validate_userlist(self, data):
query = """
query ($user: String) {
MediaListCollection (userName: $user, type: ANIME) {
lists {name}
}
}
"""
variables = {"user": data["username"]}
json_obj = self._request(query, variables) json_obj = self._request(query, variables)
lists = json_obj['data']['MediaListCollection']['lists'] if not json_obj["data"]["MediaListCollection"]:
anilist_ids = [] raise Failed(f"AniList Error: User: {data['username']} not found")
for list in lists: list_names = [n["name"] for n in json_obj["data"]["MediaListCollection"]["lists"]]
for media in list['entries']: if not list_names:
anilist_ids.append(media['media']['id']) raise Failed(f"AniList Error: User: {data['username']} has no Lists")
return anilist_ids if data["list_name"] in list_names:
return data
raise Failed(f"AniList Error: List: {data['list_name']} not found\nOptions: {', '.join(list_names)}")
def validate(self, name, data): def validate(self, name, data):
valid = [] valid = []
@ -270,8 +291,8 @@ class AniList:
anilist_ids, _, name = self._relations(data) anilist_ids, _, name = self._relations(data)
logger.info(f"Processing AniList Relations: ({data}) {name} ({len(anilist_ids)} Anime)") logger.info(f"Processing AniList Relations: ({data}) {name} ({len(anilist_ids)} Anime)")
elif method == "anilist_userlist": elif method == "anilist_userlist":
anilist_ids = self._userlist(data["username"], data["status"], data['sort_by']) anilist_ids = self._userlist(data["username"], data["list_name"], data["sort_by"])
logger.info(f"Processing AniList Userlist: Anime from {data['username']}'s {pretty_names[data['status']]} list sorted by {pretty_names[data['sort_by']]}") logger.info(f"Processing AniList Userlist: {data['list_name']} from {data['username']} sorted by {pretty_user[data['sort_by']]}")
else: else:
if method == "anilist_popular": if method == "anilist_popular":
data = {"limit": data, "popularity.gt": 3, "sort_by": "popular"} data = {"limit": data, "popularity.gt": 3, "sort_by": "popular"}

@ -958,11 +958,11 @@ class CollectionBuilder:
elif method_name == "anilist_userlist": elif method_name == "anilist_userlist":
for dict_data in util.parse(self.Type, method_name, method_data, datatype="listdict"): for dict_data in util.parse(self.Type, method_name, method_data, datatype="listdict"):
dict_methods = {dm.lower(): dm for dm in dict_data} dict_methods = {dm.lower(): dm for dm in dict_data}
self.builders.append((method_name, { self.builders.append((method_name, self.config.AniList.validate_userlist({
"username": util.parse(self.Type, "username", dict_data, methods=dict_methods, parent=method_name), "username": util.parse(self.Type, "username", dict_data, methods=dict_methods, parent=method_name),
"status": util.parse(self.Type, "status", dict_data, methods=dict_methods, parent=method_name, default="watching", options=anilist.userlist_status, translation=anilist.userlist_status_translation), "list_name": util.parse(self.Type, "list_name", dict_data, methods=dict_methods, parent=method_name),
"sort_by": util.parse(self.Type, "sort_by", dict_data, methods=dict_methods, parent=method_name, default="score", options=anilist.userlist_sort_options, translation=anilist.userlist_sort_translation), "sort_by": util.parse(self.Type, "sort_by", dict_data, methods=dict_methods, parent=method_name, default="score", options=anilist.userlist_sort_options),
})) })))
elif method_name == "anilist_search": elif method_name == "anilist_search":
if self.current_time.month in [12, 1, 2]: current_season = "winter" if self.current_time.month in [12, 1, 2]: current_season = "winter"
elif self.current_time.month in [3, 4, 5]: current_season = "spring" elif self.current_time.month in [3, 4, 5]: current_season = "spring"

Loading…
Cancel
Save