From db8fbeac3e042a30bf1df8c5564e6aaadbe65772 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Thu, 2 Feb 2023 21:51:00 -0500 Subject: [PATCH] [56] new anidb mass genre options --- VERSION | 2 +- docs/config/operations.md | 31 ++++++++++++++++++------------- modules/anidb.py | 8 +++++--- modules/cache.py | 19 +++++++++---------- modules/operations.py | 8 +++----- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/VERSION b/VERSION index b6adc40c..29ed74f7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.3-develop55 +1.18.3-develop56 diff --git a/docs/config/operations.md b/docs/config/operations.md index fbb61124..7f6ab1d2 100644 --- a/docs/config/operations.md +++ b/docs/config/operations.md @@ -85,19 +85,24 @@ Updates every item's genres in the library to the chosen site's genres. **Values:** -| Value | Description | -|:------------|:-----------------------------------| -| `tmdb` | Use TMDb for Genres | -| `tvdb` | Use TVDb for Genres | -| `imdb` | Use IMDb for Genres | -| `omdb` | Use IMDb through OMDb for Genres | -| `anidb` | Use AniDB Main Tags for Genres | -| `anidb_all` | Use All AniDB Tags for Genres | -| `mal` | Use MyAnimeList for Genres | -| `lock` | Lock Genre Field | -| `unlock` | Unlock Genre Field | -| `remove` | Remove all Genres and Lock Field | -| `reset` | Remove all Genres and Unlock Field | +| Value | Description | +|:------------|:---------------------------------------------------------------| +| `tmdb` | Use TMDb for Genres | +| `tvdb` | Use TVDb for Genres | +| `imdb` | Use IMDb for Genres | +| `omdb` | Use IMDb through OMDb for Genres | +| `anidb` | Use AniDB Main Tags for Genres | +| `anidb_3_0` | Use AniDB Main Tags and All 3 Star Tags and above for Genres | +| `anidb_2_5` | Use AniDB Main Tags and All 2.5 Star Tags and above for Genres | +| `anidb_2_0` | Use AniDB Main Tags and All 2 Star Tags and above for Genres | +| `anidb_1_5` | Use AniDB Main Tags and All 1.5 Star Tags and above for Genres | +| `anidb_1_0` | Use AniDB Main Tags and All 1 Star Tags and above for Genres | +| `anidb_0_5` | Use AniDB Main Tags and All 0.5 Star Tags and above for Genres | +| `mal` | Use MyAnimeList for Genres | +| `lock` | Lock Genre Field | +| `unlock` | Unlock Genre Field | +| `remove` | Remove all Genres and Lock Field | +| `reset` | Remove all Genres and Unlock Field | ## Mass Content Rating Update diff --git a/modules/anidb.py b/modules/anidb.py index 1591a95b..4f30d81c 100644 --- a/modules/anidb.py +++ b/modules/anidb.py @@ -15,6 +15,7 @@ urls = { "tag": f"{base_url}/tag", "login": f"{base_url}/perl-bin/animedb.pl" } +weights = {"anidb": 1000, "anidb_3_0": 600, "anidb_2_5": 500, "anidb_2_0": 400, "anidb_1_5": 300, "anidb_1_0": 200, "anidb_0_5": 100} class AniDBObj: def __init__(self, anidb, anidb_id, data): @@ -36,7 +37,9 @@ class AniDBObj: else: return data[attr] parse_results = data.xpath(xpath) - if is_dict: + if attr == "tags": + return {ta.xpath("name/text()")[0]: 1001 if ta.get("infobox") else int(ta.get("weight")) for ta in parse_results} + elif attr == "titles": return {ta.get("xml:lang"): ta.text_content() for ta in parse_results} elif len(parse_results) > 0: parse_results = [r.strip() for r in parse_results if len(r) > 0] @@ -68,8 +71,7 @@ class AniDBObj: self.average = _parse("average", "//anime/ratings/temporary/text()", is_float=True) self.score = _parse("score", "//anime/ratings/review/text()", is_float=True) self.released = _parse("released", "//anime/startdate/text()", is_date=True) - self.tags = _parse("tags", "//anime/tags/tag[@infobox='true']/name/text()", is_list=True) - self.all_tags = _parse("all_tags", "//anime/tags/tag/name/text()", is_list=True) + self.tags = _parse("tags", "//anime/tags/tag", is_dict=True) self.mal_id = _parse("mal_id", "//anime/resources/resource[@type='2']/externalentity/identifier/text()", is_int=True) self.imdb_id = _parse("imdb_id", "//anime/resources/resource[@type='43']/externalentity/identifier/text()") if isinstance(data, dict): diff --git a/modules/cache.py b/modules/cache.py index 9fdd0351..b00d5610 100644 --- a/modules/cache.py +++ b/modules/cache.py @@ -1,4 +1,4 @@ -import os, random, sqlite3 +import json, os, random, sqlite3 from contextlib import closing from datetime import datetime, timedelta from modules import util @@ -32,6 +32,7 @@ class Cache: cursor.execute("DROP TABLE IF EXISTS overlay_ratings") cursor.execute("DROP TABLE IF EXISTS anidb_data") cursor.execute("DROP TABLE IF EXISTS anidb_data2") + cursor.execute("DROP TABLE IF EXISTS anidb_data3") cursor.execute("DROP TABLE IF EXISTS mal_data") cursor.execute( """CREATE TABLE IF NOT EXISTS guids_map ( @@ -124,7 +125,7 @@ class Cache: expiration_date TEXT)""" ) cursor.execute( - """CREATE TABLE IF NOT EXISTS anidb_data3 ( + """CREATE TABLE IF NOT EXISTS anidb_data4 ( key INTEGER PRIMARY KEY, anidb_id INTEGER UNIQUE, main_title TEXT, @@ -135,7 +136,6 @@ class Cache: score REAL, released TEXT, tags TEXT, - all_tags TEXT, mal_id INTEGER, imdb_id TEXT, tmdb_id INTEGER, @@ -535,7 +535,7 @@ class Cache: with sqlite3.connect(self.cache_path) as connection: connection.row_factory = sqlite3.Row with closing(connection.cursor()) as cursor: - cursor.execute("SELECT * FROM anidb_data3 WHERE anidb_id = ?", (anidb_id,)) + cursor.execute("SELECT * FROM anidb_data4 WHERE anidb_id = ?", (anidb_id,)) row = cursor.fetchone() if row: anidb_dict["main_title"] = row["main_title"] @@ -546,7 +546,6 @@ class Cache: anidb_dict["score"] = row["score"] if row["score"] else None anidb_dict["released"] = row["released"] if row["released"] else None anidb_dict["tags"] = row["tags"] if row["tags"] else None - anidb_dict["all_tags"] = row["all_tags"] if row["all_tags"] else None anidb_dict["mal_id"] = row["mal_id"] if row["mal_id"] else None anidb_dict["imdb_id"] = row["imdb_id"] if row["imdb_id"] else None anidb_dict["tmdb_id"] = row["tmdb_id"] if row["tmdb_id"] else None @@ -561,12 +560,12 @@ class Cache: with sqlite3.connect(self.cache_path) as connection: connection.row_factory = sqlite3.Row with closing(connection.cursor()) as cursor: - cursor.execute("INSERT OR IGNORE INTO anidb_data3(anidb_id) VALUES(?)", (anidb_id,)) - update_sql = "UPDATE anidb_data3 SET main_title = ?, titles = ?, studio = ?, rating = ?, average = ?, score = ?, " \ - "released = ?, tags = ?, all_tags = ?, mal_id = ?, imdb_id = ?, tmdb_id = ?, tmdb_type = ?, expiration_date = ? WHERE anidb_id = ?" + cursor.execute("INSERT OR IGNORE INTO anidb_data4(anidb_id) VALUES(?)", (anidb_id,)) + update_sql = "UPDATE anidb_data4 SET main_title = ?, titles = ?, studio = ?, rating = ?, average = ?, score = ?, " \ + "released = ?, tags = ?, mal_id = ?, imdb_id = ?, tmdb_id = ?, tmdb_type = ?, expiration_date = ? WHERE anidb_id = ?" cursor.execute(update_sql, ( - anidb.main_title, str(anidb.titles), anidb.studio, anidb.rating, anidb.average, anidb.score, - anidb.released.strftime("%Y-%m-%d") if anidb.released else None, "|".join(anidb.tags), "|".join(anidb.all_tags), + anidb.main_title, json.dumps(anidb.titles), anidb.studio, anidb.rating, anidb.average, anidb.score, + anidb.released.strftime("%Y-%m-%d") if anidb.released else None, json.dumps(anidb.tags), anidb.mal_id, anidb.imdb_id, anidb.tmdb_id, anidb.tmdb_type, expiration_date.strftime("%Y-%m-%d"), anidb_id )) diff --git a/modules/operations.py b/modules/operations.py index 42d77681..c8404b74 100644 --- a/modules/operations.py +++ b/modules/operations.py @@ -1,6 +1,6 @@ import os, re from datetime import datetime -from modules import plex, util +from modules import plex, util, anidb from modules.util import Failed, LimitReached, YAML from plexapi.exceptions import BadRequest, NotFound @@ -321,10 +321,8 @@ class Operations: new_genres = omdb_item.genres elif tvdb_item and self.library.mass_genre_update == "tvdb": new_genres = tvdb_item.genres - elif anidb_item and self.library.mass_genre_update == "anidb": - new_genres = [str(t).title() for t in anidb_item.tags] - elif anidb_item and self.library.mass_genre_update == "anidb_all": - new_genres = [str(t).title() for t in anidb_item.all_tags] + elif anidb_item and self.library.mass_genre_update in anidb.weights: + new_genres = [str(t).title() for t, w in anidb_item.tags.items() if w >= anidb.weights[self.library.mass_genre_update]] elif mal_item and self.library.mass_genre_update == "mal": new_genres = mal_item.genres else: