[28] add anilist score

pull/1719/head
meisnate12 1 year ago
parent 8f964de9f2
commit 67bec92f9c

@ -1 +1 @@
1.19.1-develop27 1.19.1-develop28

@ -107,11 +107,17 @@ 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. The `sync_mode: sync` and `collection_order: custom` Details are recommended since the lists are continuously updated and in a specific order.
| Attribute | Description | | Attribute | Description |
|:------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |:------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `username` | **Description:** A user's AniList Username | | `username` | **Description:** A user's AniList Username |
| `list_name` | **Description:** A user's AniList List Name | | `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> | | `score.gt`<sup>1</sup> | **Description:** Only return items that have a score greater then the given number.<br>**Values:** `0.0`-`10.0` |
| `score.gte`<sup>1</sup> | **Description:** Only return items that have a score greater then or equal to the given number.<br>**Values:** `0.0`-`10.0` |
| `score.lt`<sup>1</sup> | **Description:** Only return items that have a score less then the given number.<br>**Values:** `0.0`-`10.0` |
| `score.lte`<sup>1</sup> | **Description:** Only return items that have a score less then or equal to the given number.<br>**Values:** `0.0`-`10.0` |
| `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> |
<sup>1</sup> You can use multiple score filters but the number will have to match every filter. All unrated items are considered to have a 0 rating.
```yaml ```yaml
collections: collections:

@ -4,13 +4,13 @@ This builder finds its items by using the features of Plex.
No configuration is required for these builders. No configuration is required for these builders.
| Attribute | Description | Works with Movies | Works with Shows | Works with Playlists and Custom Sort | | Attribute | Description | Works with Movies | Works with Shows | Works with Playlists and Custom Sort |
|:----------------------------------------------|:-----------------------------------------------------------------------------|:-----------------:|:----------------:|:------------------------------------:| |:----------------------------------------------|:----------------------------------------------------------------------------|:-----------------:|:----------------:|:------------------------------------:|
| [`plex_all`](#plex-all) | Gets every movie/show in your library. Useful with [Filters](filters.md) | &#9989; | &#9989; | &#10060; | | [`plex_all`](#plex-all) | Gets every movie/show in your library. Useful with [Filters](filters.md) | &#9989; | &#9989; | &#10060; |
| [`plex_watchlist`](#plex-watchlist) | Gets every movie/show in your Watchlist. | &#9989; | &#9989; | &#9989; | | [`plex_watchlist`](#plex-watchlist) | Gets every movie/show in your Watchlist. | &#9989; | &#9989; | &#9989; |
| [`plex_pilots`](#plex-pilots) | Gets the first episode of every show in your library | &#10060; | &#9989; | &#9989; | | [`plex_pilots`](#plex-pilots) | Gets the first episode of every show in your library | &#10060; | &#9989; | &#9989; |
| [`plex_collectionless`](#plex-collectionless.md) | Gets every movie/show that is not in a collection | &#9989; | &#9989; | &#10060; | | [`plex_collectionless`](#plex-collectionless) | Gets every movie/show that is not in a collection | &#9989; | &#9989; | &#10060; |
| [`plex_search`](#plex-search) | Gets every movie/show based on the search parameters provided | &#9989; | &#9989; | &#9989; | | [`plex_search`](#plex-search) | Gets every movie/show based on the search parameters provided | &#9989; | &#9989; | &#9989; |
## Plex All ## Plex All

@ -6,8 +6,8 @@ function checkURLForBranch() {
if (currentURL.indexOf("nightly") !== -1) { if (currentURL.indexOf("nightly") !== -1) {
// If "config" is found in the URL, change the CSS of .md-header to red // If "config" is found in the URL, change the CSS of .md-header to red
document.querySelector(".md-header").style.backgroundColor = "#ef5552"; document.querySelector(".md-header").style.backgroundColor = "#262dbd";
document.querySelector(".md-tabs").style.backgroundColor = "#ef5552"; document.querySelector(".md-tabs").style.backgroundColor = "#262dbd";
// Change the text of <span class="md-ellipsis"> // Change the text of <span class="md-ellipsis">
const ellipsisSpan = document.querySelector(".md-ellipsis"); const ellipsisSpan = document.querySelector(".md-ellipsis");

@ -221,13 +221,14 @@ class AniList:
return anilist_ids, ignore_ids, name return anilist_ids, ignore_ids, name
def _userlist(self, username, list_name, sort_by): def _userlist(self, username, list_name, sort_by, score):
query = """ query = """
query ($user: String, $sort: [MediaListSort]) { query ($user: String, $sort: [MediaListSort]) {
MediaListCollection (userName: $user, sort: $sort, type: ANIME) { MediaListCollection (userName: $user, sort: $sort, type: ANIME) {
lists { lists {
name name
entries { entries {
score(format: POINT_10)
media{id} media{id}
} }
} }
@ -237,7 +238,7 @@ class AniList:
variables = {"user": username, "sort": userlist_sort_options[sort_by]} variables = {"user": username, "sort": userlist_sort_options[sort_by]}
for alist in self._request(query, variables)["data"]["MediaListCollection"]["lists"]: for alist in self._request(query, variables)["data"]["MediaListCollection"]["lists"]:
if alist["name"] == list_name: if alist["name"] == list_name:
return [m["media"]["id"] for m in alist["entries"]] return [m["media"]["id"] for m in alist["entries"] if not score or not any([util.is_number_filter(value, mod, m["score"]) for mod, value in score.items()])]
return [] return []
def validate_userlist(self, data): def validate_userlist(self, data):
@ -293,7 +294,7 @@ 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["list_name"], data["sort_by"]) anilist_ids = self._userlist(data["username"], data["list_name"], data["sort_by"], data["score"])
logger.info(f"Processing AniList Userlist: {data['list_name']} from {data['username']} sorted by {pretty_user[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":

@ -1393,11 +1393,22 @@ 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.config.AniList.validate_userlist({ new_dictionary = {
"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),
"list_name": util.parse(self.Type, "list_name", dict_data, methods=dict_methods, parent=method_name), "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), "sort_by": util.parse(self.Type, "sort_by", dict_data, methods=dict_methods, parent=method_name, default="score", options=anilist.userlist_sort_options),
}))) }
score_dict = {}
for search_method, search_data in dict_data.items():
search_attr, modifier = os.path.splitext(str(search_method).lower())
if search_attr == "score" and modifier in ["gt", "gte", "lt", "lte"]:
score = util.parse(self.Type, search_method, dict_data, datatype="int", default=-1, minimum=0, maximum=10, parent=method_name)
if score > -1:
score_dict[modifier] = score
elif search_attr not in ["username", "list_name", "sort_by"]:
raise Failed(f"{self.Type} Error: {method_name} {search_method} attribute not supported")
new_dictionary["score"] = score_dict
self.builders.append((method_name, self.config.AniList.validate_userlist(new_dictionary)))
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"
@ -2525,7 +2536,7 @@ class CollectionBuilder:
elif self.playlist and items_added: elif self.playlist and items_added:
self.obj.addItems(items_added) self.obj.addItems(items_added)
elif items_added: elif items_added:
self.library.alter_collection(items_added, name, smart_label_collection=self.smart_label_collection) self.library.alter_collection(items_added, name, smart_label_collection=self.smart_label_collection)
if self.do_report and items_added: if self.do_report and items_added:
self.library.add_additions(self.name, [(i.title, self.library.get_id_from_maps(i.ratingKey)) for i in items_added], self.library.is_movie) self.library.add_additions(self.name, [(i.title, self.library.get_id_from_maps(i.ratingKey)) for i in items_added], self.library.is_movie)
logger.exorcise() logger.exorcise()
@ -2555,7 +2566,7 @@ class CollectionBuilder:
self.library._reload(self.obj) self.library._reload(self.obj)
self.obj.removeItems(items_removed) self.obj.removeItems(items_removed)
elif items_removed: elif items_removed:
self.library.alter_collection(items_removed, self.name, smart_label_collection=self.smart_label_collection, add=False) self.library.alter_collection(items_removed, self.name, smart_label_collection=self.smart_label_collection, add=False)
if self.do_report and items_removed: if self.do_report and items_removed:
self.library.add_removed(self.name, [(i.title, self.library.get_id_from_maps(i.ratingKey)) for i in items_removed], self.library.is_movie) self.library.add_removed(self.name, [(i.title, self.library.get_id_from_maps(i.ratingKey)) for i in items_removed], self.library.is_movie)
logger.info("") logger.info("")

@ -882,16 +882,7 @@ class Plex(Library):
def alter_collection(self, items, collection, smart_label_collection=False, add=True): def alter_collection(self, items, collection, smart_label_collection=False, add=True):
self.Plex.batchMultiEdits(items) self.Plex.batchMultiEdits(items)
if smart_label_collection: self.query_data(getattr(self.Plex, f"{'add' if add else 'remove'}{'Label' if smart_label_collection else 'Collection'}"), collection)
if add:
self.Plex.addLabel(collection)
else:
self.Plex.removeLabel(collection)
else:
if add:
self.Plex.addCollection(collection)
else:
self.Plex.removeCollection(collection)
self.Plex.saveMultiEdits() self.Plex.saveMultiEdits()
def move_item(self, collection, item, after=None): def move_item(self, collection, item, after=None):

Loading…
Cancel
Save