more cleanup

pull/351/head
meisnate12 3 years ago
parent ad89db3ca4
commit a9f9cca61e

@ -119,17 +119,16 @@ class Convert:
imdb_id = None imdb_id = None
try: try:
imdb_id = self.config.TMDb.convert_from(tmdb_id, "imdb_id", is_movie) imdb_id = self.config.TMDb.convert_from(tmdb_id, "imdb_id", is_movie)
except Failed:
if self.config.Trakt:
try:
imdb_id = self.config.Trakt.convert(tmdb_id, "tmdb", "imdb", "movie" if is_movie else "show")
except Failed: except Failed:
pass pass
if fail and imdb_id is None: if imdb_id:
raise Failed(f"Convert Error: No IMDb ID Found for TMDb ID: {tmdb_id}") if self.config.Cache:
if self.config.Cache and imdb_id:
self.config.Cache.update_imdb_to_tmdb_map(media_type, expired, imdb_id, tmdb_id) self.config.Cache.update_imdb_to_tmdb_map(media_type, expired, imdb_id, tmdb_id)
return imdb_id return imdb_id
elif fail:
raise Failed(f"Convert Error: No IMDb ID Found for TMDb ID: {tmdb_id}")
else:
return None
def imdb_to_tmdb(self, imdb_id, is_movie=True, fail=False): def imdb_to_tmdb(self, imdb_id, is_movie=True, fail=False):
media_type = "movie" if is_movie else "show" media_type = "movie" if is_movie else "show"
@ -141,17 +140,16 @@ class Convert:
tmdb_id = None tmdb_id = None
try: try:
tmdb_id = self.config.TMDb.convert_to(imdb_id, "imdb_id", is_movie) tmdb_id = self.config.TMDb.convert_to(imdb_id, "imdb_id", is_movie)
except Failed:
if self.config.Trakt:
try:
tmdb_id = self.config.Trakt.convert(imdb_id, "imdb", "tmdb", media_type)
except Failed: except Failed:
pass pass
if fail and tmdb_id is None: if tmdb_id:
raise Failed(f"Convert Error: No TMDb ID Found for IMDb ID: {imdb_id}") if self.config.Cache:
if self.config.Cache and tmdb_id:
self.config.Cache.update_imdb_to_tmdb_map(media_type, expired, imdb_id, tmdb_id) self.config.Cache.update_imdb_to_tmdb_map(media_type, expired, imdb_id, tmdb_id)
return tmdb_id return tmdb_id
elif fail:
raise Failed(f"Convert Error: No TMDb ID Found for IMDb ID: {imdb_id}")
else:
return None
def tmdb_to_tvdb(self, tmdb_id, fail=False): def tmdb_to_tvdb(self, tmdb_id, fail=False):
expired = False expired = False
@ -161,18 +159,17 @@ class Convert:
return cache_id return cache_id
tvdb_id = None tvdb_id = None
try: try:
tvdb_id = int(self.config.TMDb.convert_from(tmdb_id, "tvdb_id", False)) tvdb_id = self.config.TMDb.convert_from(tmdb_id, "tvdb_id", False)
except Failed:
if self.config.Trakt:
try:
tvdb_id = int(self.config.Trakt.convert(tmdb_id, "tmdb", "tvdb", "show"))
except Failed: except Failed:
pass pass
if fail and tvdb_id is None: if tvdb_id:
raise Failed(f"Convert Error: No TVDb ID Found for TMDb ID: {tmdb_id}") if self.config.Cache:
if self.config.Cache and tvdb_id:
self.config.Cache.update_tmdb_to_tvdb_map(expired, tmdb_id, tvdb_id) self.config.Cache.update_tmdb_to_tvdb_map(expired, tmdb_id, tvdb_id)
return tvdb_id return tvdb_id
elif fail:
raise Failed(f"Convert Error: No TVDb ID Found for TMDb ID: {tmdb_id}")
else:
return None
def tvdb_to_tmdb(self, tvdb_id, fail=False): def tvdb_to_tmdb(self, tvdb_id, fail=False):
expired = False expired = False
@ -183,17 +180,16 @@ class Convert:
tmdb_id = None tmdb_id = None
try: try:
tmdb_id = self.config.TMDb.convert_to(tvdb_id, "tvdb_id", False) tmdb_id = self.config.TMDb.convert_to(tvdb_id, "tvdb_id", False)
except Failed:
if self.config.Trakt:
try:
tmdb_id = self.config.Trakt.convert(tvdb_id, "tvdb", "tmdb", "show")
except Failed: except Failed:
pass pass
if fail and tmdb_id is None: if tmdb_id:
raise Failed(f"Convert Error: No TMDb ID Found for TVDb ID: {tvdb_id}") if self.config.Cache:
if self.config.Cache and tmdb_id:
self.config.Cache.update_tmdb_to_tvdb_map(expired, tmdb_id, tvdb_id) self.config.Cache.update_tmdb_to_tvdb_map(expired, tmdb_id, tvdb_id)
return tmdb_id return tmdb_id
elif fail:
raise Failed(f"Convert Error: No TMDb ID Found for TVDb ID: {tvdb_id}")
else:
return None
def tvdb_to_imdb(self, tvdb_id, fail=False): def tvdb_to_imdb(self, tvdb_id, fail=False):
expired = False expired = False
@ -204,17 +200,16 @@ class Convert:
imdb_id = None imdb_id = None
try: try:
imdb_id = self.tmdb_to_imdb(self.tvdb_to_tmdb(tvdb_id, fail=True), is_movie=False, fail=True) imdb_id = self.tmdb_to_imdb(self.tvdb_to_tmdb(tvdb_id, fail=True), is_movie=False, fail=True)
except Failed:
if self.config.Trakt:
try:
imdb_id = self.config.Trakt.convert(tvdb_id, "tvdb", "imdb", "show")
except Failed: except Failed:
pass pass
if fail and imdb_id is None: if imdb_id:
raise Failed(f"Convert Error: No IMDb ID Found for TVDb ID: {tvdb_id}") if self.config.Cache:
if self.config.Cache and imdb_id:
self.config.Cache.update_imdb_to_tvdb_map(expired, imdb_id, tvdb_id) self.config.Cache.update_imdb_to_tvdb_map(expired, imdb_id, tvdb_id)
return imdb_id return imdb_id
elif fail:
raise Failed(f"Convert Error: No IMDb ID Found for TVDb ID: {tvdb_id}")
else:
return None
def imdb_to_tvdb(self, imdb_id, fail=False): def imdb_to_tvdb(self, imdb_id, fail=False):
expired = False expired = False
@ -225,17 +220,16 @@ class Convert:
tvdb_id = None tvdb_id = None
try: try:
tvdb_id = self.tmdb_to_tvdb(self.imdb_to_tmdb(imdb_id, is_movie=False, fail=True), fail=True) tvdb_id = self.tmdb_to_tvdb(self.imdb_to_tmdb(imdb_id, is_movie=False, fail=True), fail=True)
except Failed:
if self.config.Trakt:
try:
tvdb_id = self.config.Trakt.convert(imdb_id, "imdb", "tvdb", "show")
except Failed: except Failed:
pass pass
if fail and tvdb_id is None: if tvdb_id:
raise Failed(f"Convert Error: No TVDb ID Found for IMDb ID: {imdb_id}") if self.config.Cache:
if self.config.Cache and tvdb_id:
self.config.Cache.update_imdb_to_tvdb_map(expired, imdb_id, tvdb_id) self.config.Cache.update_imdb_to_tvdb_map(expired, imdb_id, tvdb_id)
return tvdb_id return tvdb_id
elif fail:
raise Failed(f"Convert Error: No TVDb ID Found for IMDb ID: {imdb_id}")
else:
return None
def get_id(self, item, library): def get_id(self, item, library):
expired = None expired = None

