From c5eec4ff2ea9d5c472e424162bec58e41c85bd30 Mon Sep 17 00:00:00 2001 From: Derek Quenneville Date: Fri, 15 Sep 2023 14:13:34 -0400 Subject: [PATCH] Add incremental filename support to poster pull utility --- utility/plex_api_poster_pull.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/utility/plex_api_poster_pull.py b/utility/plex_api_poster_pull.py index 22ced6e2..99c0bed3 100644 --- a/utility/plex_api_poster_pull.py +++ b/utility/plex_api_poster_pull.py @@ -69,9 +69,12 @@ image_path = u'{}/{}.jpg'.format(movie_path, name) elif child.type == 'show': image_path = u'{}/{}.jpg'.format(show_path, name) - # Check if file already exists - if os.path.isfile(image_path): - print("ERROR, %s already exist" % image_path) - else: - # Save to directory - urllib.request.urlretrieve(thumb_url, image_path) + + # If the poster file to be written already exists, append an incrementing number to the filename + increment = 0 + while os.path.isfile(image_path): + increment += 1 + image_path = u'{}/{}_{}.jpg'.format(os.path.dirname(image_path), name, increment) + + # Save to directory + urllib.request.urlretrieve(thumb_url, image_path) \ No newline at end of file