1616
1717import os
1818import json
19+ from os .path import dirname
1920import re
2021import logging
2122import filecmp
@@ -127,6 +128,7 @@ def fix_borders(assets_dict, script_config, border_colors, destination_dir, dry_
127128
128129 # Extracting necessary parameters from the script config
129130 border_width = script_config ['border_width' ]
131+ exclusion_list = script_config ['exclusion_list' ]
130132 rgb_border_colors = []
131133
132134 # Convert border colors to RGB format if available
@@ -198,7 +200,7 @@ def fix_borders(assets_dict, script_config, border_colors, destination_dir, dry_
198200 if rgb_border_color :
199201 results = replace_border (input_file , output_path , rgb_border_color , border_width , logger )
200202 else :
201- results = remove_border (input_file , output_path , border_width , logger )
203+ results = remove_border (input_file , output_path , border_width , exclusion_list , logger )
202204 if results :
203205 if path :
204206 messages .append (f"{ action } { data ['title' ]} { year } - { file_name } " )
@@ -277,34 +279,75 @@ def replace_border(input_file, output_path, border_colors, border_width, logger)
277279 logger .error (f"Error processing { input_file } " )
278280 return False
279281
280- def remove_border (input_file , output_path , border_width , logger ):
282+ def remove_border (input_file , output_path , border_width , exclusion_list , logger ):
281283 """
282284 Crops the center of an image, reducing its dimensions by 50 pixels on each side.
283285
284286 Args:
285287 input_file (str): The input file.
286288 output_path (str): The output path.
287289 border_width (int): The border width.
290+ exclusion_list (list): Light posters to exclude from having a black border on the bottom
288291 Returns:
289292 bool: True if the file was saved, False otherwise.
290293 """
291294
295+ def format_season (string ):
296+ return re .sub (r'Season0*(\d+)' , r'Season \1' , string )
297+
298+ if exclusion_list is None :
299+ exclusion_list = []
300+
292301 # Open the image
293302 try :
294303 with Image .open (input_file ) as image : # Open the image
295304 # Set the border width
296305 width , height = image .size # Get the width and height of the image
297-
298306 # Remove top, left, and right borders, and replace bottom border with black
299- final_image = image .crop ((border_width , border_width , width - border_width , height )) # Crop the image to remove the borders
300- bottom_border = Image .new ("RGB" , (width - 2 * border_width , border_width ), color = 'black' ) # Create a black image for the bottom border
301- bottom_border_position = (0 , height - border_width - border_width ) # Position the bottom border 25 pixels from the bottom
302- final_image .paste (bottom_border , bottom_border_position ) # Paste the black bottom border at the specified position
307+ file_name = os .path .basename (input_file )
308+ name_without_extension , extension = os .path .splitext (file_name )
309+ # Format for no asset folders
310+ parts = name_without_extension .split ('_' )
311+ # Check if list is greater > 2 indicating season file, if not return None
312+ if len (parts )>= 2 :
313+ name_without_season , season = parts
314+ else :
315+ name_without_season = parts [0 ]
316+ season = None
317+ if season is not None :
318+ formatted_season = format_season (season )
319+ # Create variable to match exclusion_list format
320+ formatted_name_without_season = f"{ name_without_season } - { formatted_season } "
321+ else :
322+ formatted_name_without_season = None
323+
324+ # Format for asset folders
325+ directory_path = os .path .dirname (input_file )
326+ parent_dir_name = os .path .basename (directory_path )
327+ formatted_name_without_extension = format_season (name_without_extension )
328+ # Create variable to match exclusion_list format
329+ folder_season_file_name = f"{ parent_dir_name } - { formatted_name_without_extension } "
330+
331+ # Check asset folders for exclusion list match
332+ if folder_season_file_name in exclusion_list and "Season" in name_without_extension : # season file name
333+ final_image = image .crop ((border_width , border_width , width - border_width , height - border_width ))
334+ elif parent_dir_name in exclusion_list and "Season" not in name_without_extension : # poster/series file name
335+ final_image = image .crop ((border_width , border_width , width - border_width , height - border_width ))
336+
337+ # Check formatted file name against exclusion list if asset folders is false
338+ elif name_without_extension in exclusion_list : # poster/series file name
339+ final_image = image .crop ((border_width , border_width , width - border_width , height - border_width ))
340+ elif formatted_name_without_season in exclusion_list : # season file name
341+ final_image = image .crop ((border_width , border_width , width - border_width , height - border_width ))
342+ # Not an exclusion
343+ else :
344+ final_image = image .crop ((border_width , border_width , width - border_width , height )) # Crop the image to remove the borders
345+ bottom_border = Image .new ("RGB" , (width - 2 * border_width , border_width ), color = 'black' ) # Create a black image for the bottom border
346+ bottom_border_position = (0 , height - border_width - border_width ) # Position the bottom border 25 pixels from the bottom
347+ final_image .paste (bottom_border , bottom_border_position ) # Paste the black bottom border at the specified position
303348
304349 # Resize the image to 1500x1000
305350 final_image = final_image .resize ((1000 , 1500 )).convert ("RGB" )
306-
307- file_name = os .path .basename (input_file )
308351 final_path = f"{ output_path } /{ file_name } " # Set the output path to the parent directory
309352
310353 if os .path .isfile (final_path ):
@@ -546,4 +589,4 @@ def main(config):
546589 logger .error (f"\n \n An error occurred:\n " , exc_info = True )
547590 logger .error (f"\n \n " )
548591 finally :
549- logger .info (create_bar (f"END { name } " ))
592+ logger .info (create_bar (f"END { name } " ))
0 commit comments