mirror of
https://github.com/SinTan1729/TvTimeToTrakt.git
synced 2025-04-19 17:40: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
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def _search_trakt(self, tv_time_item: TVTimeItem) -> TraktItem:
|
def _search(self, tv_time_item: TVTimeItem) -> TraktItem:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -63,7 +63,7 @@ class Processor(ABC):
|
||||||
# Other developers share the service, for free - so be considerate of your usage.
|
# Other developers share the service, for free - so be considerate of your usage.
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
|
||||||
trakt_item = self._search_trakt(tv_time_item)
|
trakt_item = self._search(tv_time_item)
|
||||||
if trakt_item is None:
|
if trakt_item is None:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class TVShowProcessor(Processor):
|
||||||
def _should_continue(self, tv_time_show: TVTimeTVShow) -> bool:
|
def _should_continue(self, tv_time_show: TVTimeTVShow) -> bool:
|
||||||
return True
|
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)
|
return TVShowSearcher(tv_time_show).search(tv_time_show.title)
|
||||||
|
|
||||||
def _process(self, tv_time_show: TVTimeTVShow, trakt_show: TraktItem, progress: float) -> None:
|
def _process(self, tv_time_show: TVTimeTVShow, trakt_show: TraktItem, progress: float) -> None:
|
||||||
|
@ -196,7 +196,7 @@ class MovieProcessor(Processor):
|
||||||
|
|
||||||
return True
|
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)
|
return MovieSearcher().search(tv_time_movie.title)
|
||||||
|
|
||||||
def _process(self, tv_time_movie: TVTimeMovie, trakt_movie: TraktMovie, progress: float) -> None:
|
def _process(self, tv_time_movie: TVTimeMovie, trakt_movie: TraktMovie, progress: float) -> None:
|
||||||
|
|
21
searcher.py
21
searcher.py
|
@ -24,13 +24,16 @@ class Title:
|
||||||
without_year: str
|
without_year: str
|
||||||
year: Optional[int]
|
year: Optional[int]
|
||||||
|
|
||||||
def __init__(self, title: str):
|
def __init__(self, title: str, year: Optional[int] = None):
|
||||||
"""
|
"""
|
||||||
Parse the title's name for year.
|
Creates a Title object. If year is not passed, it tries to parse it from the title.
|
||||||
:param title:
|
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
self.name = title
|
self.name = title
|
||||||
|
if year is not None:
|
||||||
|
self.without_year = title
|
||||||
|
self.year = year
|
||||||
|
else:
|
||||||
|
try:
|
||||||
# Use a regex expression to get the value within the brackets e.g. The Americans (2017)
|
# 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)
|
year_search = re.search(r"\(([A-Za-z0-9_]+)\)", title)
|
||||||
self.year = int(year_search.group(1))
|
self.year = int(year_search.group(1))
|
||||||
|
@ -139,6 +142,16 @@ class TVTimeMovie(TVTimeItem):
|
||||||
super().__init__(row["movie_name"], row["updated_at"])
|
super().__init__(row["movie_name"], row["updated_at"])
|
||||||
self.activity_type = row["type"]
|
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):
|
class Searcher(ABC):
|
||||||
def __init__(self, user_matched_table: Table):
|
def __init__(self, user_matched_table: Table):
|
||||||
|
|
Loading…
Reference in a new issue