Skip to content

Commit

Permalink
fix parental labels (#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 authored Nov 1, 2024
1 parent ca485c4 commit 0167b82
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
done
- name: Run Spellcheck
uses: rojopolis/spellcheck-github-actions@0.43.1
uses: rojopolis/spellcheck-github-actions@0.44.0

docker-build-pull:
runs-on: ubuntu-latest
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Requirements Update (requirements will need to be reinstalled)
Update pillow requirement to 11.0.0
Update psutil requirement to 6.1.0
Update setuptools requirement to 75.2.0
Update setuptools requirement to 75.3.0

# New Features
Added the `character` search option to the `imdb_search` builder

# Defaults
Fixed incorrect content rating mappings in various Default files
Fixes an issue where Prime Video overlays/collections would not be built when the `watch_region` is set to AU
fixes an issue where Rotten Tomatoes Verified Hot wasn't working

# Bug Fixes
Fixed the `cast` search option for the `imdb_search` builder
Expand All @@ -17,3 +18,5 @@ Fixes `letterboxd_list` rating filter to use a 1-10 rating vs 1-100 to reflect h
Fixes #2274 Enhance handling of smart collections in deletion
Fixed the `ids_to_anidb` lookup for anime movies and shows
Fixes an issue where episode overlays sometimes wouldn't be added
Fixes an issue with IMDb Parental Labels not working
Fixes an issue where OMDb returned `N/A` as the content rating
2 changes: 1 addition & 1 deletion PART
Original file line number Diff line number Diff line change
@@ -1 +1 @@

3
2 changes: 1 addition & 1 deletion defaults/overlays/ratings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ templates:
image_extra:
default: ""
conditions:
- rating<<rating_num>>_image: [imdb, rt_tomato, metacritic]
- rating<<rating_num>>_image: [imdb, rt_popcorn, rt_tomato, metacritic]
image_level: Top
value: Top
- rating<<rating_num>>_image: [rt_popcorn, rt_tomato]
Expand Down
14 changes: 7 additions & 7 deletions modules/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,11 +1035,11 @@ def query_imdb_parental(self, imdb_id, expiration):
cursor.execute("SELECT * FROM imdb_parental WHERE imdb_id = ?", (imdb_id,))
row = cursor.fetchone()
if row:
imdb_dict["nudity"] = row["nudity"] if row["nudity"] else "None"
imdb_dict["violence"] = row["violence"] if row["violence"] else "None"
imdb_dict["profanity"] = row["profanity"] if row["profanity"] else "None"
imdb_dict["alcohol"] = row["alcohol"] if row["alcohol"] else "None"
imdb_dict["frightening"] = row["frightening"] if row["frightening"] else "None"
imdb_dict["Nudity"] = row["nudity"] if row["nudity"] else "None"
imdb_dict["Violence"] = row["violence"] if row["violence"] else "None"
imdb_dict["Profanity"] = row["profanity"] if row["profanity"] else "None"
imdb_dict["Alcohol"] = row["alcohol"] if row["alcohol"] else "None"
imdb_dict["Frightening"] = row["frightening"] if row["frightening"] else "None"
datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d")
time_between_insertion = datetime.now() - datetime_object
expired = time_between_insertion.days > expiration
Expand All @@ -1053,8 +1053,8 @@ def update_imdb_parental(self, expired, imdb_id, parental, expiration):
cursor.execute("INSERT OR IGNORE INTO imdb_parental(imdb_id) VALUES(?)", (imdb_id,))
update_sql = "UPDATE imdb_parental SET nudity = ?, violence = ?, profanity = ?, alcohol = ?, " \
"frightening = ?, expiration_date = ? WHERE imdb_id = ?"
cursor.execute(update_sql, (parental["nudity"], parental["violence"], parental["profanity"], parental["alcohol"],
parental["frightening"], expiration_date.strftime("%Y-%m-%d"), imdb_id))
cursor.execute(update_sql, (parental["Nudity"], parental["Violence"], parental["Profanity"], parental["Alcohol"],
parental["Frightening"], expiration_date.strftime("%Y-%m-%d"), imdb_id))

def query_ergast(self, year, expiration):
ergast_list = []
Expand Down
15 changes: 8 additions & 7 deletions modules/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,14 @@ def parental_guide(self, imdb_id, ignore_cache=False):
parental_dict, expired = self.cache.query_imdb_parental(imdb_id, self.cache.expiration)
if parental_dict and expired is False:
return parental_dict
response = self._request(f"{base_url}/title/{imdb_id}/parentalguide")
for ptype in util.parental_types:
results = response.xpath(f"//section[@id='advisory-{ptype}']//span[contains(@class,'ipl-status-pill')]/text()")
if results:
parental_dict[ptype] = results[0].strip()
else:
raise Failed(f"IMDb Error: No Item Found for IMDb ID: {imdb_id}")
for e in self._request(f"{base_url}/title/{imdb_id}/parentalguide", xpath="//li[contains(@class, 'ipc-metadata-list-item--link')]"):
parental_dict[util.parental_types[e.xpath("a/text()")[0][:-1]]] = e.xpath("div/div/div/text()")[0]
if parental_dict:
for _, v in util.parental_types.items():
if v not in parental_dict:
parental_dict[v] = None
else:
raise Failed(f"IMDb Error: No Parental Guide Found for IMDb ID: {imdb_id}")
if self.cache and not ignore_cache:
self.cache.update_imdb_parental(expired, imdb_id, parental_dict, self.cache.expiration)
return parental_dict
Expand Down
2 changes: 2 additions & 0 deletions modules/omdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def _parse(key, is_int=False, is_float=False, is_date=False, replace=None):
return float(value)
elif is_date:
return datetime.strptime(value, "%d %b %Y")
elif value == "N/A":
return None
else:
return value
except (ValueError, TypeError, KeyError):
Expand Down
2 changes: 1 addition & 1 deletion modules/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def should_be_deleted(col_in, labels_in, configured_in, managed_in, less_in, ign
parental_labels = []
else:
parental_guide = self.config.IMDb.parental_guide(imdb_id)
parental_labels = [f"{k.capitalize()}:{v}" for k, v in parental_guide.items() if v not in util.parental_levels[self.library.mass_imdb_parental_labels]]
parental_labels = [f"{k}:{v}" for k, v in parental_guide.items() if v and v not in util.parental_levels[self.library.mass_imdb_parental_labels]]
add_labels = [la for la in parental_labels if la not in current_labels]
remove_labels = [la for la in current_labels if la in util.parental_labels and la not in parental_labels]
for label_list, edit_type in [(add_labels, "add"), (remove_labels, "remove")]:
Expand Down
4 changes: 2 additions & 2 deletions modules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def __call__(self, retry_state):
"show_items": "showItems", "showitems": "showItems"
}
image_content_types = ["image/png", "image/jpeg", "image/webp"]
parental_types = ["nudity", "violence", "profanity", "alcohol", "frightening"]
parental_types = {"Sex & Nudity": "Nudity", "Violence & Gore": "Violence", "Profanity": "Profanity", "Alcohol, Drugs & Smoking": "Alcohol", "Frightening & Intense Scenes": "Frightening"}
parental_values = ["None", "Mild", "Moderate", "Severe"]
parental_levels = {"none": [], "mild": ["None"], "moderate": ["None", "Mild"], "severe": ["None", "Mild", "Moderate"]}
parental_labels = [f"{t.capitalize()}:{v}" for t in parental_types for v in parental_values]
parental_labels = [f"{t}:{v}" for t in parental_types.values() for v in parental_values]
previous_time = None
start_time = None

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ requests==2.32.3
tenacity==9.0.0
ruamel.yaml==0.18.6
schedule==1.2.2
setuptools==75.2.0
setuptools==75.3.0
tmdbapis==1.2.21

0 comments on commit 0167b82

Please sign in to comment.