@ -75,7 +75,7 @@ class TMDb:
id_to_return = self.Movie.external_ids(tmdb_id)[convert_to] if is_movie else self.TV.external_ids(tmdb_id)[convert_to] id_to_return = self.Movie.external_ids(tmdb_id)[convert_to] if is_movie else self.TV.external_ids(tmdb_id)[convert_to]
if not id_to_return or (convert_to == "tvdb_id" and id_to_return == 0): if not id_to_return or (convert_to == "tvdb_id" and id_to_return == 0):
raise Failed(f"TMDb Error: No {convert_to.upper().replace('B_', 'b ')} found for TMDb ID {tmdb_id}") raise Failed(f"TMDb Error: No {convert_to.upper().replace('B_', 'b ')} found for TMDb ID {tmdb_id}")
return id_to_return return id_to_return if convert_to == "imdb_id" else int(id_to_return)
except TMDbException: except TMDbException:
raise Failed(f"TMDb Error: TMDb {'Movie' if is_movie else 'Show'} ID: {tmdb_id} not found") raise Failed(f"TMDb Error: TMDb {'Movie' if is_movie else 'Show'} ID: {tmdb_id} not found")

@ -1,11 +1,11 @@
PlexAPI==4.7.0 PlexAPI==4.7.0
tmdbv3api==1.7.6 tmdbv3api==1.7.6
arrapi==1.1.2 arrapi==1.1.2
lxml lxml==4.6.3
requests>=2.4.2 requests==2.26.0
ruamel.yaml ruamel.yaml==0.17.10
schedule schedule==1.1.0
retrying retrying==1.3.3
pathvalidate pathvalidate==2.4.1
pillow pillow==8.3.1
python-slugify python-slugify==5.0.2
Loading…
Cancel
Save