From 6c0b1a5edaeea6b2cfa33d50ffe2d19338318c3a Mon Sep 17 00:00:00 2001 From: Matthew Lynden Date: Sat, 27 Dec 2025 12:17:12 +1100 Subject: [PATCH 1/2] Add .python-version to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3b3739a..6a65024 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ **/*.log **/*.pickle **/*.sqlite +**/.python-version Kometa/metadata-items From 428824dd82d821807961cc91206d65e02fbbcacd Mon Sep 17 00:00:00 2001 From: Matthew Lynden Date: Sat, 27 Dec 2025 12:20:05 +1100 Subject: [PATCH 2/2] Support asset type subfolders in asset folder --- .env.example | 1 + Kometa/.env.example | 1 + Kometa/README.md | 26 ++++++++++++++-- Kometa/originals-to-assets.py | 58 ++++++++++++++++++++++++----------- 4 files changed, 65 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index a53f915..5d62c5f 100644 --- a/.env.example +++ b/.env.example @@ -40,6 +40,7 @@ RETAIN_TCM_OVERLAID_IMAGES=0 # keep images that have the TCM ove USE_ASSET_NAMING=1 # should grab-all-posters name images to match Kometa's Asset Directory requirements? USE_ASSET_FOLDERS=1 # should those Kometa-Asset-Directory names use asset folders? USE_ASSET_SUBFOLDERS=0 # create asset folders in subfolders ["Collections", "Other", or [0-9, A-Z]] ] +USE_ASSET_TYPE_SUBFOLDERS=0 # should those Kometa-Asset-Directory names use asset type subfolders (movie, show)? ASSETS_BY_LIBRARIES=1 # should those Kometa-Asset-Directory images be sorted into library folders? ASSET_DIR=assets # top-level directory for those Kometa-Asset-Directory images # if asset-directory naming is on, the next three are ignored diff --git a/Kometa/.env.example b/Kometa/.env.example index 83d0dcd..7aaee3e 100644 --- a/Kometa/.env.example +++ b/Kometa/.env.example @@ -18,6 +18,7 @@ KOMETA_CONFIG_DIR=/opt/kometa/config # Path to Kometa config directory # ORIGINAL TO ASSETS USE_ASSET_FOLDERS=1 # should those Kometa-Asset-Directory names use asset folders? +USE_ASSET_TYPE_SUBFOLDERS=0 # should those Kometa-Asset-Directory names use asset type subfolders (movie, show)? ASSET_DIR=assets # top-level directory for those Kometa-Asset-Directory images KOMETA_CONFIG_DIR=/kometa/is/here diff --git a/Kometa/README.md b/Kometa/README.md index bcfb7aa..6d2dee3 100644 --- a/Kometa/README.md +++ b/Kometa/README.md @@ -269,17 +269,37 @@ If you don't have overlays on any episodes, this script will not put any episode ``` # ORIGINAL TO ASSETS USE_ASSET_FOLDERS=1 # should the asset directory use asset folders? +USE_ASSET_TYPE_SUBFOLDERS=1 # optionally, should the asset directory use asset type subfolders? (e.g. 'movie', 'show') ASSET_DIR=assets # top-level directory for those assets ``` -The asset file system will be rooted at the directory in the `ASSET_DIR` setting, and `USE_ASSET_FOLDERS` controls whether the images are stored as: +The asset file system will be rooted at the directory in the `ASSET_DIR` setting, while `USE_ASSET_FOLDERS` and `USE_ASSET_TYPE_SUBFOLDERS` controls whether the images are stored as: `USE_ASSET_FOLDERS=0` ``` -Media-Scripts/Plex/assets/All That Jazz (1979) {imdb-tt0078754} {tmdb-16858}.jpg +# movie|show +Media-Scripts/Plex/assets/.jpg +# season +Media-Scripts/Plex/assets/_Season##.jpg +# episode +Media-Scripts/Plex/assets/_S##E##.jpg ``` or `USE_ASSET_FOLDERS=1` ``` -Media-Scripts/Plex/assets/All That Jazz (1979) {imdb-tt0078754} {tmdb-16858}/poster.jpg +# movie|show +Media-Scripts/Plex/assets//poster.jpg +# season +Media-Scripts/Plex/assets//Season##.jpg +# episode +Media-Scripts/Plex/assets//S##E##.jpg +``` +with `USE_ASSET_TYPE_SUBFOLDERS=1` +``` +# movie|show +Media-Scripts/Plex/assets//... +# season +Media-Scripts/Plex/assets/show/... +# episode +Media-Scripts/Plex/assets/show/... ``` example output: diff --git a/Kometa/originals-to-assets.py b/Kometa/originals-to-assets.py index df40040..cc463d3 100644 --- a/Kometa/originals-to-assets.py +++ b/Kometa/originals-to-assets.py @@ -22,8 +22,9 @@ # 0.0.4 more chatty logging and bail if the original isn't found # 0.0.5 Actually fix TV libraries # 0.0.6 use parent directory name rather than stem +# 0.0.7 add USE_ASSET_TYPE_SUBFOLDERS option -VERSION = "0.0.6" +VERSION = "0.0.7" env_file_path = Path(".env") @@ -87,6 +88,7 @@ def superchat(msg, level, logfile): ASSET_PATH = Path(ASSET_DIR) USE_ASSET_FOLDERS = booler(os.getenv("USE_ASSET_FOLDERS")) +USE_ASSET_TYPE_SUBFOLDERS = booler(os.getenv("USE_ASSET_TYPE_SUBFOLDERS")) if ASSET_DIR is None: ASSET_DIR = "assets" @@ -191,27 +193,47 @@ def target_asset(item): superchat(f"Episode asset name: {asset_name}", "info", "a") if USE_ASSET_FOLDERS: - # Movie/Show poster /ASSET_NAME/poster.ext - target_file = Path(ASSET_PATH, asset_name, "poster.jpg") - # Season poster /ASSET_NAME/Season##.ext + if USE_ASSET_TYPE_SUBFOLDERS: + # If using type subfolders, then assets go in a subfolder for their type (movie or show): + # Movie/Show poster: -> // + # Season/Episode poster: -> /show/ + type_subfolder = "movie" if item.TYPE == "movie" else "show" + base_path = Path(ASSET_PATH, type_subfolder, asset_name) + else: + # Flat asset structure: all assets go directly in an ASSET_PATH/ folder + base_path = Path(ASSET_PATH, asset_name) + if item.TYPE == "season": - target_file = Path( - ASSET_PATH, asset_name, f"Season{str(item_season).zfill(2)}.jpg" - ) - # Episode poster /ASSET_NAME/S##E##.ext - if item.TYPE == "episode": - target_file = Path(ASSET_PATH, asset_name, f"{item_se_str}.jpg") + # Season poster: /Season##.jpg + target_file = base_path / f"Season{str(item_season).zfill(2)}.jpg" + elif item.TYPE == "episode": + # Episode poster: /S##E##.jpg + target_file = base_path / f"{item_se_str}.jpg" + else: + # Movie/Show poster: /poster.jpg + target_file = base_path / "poster.jpg" else: - # Movie/Show poster /ASSET_NAME.ext - target_file = Path(ASSET_PATH, f"{asset_name}.jpg") - # Season poster /ASSET_NAME_Season##.ext + if USE_ASSET_TYPE_SUBFOLDERS: + # If using type subfolders, then assets go in a subfolder for their type (movie or show): + # Movie/Show poster: -> / + # Season/Episode poster: -> /show + type_subfolder = "movie" if item.TYPE == "movie" else "show" + base_path = Path(ASSET_PATH, type_subfolder) + else: + # Flat asset structure: all assets go directly in the ASSET_PATH + base_path = ASSET_PATH + if item.TYPE == "season": - target_file = Path( - ASSET_PATH, f"{asset_name}_Season{str(item_season).zfill(2)}.jpg" + target_file = ( + base_path + / f"{asset_name}_Season{str(item_season).zfill(2)}.jpg" # _Season##.jpg + ) + elif item.TYPE == "episode": + target_file = ( + base_path / f"{asset_name}_{item_se_str}.jpg" # _S##E##.jpg ) - # Episode poster /ASSET_NAME_S##E##.ext - if item.TYPE == "episode": - target_file = Path(ASSET_PATH, f"{asset_name}_{item_se_str}.jpg") + else: + target_file = base_path / f"{asset_name}.jpg" # .jpg superchat(f"Target file: {target_file}", "info", "a")