[51] fix episode rating overlays

pull/1955/head
meisnate12 8 months ago
parent e730222921
commit 7ec1f78161

@ -1 +1 @@
1.20.0-develop48 1.20.0-develop51

@ -329,7 +329,7 @@ Each Special Text Variables has multiple modifiers that can be used to format th
| `audience_rating` | Plex Audience Rating | `Movies`, `Shows`, or `Episodes` | | `audience_rating` | Plex Audience Rating | `Movies`, `Shows`, or `Episodes` |
| `critic_rating` | Plex Critic Rating | `Movies`, `Shows`, or `Episodes` | | `critic_rating` | Plex Critic Rating | `Movies`, `Shows`, or `Episodes` |
| `user_rating` | Plex User Rating | `Movies`, `Shows`, `Seasons`, or `Episodes` | | `user_rating` | Plex User Rating | `Movies`, `Shows`, `Seasons`, or `Episodes` |
| `tmdb_rating` | TMDb Rating | `Movies`, `Shows`, or `Episodes` | | `tmdb_rating` | TMDb Rating | `Movies`, `Shows`, `Seasons`, or `Episodes` |
| `imdb_rating` | IMDb Rating | `Movies`, `Shows`, or `Episodes` | | `imdb_rating` | IMDb Rating | `Movies`, `Shows`, or `Episodes` |
| `trakt_user_rating` | Trakt User Rating | `Movies` or `Shows` | | `trakt_user_rating` | Trakt User Rating | `Movies` or `Shows` |
| `omdb_rating` | OMDb Rating | `Movies` or `Shows` | | `omdb_rating` | OMDb Rating | `Movies` or `Shows` |

@ -31,6 +31,7 @@ class Cache:
cursor.execute("DROP TABLE IF EXISTS tvdb_data") cursor.execute("DROP TABLE IF EXISTS tvdb_data")
cursor.execute("DROP TABLE IF EXISTS tvdb_data2") cursor.execute("DROP TABLE IF EXISTS tvdb_data2")
cursor.execute("DROP TABLE IF EXISTS tmdb_show_data") cursor.execute("DROP TABLE IF EXISTS tmdb_show_data")
cursor.execute("DROP TABLE IF EXISTS tmdb_show_data2")
cursor.execute("DROP TABLE IF EXISTS overlay_ratings") cursor.execute("DROP TABLE IF EXISTS overlay_ratings")
cursor.execute("DROP TABLE IF EXISTS anidb_data") cursor.execute("DROP TABLE IF EXISTS anidb_data")
cursor.execute("DROP TABLE IF EXISTS anidb_data2") cursor.execute("DROP TABLE IF EXISTS anidb_data2")
@ -187,7 +188,7 @@ class Cache:
expiration_date TEXT)""" expiration_date TEXT)"""
) )
cursor.execute( cursor.execute(
"""CREATE TABLE IF NOT EXISTS tmdb_show_data2 ( """CREATE TABLE IF NOT EXISTS tmdb_show_data3 (
key INTEGER PRIMARY KEY, key INTEGER PRIMARY KEY,
tmdb_id INTEGER UNIQUE, tmdb_id INTEGER UNIQUE,
title TEXT, title TEXT,
@ -669,7 +670,7 @@ class Cache:
with sqlite3.connect(self.cache_path) as connection: with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor: with closing(connection.cursor()) as cursor:
cursor.execute("SELECT * FROM tmdb_show_data2 WHERE tmdb_id = ?", (tmdb_id,)) cursor.execute("SELECT * FROM tmdb_show_data3 WHERE tmdb_id = ?", (tmdb_id,))
row = cursor.fetchone() row = cursor.fetchone()
if row: if row:
tmdb_dict["title"] = row["title"] if row["title"] else "" tmdb_dict["title"] = row["title"] if row["title"] else ""
@ -703,8 +704,8 @@ class Cache:
with sqlite3.connect(self.cache_path) as connection: with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor: with closing(connection.cursor()) as cursor:
cursor.execute("INSERT OR IGNORE INTO tmdb_show_data2(tmdb_id) VALUES(?)", (obj.tmdb_id,)) cursor.execute("INSERT OR IGNORE INTO tmdb_show_data3(tmdb_id) VALUES(?)", (obj.tmdb_id,))
update_sql = "UPDATE tmdb_show_data2 SET title = ?, original_title = ?, studio = ?, overview = ?, tagline = ?, imdb_id = ?, " \ update_sql = "UPDATE tmdb_show_data3 SET title = ?, original_title = ?, studio = ?, overview = ?, tagline = ?, imdb_id = ?, " \
"poster_url = ?, backdrop_url = ?, vote_count = ?, vote_average = ?, language_iso = ?, " \ "poster_url = ?, backdrop_url = ?, vote_count = ?, vote_average = ?, language_iso = ?, " \
"language_name = ?, genres = ?, keywords = ?, first_air_date = ?, last_air_date = ?, status = ?, " \ "language_name = ?, genres = ?, keywords = ?, first_air_date = ?, last_air_date = ?, status = ?, " \
"type = ?, tvdb_id = ?, countries = ?, seasons = ?, expiration_date = ? WHERE tmdb_id = ?" "type = ?, tvdb_id = ?, countries = ?, seasons = ?, expiration_date = ? WHERE tmdb_id = ?"

@ -24,6 +24,7 @@ date_vars = ["originally_available"]
types_for_var = { types_for_var = {
"movie_show_season_episode_artist_album": ["runtime", "user_rating", "title"], "movie_show_season_episode_artist_album": ["runtime", "user_rating", "title"],
"movie_show_episode_album": ["critic_rating", "originally_available"], "movie_show_episode_album": ["critic_rating", "originally_available"],
"movie_show_season_episode": ["tmdb_rating"],
"movie_show_episode": ["audience_rating", "content_rating", "tmdb_rating", "imdb_rating"], "movie_show_episode": ["audience_rating", "content_rating", "tmdb_rating", "imdb_rating"],
"movie_show": [ "movie_show": [
"original_title", "trakt_user_rating", "omdb_rating", "mdb_rating", "mdb_average_rating", "mdb_imdb_rating", "original_title", "trakt_user_rating", "omdb_rating", "mdb_rating", "mdb_average_rating", "mdb_imdb_rating",

@ -2,7 +2,7 @@ import os, re
from datetime import datetime from datetime import datetime
from modules import plex, util, overlay from modules import plex, util, overlay
from modules.builder import CollectionBuilder from modules.builder import CollectionBuilder
from modules.util import Failed, FilterFailed, NonExisting, NotScheduled, LimitReached from modules.util import Failed, FilterFailed, NotScheduled, LimitReached
from num2words import num2words from num2words import num2words
from plexapi.exceptions import BadRequest from plexapi.exceptions import BadRequest
from plexapi.video import Season, Episode from plexapi.video import Season, Episode
@ -255,15 +255,27 @@ class Overlays:
elif format_var in overlay.rating_sources: elif format_var in overlay.rating_sources:
found_rating = None found_rating = None
try: try:
tmdb_id, tvdb_id, imdb_id = self.library.get_ids(item) item_to_id = item.show() if isinstance(item, (Season, Episode)) else item
tmdb_id, tvdb_id, imdb_id = self.library.get_ids(item_to_id)
if format_var == "tmdb_rating": if format_var == "tmdb_rating":
_item = self.config.TMDb.get_item(item, tmdb_id, tvdb_id, imdb_id, is_movie=self.library.is_movie) _item = self.config.TMDb.get_item(item_to_id, tmdb_id, tvdb_id, imdb_id, is_movie=self.library.is_movie)
if _item: if _item:
found_rating = _item.vote_average if isinstance(item, Episode):
found_rating = self.config.TMDb.get_episode(_item.tmdb_id, item.seasonNumber, item.episodeNumber).vote_average
elif isinstance(item, Season):
for season in _item.seasons:
if item.seasonNumber == season.season_number:
found_rating = season.average
break
else:
found_rating = _item.vote_average
else: else:
raise Failed(f"No TMDb ID for Guid: {item.guid}") raise Failed(f"No TMDb ID for Guid: {item.guid}")
elif format_var == "imdb_rating": elif format_var == "imdb_rating":
found_rating = self.config.IMDb.get_rating(imdb_id) if isinstance(item, Episode):
found_rating = self.config.IMDb.get_episode_rating(imdb_id, item.seasonNumber, item.episodeNumber)
else:
found_rating = self.config.IMDb.get_rating(imdb_id)
elif format_var == "omdb_rating": elif format_var == "omdb_rating":
if self.config.OMDb.limit is not False: if self.config.OMDb.limit is not False:
raise Failed("Daily OMDb Limit Reached") raise Failed("Daily OMDb Limit Reached")
@ -408,9 +420,9 @@ class Overlays:
else: else:
final_value = int(actual_value / 60000) final_value = int(actual_value / 60000)
elif mod == "%": elif mod == "%":
final_value = int(actual_value * 10) final_value = int(float(actual_value) * 10)
elif mod == "#": elif mod == "#":
actual_value = f"{actual_value:.1f}" actual_value = f"{float(actual_value):.1f}"
final_value = actual_value[:-2] if actual_value.endswith(".0") else actual_value final_value = actual_value[:-2] if actual_value.endswith(".0") else actual_value
elif mod == "/": elif mod == "/":
final_value = f"{float(actual_value) / 2:.1f}" final_value = f"{float(actual_value) / 2:.1f}"
@ -431,7 +443,7 @@ class Overlays:
elif mod == "P": elif mod == "P":
final_value = str(actual_value).title() final_value = str(actual_value).title()
elif format_var in overlay.rating_sources: elif format_var in overlay.rating_sources:
final_value = f"{actual_value:.1f}" final_value = f"{float(actual_value):.1f}"
else: else:
final_value = actual_value final_value = actual_value
if sub_value: if sub_value:

@ -79,11 +79,12 @@ class TMDbCountry:
class TMDbSeason: class TMDbSeason:
def __init__(self, data): def __init__(self, data):
self.season_number = data.split("%:%")[0] if isinstance(data, str) else data.season_number self.season_number = int(data.split("%:%")[0]) if isinstance(data, str) else data.season_number
self.name = data.split("%:%")[1] if isinstance(data, str) else data.name self.name = data.split("%:%")[1] if isinstance(data, str) else data.name
self.average = float(data.split("%:%")[2]) if isinstance(data, str) else data.vote_average
def __repr__(self): def __repr__(self):
return f"{self.season_number}%:%{self.name}" return f"{self.season_number}%:%{self.name}%:%{self.average}"
class TMDBObj: class TMDBObj:

@ -13,4 +13,4 @@ retrying==1.3.4
ruamel.yaml==0.18.6 ruamel.yaml==0.18.6
schedule==1.2.1 schedule==1.2.1
setuptools==69.2.0 setuptools==69.2.0
tmdbapis==1.2.7 tmdbapis==1.2.9
Loading…
Cancel
Save