Skip to content

Commit 1c02c89

Browse files
authored
Merge pull request #162 from Drazzilb08/dev
[v1.2.0]
2 parents 7f07f95 + af7ee04 commit 1c02c89

File tree

7 files changed

+85
-33
lines changed

7 files changed

+85
-33
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.2
1+
1.2.0

config/config.sample.yml

+5
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ border_replacerr:
216216
border_width: 26
217217
# skip - This will skip border replacement until the next schedule/holiday
218218
skip: false
219+
# fix light mm2k posters so no black bar shows at the bottom
220+
exclusion_list:
221+
# - "Fall (2022)"
222+
# - "Inglourious Basterds (2009)"
223+
# - "True Detective (2014) - Season 1"
219224
# Setting a border color of nothing will remove the border, else it will add the border color
220225
# Examples: Must include everything from double quotes to double quotes such as "#FF0000"
221226
# "#FF0000" - Red

modules/border_replacerr.py

+53-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818
import json
19+
from os.path import dirname
1920
import re
2021
import logging
2122
import 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\nAn 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}"))

modules/health_checkarr.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def main(config):
7979
id_list = []
8080
if health:
8181
for health_item in health:
82-
if health_item['source'] == "RemovedMovieCheck" or health_item['source'] == "RemoveSeriesCheck":
83-
if instance_type == "Radarr":
82+
if health_item['source'] == "RemovedMovieCheck" or health_item['source'] == "RemovedSeriesCheck":
83+
if instance_type == "radarr":
8484
for m in re.finditer(tmdb_id_extractor, health_item['message']):
8585
id_list.append(int(m.group(1)))
86-
if instance_type == "Sonarr":
86+
if instance_type == "sonarr":
8787
for m in re.finditer(tvdb_id_extractor, health_item['message']):
8888
id_list.append(int(m.group(1)))
8989
logger.debug(f"id_list:\n{json.dumps(id_list, indent=4)}")
@@ -98,10 +98,10 @@ def main(config):
9898
logger.info(f"Deleting {len(output)} {instance_type} items from {server_name}")
9999
for item in tqdm(output, desc=f"Deleting {instance_type} items", unit="items", disable=None, total=len(output)):
100100
if not dry_run:
101-
logger.info(f"{item['title']} deleted with id: {item['db_id']}")
102-
app.delete_media(item['db_id'], instance_type)
101+
logger.info(f"{item['title']} deleted with id: {item['media_id']} and tvdb/tmdb id: {item['db_id']}")
102+
app.delete_media(item['media_id'])
103103
else:
104-
logger.info(f"{item['title']} would have been deleted with id: {item['db_id']}")
104+
logger.info(f"{item['title']} would have been deleted with id: {item['media_id']}")
105105
except KeyboardInterrupt:
106106
print("Keyboard Interrupt detected. Exiting...")
107107
sys.exit()

modules/sync_gdrive.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@ def set_cmd_args(settings, logger):
5454
sync_id = sync_item['id']
5555

5656
sync_cmd = cmd.copy()
57-
if client_id:
58-
sync_cmd.append('-i')
59-
sync_cmd.append(shlex.quote(client_id))
60-
else:
61-
logger.error("No client id provided")
62-
return
63-
64-
if client_secret:
65-
sync_cmd.append('-s')
66-
sync_cmd.append(shlex.quote(client_secret))
67-
else:
68-
logger.error("No client secret provided")
69-
return
57+
if not gdrive_sa_location:
58+
if client_id:
59+
sync_cmd.append('-i')
60+
sync_cmd.append(shlex.quote(client_id))
61+
else:
62+
logger.error("No client id provided")
63+
return
64+
65+
if client_secret:
66+
sync_cmd.append('-s')
67+
sync_cmd.append(shlex.quote(client_secret))
68+
else:
69+
logger.error("No client secret provided")
70+
return
7071

7172
if gdrive_sync:
7273
if sync_location != '' and os.path.exists(sync_location):

modules/unmatched_assets.py

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ def print_output(unmatched_dict, media_dict, logger):
157157
logger.info(create_table(table))
158158
logger.info("")
159159
for item in data:
160+
if data.index(item) % 10 == 0:
161+
logger.info(f"\t*** {location_base.title()}{suffix} {data.index(item)+1} - {min(data.index(item)+10, len(data))} ***")
162+
logger.info("")
160163
if asset_type == 'series':
161164
missing_seasons = item.get('missing_seasons', False)
162165
if missing_seasons:

util/arrpy.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -659,16 +659,16 @@ def get_health(self):
659659
endpoint = f"{self.url}/api/v3/health"
660660
return self.make_get_request(endpoint, headers=self.headers)
661661

662-
def delete_media(self, media_id, instance_type):
662+
def delete_media(self, media_id):
663663
"""
664664
Delete a media item.
665665
Args:
666666
media_id (int): The ID of the media item to delete.
667667
"""
668668
endpoint = None
669-
if instance_type == 'Sonarr':
669+
if self.instance_type == 'Sonarr':
670670
endpoint = f"{self.url}/api/v3/series/{media_id}"
671-
elif instance_type == 'Radarr':
671+
elif self.instance_type == 'Radarr':
672672
endpoint = f"{self.url}/api/v3/movie/{media_id}"
673673
return self.make_delete_request(endpoint)
674674

0 commit comments

Comments
 (0)