mirror of
https://github.com/SinTan1729/TvTimeToTrakt.git
synced 2025-04-19 09:30:01 -05:00
Read release date where possible
This commit is contained in:
parent
eba70949eb
commit
18aba85eb4
2 changed files with 32 additions and 19 deletions
|
@ -27,7 +27,7 @@ class Processor(ABC):
|
|||
pass
|
||||
|
||||
@abstractmethod
|
||||
def _search_trakt(self, tv_time_item: TVTimeItem) -> TraktItem:
|
||||
def _search(self, tv_time_item: TVTimeItem) -> TraktItem:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
|
@ -63,7 +63,7 @@ class Processor(ABC):
|
|||
# Other developers share the service, for free - so be considerate of your usage.
|
||||
time.sleep(delay)
|
||||
|
||||
trakt_item = self._search_trakt(tv_time_item)
|
||||
trakt_item = self._search(tv_time_item)
|
||||
if trakt_item is None:
|
||||
break
|
||||
|
||||
|
@ -138,7 +138,7 @@ class TVShowProcessor(Processor):
|
|||
def _should_continue(self, tv_time_show: TVTimeTVShow) -> bool:
|
||||
return True
|
||||
|
||||
def _search_trakt(self, tv_time_show: TVTimeTVShow) -> TraktTVShow:
|
||||
def _search(self, tv_time_show: TVTimeTVShow) -> TraktTVShow:
|
||||
return TVShowSearcher(tv_time_show).search(tv_time_show.title)
|
||||
|
||||
def _process(self, tv_time_show: TVTimeTVShow, trakt_show: TraktItem, progress: float) -> None:
|
||||
|
@ -196,7 +196,7 @@ class MovieProcessor(Processor):
|
|||
|
||||
return True
|
||||
|
||||
def _search_trakt(self, tv_time_movie: TVTimeMovie) -> TraktMovie:
|
||||
def _search(self, tv_time_movie: TVTimeMovie) -> TraktMovie:
|
||||
return MovieSearcher().search(tv_time_movie.title)
|
||||
|
||||
def _process(self, tv_time_movie: TVTimeMovie, trakt_movie: TraktMovie, progress: float) -> None:
|
||||
|
|
43
searcher.py
43
searcher.py
|
@ -24,24 +24,27 @@ class Title:
|
|||
without_year: str
|
||||
year: Optional[int]
|
||||
|
||||
def __init__(self, title: str):
|
||||
def __init__(self, title: str, year: Optional[int] = None):
|
||||
"""
|
||||
Parse the title's name for year.
|
||||
:param title:
|
||||
Creates a Title object. If year is not passed, it tries to parse it from the title.
|
||||
"""
|
||||
try:
|
||||
self.name = title
|
||||
# Use a regex expression to get the value within the brackets e.g. The Americans (2017)
|
||||
year_search = re.search(r"\(([A-Za-z0-9_]+)\)", title)
|
||||
self.year = int(year_search.group(1))
|
||||
# Then, get the title without the year value included
|
||||
self.without_year = title.split("(")[0].strip()
|
||||
except Exception:
|
||||
# If the above failed, then the title doesn't include a year
|
||||
# so create the value with "defaults"
|
||||
self.name = title
|
||||
self.name = title
|
||||
if year is not None:
|
||||
self.without_year = title
|
||||
self.year = None
|
||||
self.year = year
|
||||
else:
|
||||
try:
|
||||
# Use a regex expression to get the value within the brackets e.g. The Americans (2017)
|
||||
year_search = re.search(r"\(([A-Za-z0-9_]+)\)", title)
|
||||
self.year = int(year_search.group(1))
|
||||
# Then, get the title without the year value included
|
||||
self.without_year = title.split("(")[0].strip()
|
||||
except Exception:
|
||||
# If the above failed, then the title doesn't include a year
|
||||
# so create the value with "defaults"
|
||||
self.name = title
|
||||
self.without_year = title
|
||||
self.year = None
|
||||
|
||||
def items_with_same_name(self, items: list[TraktItem]) -> list[TraktItem]:
|
||||
with_same_name = []
|
||||
|
@ -139,6 +142,16 @@ class TVTimeMovie(TVTimeItem):
|
|||
super().__init__(row["movie_name"], row["updated_at"])
|
||||
self.activity_type = row["type"]
|
||||
|
||||
# Release date is available for movies
|
||||
|
||||
release_date = datetime.strptime(
|
||||
row["release_date"], "%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
|
||||
# Check that date is valid
|
||||
if release_date.year > 1800:
|
||||
self.title = Title(self.title.name, release_date.year)
|
||||
|
||||
|
||||
class Searcher(ABC):
|
||||
def __init__(self, user_matched_table: Table):
|
||||
|
|
Loading…
Reference in a new issue