mirror of
https://github.com/SinTan1729/TvTimeToTrakt.git
synced 2025-04-19 17:40:01 -05:00
Remove old Title fields
This commit is contained in:
parent
f81be51903
commit
2b8c393c6a
1 changed files with 18 additions and 33 deletions
|
@ -8,6 +8,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import trakt.core
|
import trakt.core
|
||||||
from tinydb import Query, TinyDB
|
from tinydb import Query, TinyDB
|
||||||
|
@ -100,11 +101,9 @@ def init_trakt_auth():
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Title:
|
class Title:
|
||||||
full_title: str
|
full: str
|
||||||
without_year: str
|
without_year: str
|
||||||
year: int
|
year: Optional[int]
|
||||||
titleWithoutYear: str
|
|
||||||
yearValue: int
|
|
||||||
|
|
||||||
def __init__(self, title: str):
|
def __init__(self, title: str):
|
||||||
try:
|
try:
|
||||||
|
@ -114,19 +113,15 @@ class Title:
|
||||||
# Then, get the title without the year value included
|
# Then, get the title without the year value included
|
||||||
title_value = title.split("(")[0].strip()
|
title_value = title.split("(")[0].strip()
|
||||||
# Put this together into an object
|
# Put this together into an object
|
||||||
self.full_title = title
|
self.full = title
|
||||||
self.without_year = title_value
|
self.without_year = title_value
|
||||||
self.titleWithoutYear = title_value
|
|
||||||
self.year = int(year_value)
|
self.year = int(year_value)
|
||||||
self.yearValue = int(year_value)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
# If the above failed, then the title doesn't include a year
|
# If the above failed, then the title doesn't include a year
|
||||||
# so return the object as is.
|
# so return the object as is.
|
||||||
self.full_title = title
|
self.full = title
|
||||||
self.without_year = title
|
self.without_year = title
|
||||||
self.titleWithoutYear = title
|
self.year = None
|
||||||
self.year = -1
|
|
||||||
self.yearValue = -1
|
|
||||||
|
|
||||||
|
|
||||||
def get_year_from_title(title) -> Title:
|
def get_year_from_title(title) -> Title:
|
||||||
|
@ -169,16 +164,11 @@ def check_title_name_match(tv_time_title, trakt_title):
|
||||||
|
|
||||||
def get_show_by_name(name, season_number, episode_number):
|
def get_show_by_name(name, season_number, episode_number):
|
||||||
# Parse the TV Show's name for year, if one is present in the string
|
# Parse the TV Show's name for year, if one is present in the string
|
||||||
title_obj = get_year_from_title(name)
|
title = get_year_from_title(name)
|
||||||
|
|
||||||
# Create a boolean to indicate if the title contains a year,
|
|
||||||
# this is used later on to improve the accuracy of picking
|
|
||||||
# from search results
|
|
||||||
does_title_include_year = title_obj.yearValue != -1
|
|
||||||
|
|
||||||
# If the title contains a year, then replace the local variable with the stripped version
|
# If the title contains a year, then replace the local variable with the stripped version
|
||||||
if does_title_include_year:
|
if title.year:
|
||||||
name = title_obj.titleWithoutYear
|
name = title.without_year
|
||||||
|
|
||||||
# Request the Trakt API for search results, using the name
|
# Request the Trakt API for search results, using the name
|
||||||
tv_search = TVShow.search(name)
|
tv_search = TVShow.search(name)
|
||||||
|
@ -192,15 +182,15 @@ def get_show_by_name(name, season_number, episode_number):
|
||||||
if check_title_name_match(name, show.title):
|
if check_title_name_match(name, show.title):
|
||||||
# If the title included the year of broadcast, then we can be more picky in the results
|
# If the title included the year of broadcast, then we can be more picky in the results
|
||||||
# to look for a show with a broadcast year that matches
|
# to look for a show with a broadcast year that matches
|
||||||
if does_title_include_year:
|
if title.year:
|
||||||
# If the show title is a 1:1 match, with the same broadcast year, then bingo!
|
# If the show title is a 1:1 match, with the same broadcast year, then bingo!
|
||||||
if (name == show.title) and (show.year == title_obj.yearValue):
|
if (name == show.title) and (show.year == title.year):
|
||||||
# Clear previous results, and only use this one
|
# Clear previous results, and only use this one
|
||||||
shows_with_same_name = [show]
|
shows_with_same_name = [show]
|
||||||
break
|
break
|
||||||
|
|
||||||
# Otherwise, only add the show if the broadcast year matches
|
# Otherwise, only add the show if the broadcast year matches
|
||||||
if show.year == title_obj.yearValue:
|
if show.year == title.year:
|
||||||
shows_with_same_name.append(show)
|
shows_with_same_name.append(show)
|
||||||
# If the program doesn't have the broadcast year, then add all the results
|
# If the program doesn't have the broadcast year, then add all the results
|
||||||
else:
|
else:
|
||||||
|
@ -487,16 +477,11 @@ def process_watched_shows():
|
||||||
|
|
||||||
def get_movie_by_name(name):
|
def get_movie_by_name(name):
|
||||||
# Parse the Movie's name for year, if one is present in the string
|
# Parse the Movie's name for year, if one is present in the string
|
||||||
title_obj = get_year_from_title(name)
|
title = get_year_from_title(name)
|
||||||
|
|
||||||
# Create a boolean to indicate if the title contains a year,
|
|
||||||
# this is used later on to improve the accuracy of picking
|
|
||||||
# from search results
|
|
||||||
does_title_include_year = title_obj.yearValue != -1
|
|
||||||
|
|
||||||
# If the title contains a year, then replace the local variable with the stripped version
|
# If the title contains a year, then replace the local variable with the stripped version
|
||||||
if does_title_include_year:
|
if title.year:
|
||||||
name = title_obj.titleWithoutYear
|
name = title.without_year
|
||||||
|
|
||||||
# Request the Trakt API for search results, using the name
|
# Request the Trakt API for search results, using the name
|
||||||
movie_search = Movie.search(name)
|
movie_search = Movie.search(name)
|
||||||
|
@ -510,15 +495,15 @@ def get_movie_by_name(name):
|
||||||
if check_title_name_match(name, movie.title):
|
if check_title_name_match(name, movie.title):
|
||||||
# If the title included the year of broadcast, then we can be more picky in the results
|
# If the title included the year of broadcast, then we can be more picky in the results
|
||||||
# to look for a movie with a broadcast year that matches
|
# to look for a movie with a broadcast year that matches
|
||||||
if does_title_include_year:
|
if title.year:
|
||||||
# If the movie title is a 1:1 match, with the same broadcast year, then bingo!
|
# If the movie title is a 1:1 match, with the same broadcast year, then bingo!
|
||||||
if (name == movie.title) and (movie.year == title_obj.yearValue):
|
if (name == movie.title) and (movie.year == title.year):
|
||||||
# Clear previous results, and only use this one
|
# Clear previous results, and only use this one
|
||||||
movies_with_same_name = [movie]
|
movies_with_same_name = [movie]
|
||||||
break
|
break
|
||||||
|
|
||||||
# Otherwise, only add the movie if the broadcast year matches
|
# Otherwise, only add the movie if the broadcast year matches
|
||||||
if movie.year == title_obj.yearValue:
|
if movie.year == title.year:
|
||||||
movies_with_same_name.append(movie)
|
movies_with_same_name.append(movie)
|
||||||
# If the program doesn't have the broadcast year, then add all the results
|
# If the program doesn't have the broadcast year, then add all the results
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue