@ -131,7 +131,7 @@ class TMDbAPI:
self . image_url = " https://image.tmdb.org/t/p/original "
self . image_url = " https://image.tmdb.org/t/p/original "
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
def convert _from_tmdb( self , tmdb_id , convert_to , is_movie ) :
def _from_tmdb( self , tmdb_id , convert_to , is_movie ) :
try :
try :
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 ) :
@ -141,16 +141,16 @@ class TMDbAPI:
raise Failed ( f " TMDb Error: { ' Movie ' if is_movie else ' Show ' } TMDb ID: { tmdb_id } not found " )
raise Failed ( f " TMDb Error: { ' Movie ' if is_movie else ' Show ' } TMDb ID: { tmdb_id } not found " )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
def convert _to_tmdb( self , external_id , external_source , is_movie ) :
def _to_tmdb( self , external_id , external_source , is_movie ) :
search_results = self . Movie . external ( external_id = external_id , external_source = external_source )
search_results = self . Movie . external ( external_id = external_id , external_source = external_source )
search = search_results [ " movie_results " if is_movie else " tv_results " ]
search = search_results [ " movie_results " if is_movie else " tv_results " ]
if len ( search ) == 1 : return int ( search [ 0 ] [ " id " ] )
if len ( search ) == 1 : return int ( search [ 0 ] [ " id " ] )
else : raise Failed ( f " TMDb Error: No TMDb ID found for { external_source . upper ( ) . replace ( ' B_ ' , ' b ' ) } { external_id } " )
else : raise Failed ( f " TMDb Error: No TMDb ID found for { external_source . upper ( ) . replace ( ' B_ ' , ' b ' ) } { external_id } " )
def convert_tmdb_to_imdb ( self , tmdb_id , is_movie = True ) : return self . convert _from_tmdb( tmdb_id , " imdb_id " , is_movie )
def convert_tmdb_to_imdb ( self , tmdb_id , is_movie = True ) : return self . _from_tmdb( tmdb_id , " imdb_id " , is_movie )
def convert_imdb_to_tmdb ( self , imdb_id , is_movie = True ) : return self . convert _to_tmdb( imdb_id , " imdb_id " , is_movie )
def convert_imdb_to_tmdb ( self , imdb_id , is_movie = True ) : return self . _to_tmdb( imdb_id , " imdb_id " , is_movie )
def convert_tmdb_to_tvdb ( self , tmdb_id ) : return self . convert _from_tmdb( tmdb_id , " tvdb_id " , False )
def convert_tmdb_to_tvdb ( self , tmdb_id ) : return self . _from_tmdb( tmdb_id , " tvdb_id " , False )
def convert_tvdb_to_tmdb ( self , tvdb_id ) : return self . convert _to_tmdb( tvdb_id , " tvdb_id " , False )
def convert_tvdb_to_tmdb ( self , tvdb_id ) : return self . _to_tmdb( tvdb_id , " tvdb_id " , False )
def convert_tvdb_to_imdb ( self , tvdb_id ) : return self . convert_tmdb_to_imdb ( self . convert_tvdb_to_tmdb ( tvdb_id ) , False )
def convert_tvdb_to_imdb ( self , tvdb_id ) : return self . convert_tmdb_to_imdb ( self . convert_tvdb_to_tmdb ( tvdb_id ) , False )
def convert_imdb_to_tvdb ( self , imdb_id ) : return self . convert_tmdb_to_tvdb ( self . convert_imdb_to_tmdb ( imdb_id , False ) )
def convert_imdb_to_tvdb ( self , imdb_id ) : return self . convert_tmdb_to_tvdb ( self . convert_imdb_to_tmdb ( imdb_id , False ) )
@ -183,22 +183,22 @@ class TMDbAPI:
except TMDbException as e : raise Failed ( f " TMDb Error: No Person found for TMDb ID { tmdb_id } : { e } " )
except TMDbException as e : raise Failed ( f " TMDb Error: No Person found for TMDb ID { tmdb_id } : { e } " )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
def get _person_credits( self , tmdb_id ) :
def _person_credits( self , tmdb_id ) :
try : return self . Person . combined_credits ( tmdb_id )
try : return self . Person . combined_credits ( tmdb_id )
except TMDbException as e : raise Failed ( f " TMDb Error: No Person found for TMDb ID { tmdb_id } : { e } " )
except TMDbException as e : raise Failed ( f " TMDb Error: No Person found for TMDb ID { tmdb_id } : { e } " )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
def get _company( self , tmdb_id ) :
def _company( self , tmdb_id ) :
try : return self . Company . details ( tmdb_id )
try : return self . Company . details ( tmdb_id )
except TMDbException as e : raise Failed ( f " TMDb Error: No Company found for TMDb ID { tmdb_id } : { e } " )
except TMDbException as e : raise Failed ( f " TMDb Error: No Company found for TMDb ID { tmdb_id } : { e } " )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
def get _network( self , tmdb_id ) :
def _network( self , tmdb_id ) :
try : return self . Network . details ( tmdb_id )
try : return self . Network . details ( tmdb_id )
except TMDbException as e : raise Failed ( f " TMDb Error: No Network found for TMDb ID { tmdb_id } : { e } " )
except TMDbException as e : raise Failed ( f " TMDb Error: No Network found for TMDb ID { tmdb_id } : { e } " )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
@retry ( stop_max_attempt_number = 6 , wait_fixed = 10000 , retry_on_exception = util . retry_if_not_failed )
def get _keyword( self , tmdb_id ) :
def _keyword( self , tmdb_id ) :
try : return self . Keyword . details ( tmdb_id )
try : return self . Keyword . details ( tmdb_id )
except TMDbException as e : raise Failed ( f " TMDb Error: No Keyword found for TMDb ID { tmdb_id } : { e } " )
except TMDbException as e : raise Failed ( f " TMDb Error: No Keyword found for TMDb ID { tmdb_id } : { e } " )
@ -207,10 +207,10 @@ class TMDbAPI:
try : return self . List . details ( tmdb_id , all_details = True )
try : return self . List . details ( tmdb_id , all_details = True )
except TMDbException as e : raise Failed ( f " TMDb Error: No List found for TMDb ID { tmdb_id } : { e } " )
except TMDbException as e : raise Failed ( f " TMDb Error: No List found for TMDb ID { tmdb_id } : { e } " )
def get _credits( self , tmdb_id , actor = False , crew = False , director = False , producer = False , writer = False ) :
def _credits( self , tmdb_id , actor = False , crew = False , director = False , producer = False , writer = False ) :
movie_ids = [ ]
movie_ids = [ ]
show_ids = [ ]
show_ids = [ ]
actor_credits = self . get _person_credits( tmdb_id )
actor_credits = self . _person_credits( tmdb_id )
if actor :
if actor :
for credit in actor_credits . cast :
for credit in actor_credits . cast :
if credit . media_type == " movie " :
if credit . media_type == " movie " :
@ -234,7 +234,7 @@ class TMDbAPI:
logger . warning ( e )
logger . warning ( e )
return movie_ids , show_ids
return movie_ids , show_ids
def get _pagenation( self , method , amount , is_movie ) :
def _pagenation( self , method , amount , is_movie ) :
ids = [ ]
ids = [ ]
count = 0
count = 0
for x in range ( int ( amount / 20 ) + 1 ) :
for x in range ( int ( amount / 20 ) + 1 ) :
@ -254,7 +254,7 @@ class TMDbAPI:
if count == amount : break
if count == amount : break
return ids
return ids
def get _discover( self , attrs , amount , is_movie ) :
def _discover( self , attrs , amount , is_movie ) :
ids = [ ]
ids = [ ]
count = 0
count = 0
for date_attr in discover_dates :
for date_attr in discover_dates :
@ -278,6 +278,24 @@ class TMDbAPI:
if count == amount : break
if count == amount : break
return ids , amount
return ids , amount
def validate_tmdb_list ( self , tmdb_list , tmdb_type ) :
tmdb_values = [ ]
for tmdb_id in tmdb_list :
try : tmdb_values . append ( self . validate_tmdb ( tmdb_id , tmdb_type ) )
except Failed as e : logger . error ( e )
if len ( tmdb_values ) == 0 : raise Failed ( f " TMDb Error: No valid TMDb IDs in { tmdb_list } " )
return tmdb_values
def validate_tmdb ( self , tmdb_id , tmdb_type ) :
if tmdb_type == " Movie " : self . get_movie ( tmdb_id )
elif tmdb_type == " Show " : self . get_show ( tmdb_id )
elif tmdb_type == " Collection " : self . get_collection ( tmdb_id )
elif tmdb_type == " Person " : self . get_person ( tmdb_id )
elif tmdb_type == " Company " : self . _company ( tmdb_id )
elif tmdb_type == " Network " : self . _network ( tmdb_id )
elif tmdb_type == " List " : self . get_list ( tmdb_id )
return tmdb_id
def get_items ( self , method , data , is_movie , status_message = True ) :
def get_items ( self , method , data , is_movie , status_message = True ) :
if status_message :
if status_message :
logger . debug ( f " Data: { data } " )
logger . debug ( f " Data: { data } " )
@ -292,20 +310,20 @@ class TMDbAPI:
if method in [ " tmdb_company " , " tmdb_network " , " tmdb_keyword " ] :
if method in [ " tmdb_company " , " tmdb_network " , " tmdb_keyword " ] :
tmdb_id = int ( data )
tmdb_id = int ( data )
if method == " tmdb_company " :
if method == " tmdb_company " :
tmdb_name = str ( self . get _company( tmdb_id ) . name )
tmdb_name = str ( self . _company( tmdb_id ) . name )
attrs = { " with_companies " : tmdb_id }
attrs = { " with_companies " : tmdb_id }
elif method == " tmdb_network " :
elif method == " tmdb_network " :
tmdb_name = str ( self . get _network( tmdb_id ) . name )
tmdb_name = str ( self . _network( tmdb_id ) . name )
attrs = { " with_networks " : tmdb_id }
attrs = { " with_networks " : tmdb_id }
elif method == " tmdb_keyword " :
elif method == " tmdb_keyword " :
tmdb_name = str ( self . get _keyword( tmdb_id ) . name )
tmdb_name = str ( self . _keyword( tmdb_id ) . name )
attrs = { " with_keywords " : tmdb_id }
attrs = { " with_keywords " : tmdb_id }
limit = 0
limit = 0
else :
else :
attrs = data . copy ( )
attrs = data . copy ( )
limit = int ( attrs . pop ( " limit " ) )
limit = int ( attrs . pop ( " limit " ) )
if is_movie : movie_ids , amount = self . get _discover( attrs , limit , is_movie )
if is_movie : movie_ids , amount = self . _discover( attrs , limit , is_movie )
else : show_ids , amount = self . get _discover( attrs , limit , is_movie )
else : show_ids , amount = self . _discover( attrs , limit , is_movie )
if status_message :
if status_message :
if method in [ " tmdb_company " , " tmdb_network " , " tmdb_keyword " ] :
if method in [ " tmdb_company " , " tmdb_network " , " tmdb_keyword " ] :
logger . info ( f " Processing { pretty } : ( { tmdb_id } ) { tmdb_name } ( { amount } { media_type } { ' ' if amount == 1 else ' s ' } ) " )
logger . info ( f " Processing { pretty } : ( { tmdb_id } ) { tmdb_name } ( { amount } { media_type } { ' ' if amount == 1 else ' s ' } ) " )
@ -314,8 +332,8 @@ class TMDbAPI:
for attr , value in attrs . items ( ) :
for attr , value in attrs . items ( ) :
logger . info ( f " { attr } : { value } " )
logger . info ( f " { attr } : { value } " )
elif method in [ " tmdb_popular " , " tmdb_top_rated " , " tmdb_now_playing " , " tmdb_trending_daily " , " tmdb_trending_weekly " ] :
elif method in [ " tmdb_popular " , " tmdb_top_rated " , " tmdb_now_playing " , " tmdb_trending_daily " , " tmdb_trending_weekly " ] :
if is_movie : movie_ids = self . get _pagenation( method , data , is_movie )
if is_movie : movie_ids = self . _pagenation( method , data , is_movie )
else : show_ids = self . get _pagenation( method , data , is_movie )
else : show_ids = self . _pagenation( method , data , is_movie )
if status_message :
if status_message :
logger . info ( f " Processing { pretty } : { data } { media_type } { ' ' if data == 1 else ' s ' } " )
logger . info ( f " Processing { pretty } : { data } { media_type } { ' ' if data == 1 else ' s ' } " )
else :
else :
@ -342,11 +360,11 @@ class TMDbAPI:
show_ids . append ( self . convert_tmdb_to_tvdb ( tmdb_id ) )
show_ids . append ( self . convert_tmdb_to_tvdb ( tmdb_id ) )
else :
else :
tmdb_name = str ( self . get_person ( tmdb_id ) . name )
tmdb_name = str ( self . get_person ( tmdb_id ) . name )
if method == " tmdb_actor " : movie_ids , show_ids = self . get _credits( tmdb_id , actor = True )
if method == " tmdb_actor " : movie_ids , show_ids = self . _credits( tmdb_id , actor = True )
elif method == " tmdb_director " : movie_ids , show_ids = self . get _credits( tmdb_id , director = True )
elif method == " tmdb_director " : movie_ids , show_ids = self . _credits( tmdb_id , director = True )
elif method == " tmdb_producer " : movie_ids , show_ids = self . get _credits( tmdb_id , producer = True )
elif method == " tmdb_producer " : movie_ids , show_ids = self . _credits( tmdb_id , producer = True )
elif method == " tmdb_writer " : movie_ids , show_ids = self . get _credits( tmdb_id , writer = True )
elif method == " tmdb_writer " : movie_ids , show_ids = self . _credits( tmdb_id , writer = True )
elif method == " tmdb_crew " : movie_ids , show_ids = self . get _credits( tmdb_id , crew = True )
elif method == " tmdb_crew " : movie_ids , show_ids = self . _credits( tmdb_id , crew = True )
else : raise Failed ( f " TMDb Error: Method { method } not supported " )
else : raise Failed ( f " TMDb Error: Method { method } not supported " )
if status_message and len ( movie_ids ) > 0 :
if status_message and len ( movie_ids ) > 0 :
logger . info ( f " Processing { pretty } : ( { tmdb_id } ) { tmdb_name } ( { len ( movie_ids ) } Movie { ' ' if len ( movie_ids ) == 1 else ' s ' } ) " )
logger . info ( f " Processing { pretty } : ( { tmdb_id } ) { tmdb_name } ( { len ( movie_ids ) } Movie { ' ' if len ( movie_ids ) == 1 else ' s ' } ) " )
@ -356,21 +374,3 @@ class TMDbAPI:
logger . debug ( f " TMDb IDs Found: { movie_ids } " )
logger . debug ( f " TMDb IDs Found: { movie_ids } " )
logger . debug ( f " TVDb IDs Found: { show_ids } " )
logger . debug ( f " TVDb IDs Found: { show_ids } " )
return movie_ids , show_ids
return movie_ids , show_ids
def validate_tmdb_list ( self , tmdb_list , tmdb_type ) :
tmdb_values = [ ]
for tmdb_id in tmdb_list :
try : tmdb_values . append ( self . validate_tmdb ( tmdb_id , tmdb_type ) )
except Failed as e : logger . error ( e )
if len ( tmdb_values ) == 0 : raise Failed ( f " TMDb Error: No valid TMDb IDs in { tmdb_list } " )
return tmdb_values
def validate_tmdb ( self , tmdb_id , tmdb_type ) :
if tmdb_type == " Movie " : self . get_movie ( tmdb_id )
elif tmdb_type == " Show " : self . get_show ( tmdb_id )
elif tmdb_type == " Collection " : self . get_collection ( tmdb_id )
elif tmdb_type == " Person " : self . get_person ( tmdb_id )
elif tmdb_type == " Company " : self . get_company ( tmdb_id )
elif tmdb_type == " Network " : self . get_network ( tmdb_id )
elif tmdb_type == " List " : self . get_list ( tmdb_id )
return tmdb_id