Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
[UPDATE] Renamer 5.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
MrZablah committed Nov 13, 2023
1 parent 7c2c16b commit 971590f
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions modules/renamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Name: renamer.py
# Description: This script will check for unmatched assets in your Plex library.
# It will output the results to a file in the logs folder.
# This is a modified version of the original script by Drazzilb, Version: 5.3.4
# This is a modified version of the original script by Drazzilb:
# Version: 5.3.6
# you can find the original script here: https://github.com/Drazzilb08/userScripts/blob/master/python-scripts/renamer.py
# ===================================================================================================

Expand Down Expand Up @@ -179,7 +180,7 @@ def match_media(media, source_file_list, type):
if item['status'] == 'upcoming' or item['status'] == 'announced':
continue
else:
logger.warning(f"Unable to find year in path: {item['path']}")
logger.warning(f"Unable to find year in {item['title']} path")
try:
if item['alternateTitles']:
for i in item['alternateTitles']:
Expand Down Expand Up @@ -491,50 +492,46 @@ def sort_files(files, path, dict, basename):


def get_assets_files(assets_path, override_paths):
asset_files = {"series": [], "movies": [], "collections": []}
override_files = {"series": [], "movies": [], "collections": []}
asset_types = ['series', 'movies', 'collections']
asset_files = {asset_type: [] for asset_type in ['series', 'movies', 'collections']}
override_files = {asset_type: [] for asset_type in ['series', 'movies', 'collections']}
if assets_path:
files = get_files(assets_path)
basename = os.path.basename(assets_path.rstrip('/'))
asset_files = sort_files(files, assets_path, asset_files, basename)
if isinstance(override_paths, str):
override_paths = [override_paths]
if override_paths:
for paths in override_paths:
files = get_files(paths)
basename = os.path.basename(paths.rstrip('/'))
override_files = sort_files(files, paths, override_files, basename)
for path in tqdm(override_paths, desc="Processing override paths", total=len(override_paths)):
files = get_files(path)
basename = os.path.basename(path.rstrip('/'))
override_files = sort_files(files, path, override_files, basename)
if override_files and asset_files:
asset_files = handle_override_files(asset_files, override_files, asset_types)
for asset_types in asset_files:
for asset in asset_files[asset_types]:
asset_files = handle_override_files(asset_files, override_files, path, asset_types=['series', 'movies', 'collections'])
for asset_type in asset_files:
for asset in asset_files[asset_type]:
normalized_title = normalize_titles(asset['title'])
asset['normalized_title'] = normalized_title
for asset_types in asset_files:
for asset in asset_files[asset_types]:
asset['files'].sort()
logger.debug(json.dumps(asset_files, indent=4))
return asset_files


def handle_override_files(asset_files, override_files, asset_types):
def handle_override_files(asset_files, override_files, path, asset_types):
for type in asset_types:
for override_asset in override_files[type]:
found = False
asset_found = False
for asset in asset_files[type]:
if override_asset['title'] == asset['title'] and override_asset['year'] == asset['year']:
found = True
seen_files = set()
logger.debug(f"Override asset: {override_asset['title']} {override_asset['year']} will be used instead of {asset['title']} {asset['year']}")
asset_found = True
for override_file in override_asset['files']:
override_file_name = os.path.splitext(os.path.basename(override_file))[0]
if override_file_name not in seen_files:
seen_files.add(override_file_name)
asset['files'] = [f for f in asset['files'] if os.path.splitext(os.path.basename(f))[0] != override_file_name]
asset['files'].append(override_file)
if not found:
over_ride_file_name = os.path.split(override_file)[1]
asset['files'] = [f for f in asset['files'] if os.path.split(f)[1] != over_ride_file_name]
asset['files'].append(override_file)
logger.debug(f"Override: Added {override_file} to {asset['title']}")
break
if not asset_found:
asset_files[type].append(override_asset)
logger.debug(f"Override: Added {override_asset['title']} to {type} from {path}")
return asset_files


Expand Down

0 comments on commit 971590f

Please sign in to comment.