diff --git a/media_manager/movies/service.py b/media_manager/movies/service.py index 989b05d..89450be 100644 --- a/media_manager/movies/service.py +++ b/media_manager/movies/service.py @@ -588,7 +588,7 @@ class MovieService: """ video_files, subtitle_files, all_files = get_files_for_import(torrent=torrent) - success: bool = False # determines if the import was successful, if true, the Imported flag will be set to True after the import + success: list[bool] = [] if len(video_files) != 1: # Send notification about multiple video files found @@ -612,23 +612,34 @@ class MovieService: ) for movie_file in movie_files: - self.import_movie( - movie=movie, - video_files=video_files, - subtitle_files=subtitle_files, - file_path_suffix=movie_file.file_path_suffix, + success.append( + self.import_movie( + movie=movie, + video_files=video_files, + subtitle_files=subtitle_files, + file_path_suffix=movie_file.file_path_suffix, + ) ) - if success: + if all(success): torrent.imported = True self.torrent_service.torrent_repository.save_torrent(torrent=torrent) - # Send successful import notification if self.notification_service: self.notification_service.send_notification_to_all_providers( title="Movie Downloaded", message=f"Successfully downloaded: {movie.name} ({movie.year}) from torrent {torrent.title}.", ) + else: + log.error( + f"Importing files for torrent {torrent.title} encountered errors." + ) + + if self.notification_service: + self.notification_service.send_notification_to_all_providers( + title="Movie import failed", + message=f"There were errors importing: {movie.name} ({movie.year}) from torrent {torrent.title}. Please check the logs for details.", + ) log.info(f"Finished importing files for torrent {torrent.title}") diff --git a/media_manager/tv/service.py b/media_manager/tv/service.py index bff18f4..b6884e0 100644 --- a/media_manager/tv/service.py +++ b/media_manager/tv/service.py @@ -699,7 +699,7 @@ class TvService: video_files, subtitle_files, all_files = get_files_for_import(torrent=torrent) - success: bool = True # determines if the import was successful, if true, the Imported flag will be set to True after the import + success: list[bool] = [] log.debug( f"Importing these {len(video_files)} files:\n" + pprint.pformat(video_files) @@ -719,6 +719,7 @@ class TvService: subtitle_files=subtitle_files, file_path_suffix=season_file.file_path_suffix, ) + success.append(season_import_success) if season_import_success: log.info( f"Season {season.number} successfully imported from torrent {torrent.title}" @@ -727,22 +728,27 @@ class TvService: log.warning( f"Season {season.number} failed to import from torrent {torrent.title}" ) - success = False log.info( - f"Finished importing files for torrent {torrent.title} {'without' if success else 'with'} errors" + f"Finished importing files for torrent {torrent.title} {'without' if all(success) else 'with'} errors" ) - if success: + if all(success): torrent.imported = True self.torrent_service.torrent_repository.save_torrent(torrent=torrent) # Send successful season download notification if self.notification_service: self.notification_service.send_notification_to_all_providers( - title="TV Season Downloaded", + title="TV Show imported successfully", message=f"Successfully imported {show.name} ({show.year}) from torrent {torrent.title}.", ) + else: + if self.notification_service: + self.notification_service.send_notification_to_all_providers( + title="Failed to import TV Show", + message=f"Importing {show.name} ({show.year}) from torrent {torrent.title} completed with errors. Please check the logs for details.", + ) def update_show_metadata( self, db_show: Show, metadata_provider: AbstractMetadataProvider