Skip to content

Commit

Permalink
Merge pull request #61 from InsertDisc/InsertDisc-patch-status-key
Browse files Browse the repository at this point in the history
Update pattrmm.py
  • Loading branch information
InsertDisc authored Aug 26, 2024
2 parents 4a45ddb + 25b4d45 commit 2d73b33
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 37 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

PATTRMM (Plex Assistant To The Regional Meta Manager) is a python script that automates a 'Returning Soon' Trakt list in chronological order by date and matching metadata and overlay file for use in [Plex Meta Manager](https://metamanager.wiki/en/latest/index.html). Extensions have been added to further PATTRMM's capabilities.

> **_NOTE:_** The latest update changes the *-returning-soon.yml to *-returning-soon-metadata.yml. Make sure to update your pmm config file with the new filename if you've updated your script. If you want to use the new alignment options then you will also need to delete your old 'pattrmm/preferences/' template files.
> **_NOTE:_** The latest update changes the *-returning-soon-metadata.yml to *-returning-soon-collection.yml. Make sure to update your pmm config file with the new filename if you've updated your script. If you want to use the new alignment options then you will also need to delete your old 'pattrmm/preferences/' template files.

## Installation
Expand Down Expand Up @@ -46,6 +46,7 @@ services:
- GUID=1000
- TZ=America/New_York
- PATTRMM_TIME=02:00 # Schedule run time
- RUN_NOW=False # setting this to True will function the same as a -run command line argument and ignore the PATTRMM_TIME.
volumes:
- /path/to/pattrmm/data:/data
- /path/to/pattrmm/preferences:/preferences
Expand Down
7 changes: 6 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
with open("pattrmm.py") as f:
exec(f.read())


if "RUN_NOW" in os.environ:
argument = os.environ["RUN_NOW"]
if argument == True:
with open("pattrmm.py") as f:
exec(f.read())

else:
if "PATTRMM_TIME" in os.environ:
runwhen = os.environ["PATTRMM_TIME"]
Expand Down
89 changes: 54 additions & 35 deletions pattrmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def log_setup():
libraries:
TV Shows: # Plex Libraries to read from. Can enter multiple libraries.
trakt_list_privacy: private
save_folder: "metadata/"
save_folder: "collections/"
overlay_save_folder: "overlays/"
font_path: "fonts/Juventus-Fans-Bold.ttf"
refresh: 30 # Full-refresh delay for library
Expand Down Expand Up @@ -1706,27 +1706,27 @@ def get_missing_episodes_count(self, series_id):
# cache file for tmdb details
cache_file = "./data/" + library_clean_path + "-tmdb-cache.json"

# returning soon metadata save folder
rs_metadata_folder = vars.librarySetting(library, 'save_folder')
pmm_rs_metadata_folder = pmm_config_path_prefix + rs_metadata_folder
if pmm_rs_metadata_folder != '':
pmm_rs_metadata_folder_exists = os.path.exists(pmm_rs_metadata_folder)
if not pmm_rs_metadata_folder_exists:
rs_metadata_subfolder_path = f"config/{rs_metadata_folder}"
print(f"Sub-folder {rs_metadata_subfolder_path} not found.")
# returning soon collection save folder
rs_collection_folder = vars.librarySetting(library, 'save_folder')
pmm_rs_collection_folder = pmm_config_path_prefix + rs_collection_folder
if pmm_rs_collection_folder != '':
pmm_rs_collection_folder_exists = os.path.exists(pmm_rs_collection_folder)
if not pmm_rs_collection_folder_exists:
rs_collection_subfolder_path = f"config/{rs_collection_folder}"
print(f"Sub-folder {rs_collection_subfolder_path} not found.")
print(f"Attempting to create.")
logging.info(f"Sub-folder {rs_metadata_subfolder_path} not found.")
logging.info(f"Sub-folder {rs_collection_subfolder_path} not found.")
logging.info(f"Attempting to create.")
try:
os.makedirs(pmm_rs_metadata_folder)
print(f"{rs_metadata_subfolder_path} created successfully.")
logging.info(f"{rs_metadata_subfolder_path} created successfully.")
os.makedirs(pmm_rs_collection_folder)
print(f"{rs_collection_subfolder_path} created successfully.")
logging.info(f"{rs_collection_subfolder_path} created successfully.")
except Exception as sf:
print(f"Exception: {str(sf)}")
logging.warning(f"Exception: {str(sf)}")

# returning-soon metadata file for collection
rs_metadata_file = pmm_rs_metadata_folder + library_clean_path + "-returning-soon-metadata.yml"
# returning-soon collection file
rs_collection_file = pmm_rs_collection_folder + library_clean_path + "-returning-soon-collection.yml"

# returning soon overlay save folder
rs_overlay_folder = vars.librarySetting(library, 'overlay_save_folder')
Expand Down Expand Up @@ -1806,14 +1806,14 @@ def get_missing_episodes_count(self, series_id):
print(library + " cache file present.")
logging.info(library + " cache file present.")

# If returning-soon metadata file doesn't exist, create it
rs_metadata_file_exists = os.path.exists(rs_metadata_file)
if not rs_metadata_file_exists:
print("Creating " + library + " metadata collection file..")
logging.info("Creating " + library + " metadata collection file..")
create_rs_metadata_file = open(rs_metadata_file, "x")
# If returning-soon collection file doesn't exist, create it
rs_collection_file_exists = os.path.exists(rs_collection_file)
if not rs_collection_file_exists:
print("Creating " + library + " collection file..")
logging.info("Creating " + library + " collection file..")
create_rs_collection_file = open(rs_collection_file, "x")
trakt_user_name = vars.traktApi('me')
create_rs_metadata_file.write(
create_rs_collection_file.write(
f'''
collections:
Returning Soon:
Expand All @@ -1825,10 +1825,10 @@ def get_missing_episodes_count(self, series_id):
sync_mode: sync
'''
)
create_rs_metadata_file.close()
create_rs_collection_file.close()
else:
print(library + " metadata file present.")
logging.info(library + " metadata file present.")
print(library + " collection file present.")
logging.info(library + " collection file present.")


# If overlay template doesn't exist, create it
Expand Down Expand Up @@ -2436,6 +2436,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
weight: 90
back_color: "{upcoming_color}"
vertical_align: {upcoming_vertical_align}
status: upcoming
plex_all: true
filters:
tmdb_status:
Expand All @@ -2456,6 +2457,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {upcoming_vertical_align}
horizontal_offset: {upcoming_horizontal_offset}
vertical_offset: {upcoming_vertical_offset}
status: upcoming
plex_all: true
filters:
tmdb_status:
Expand Down Expand Up @@ -2503,6 +2505,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{new_airing_next_color}"
vertical_align: {new_airing_next_vertical_align}
status: new_airing_next
tmdb_discover:
air_date.gte: {new_airing_next_formatted}
air_date.lte: {new_airing_next_formatted}
Expand All @@ -2512,7 +2515,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
filters:
first_episode_aired.after: {new_first_aired_after_formatted}
# Next Next
# New Next
{library}_Status_Next_Next_{new_next_air_display}:
template:
name: {library}_Status
Expand All @@ -2524,6 +2527,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {new_airing_next_vertical_align}
horizontal_offset: {new_airing_next_horizontal_offset}
vertical_offset: {new_airing_next_vertical_offset}
status: new_airing_next
tmdb_discover:
air_date.gte: {new_airing_next_formatted}
air_date.lte: {new_airing_next_formatted}
Expand Down Expand Up @@ -2559,6 +2563,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{new_color}"
vertical_align: {new_vertical_align}
status: new
plex_all: true
filters:
tmdb_status:
Expand All @@ -2581,6 +2586,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {new_vertical_align}
horizontal_offset: {new_horizontal_offset}
vertical_offset: {new_vertical_offset}
status: new
plex_all: true
filters:
tmdb_status:
Expand Down Expand Up @@ -2619,6 +2625,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{airing_color}"
vertical_align: {airing_vertical_align}
status: airing
plex_all: true
filters:
tmdb_status:
Expand All @@ -2639,6 +2646,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {airing_vertical_align}
horizontal_offset: {airing_horizontal_offset}
vertical_offset: {airing_vertical_offset}
status: airing
plex_all: true
filters:
tmdb_status:
Expand All @@ -2655,6 +2663,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{airing_color}"
vertical_align: {airing_vertical_align}
status: airing_today
tmdb_discover:
air_date.gte: {airing_today_formatted}
air_date.lte: {airing_today_formatted}
Expand All @@ -2674,6 +2683,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {airing_vertical_align}
horizontal_offset: {airing_horizontal_offset}
vertical_offset: {airing_vertical_offset}
status: airing_today
tmdb_discover:
air_date.gte: {airing_today_formatted}
air_date.lte: {airing_today_formatted}
Expand Down Expand Up @@ -2718,6 +2728,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{airing_next_color}"
vertical_align: {airing_next_vertical_align}
status: airing_next
tmdb_discover:
air_date.gte: {airing_next_formatted}
air_date.lte: {airing_next_formatted}
Expand All @@ -2739,6 +2750,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {airing_next_vertical_align}
horizontal_offset: {airing_next_horizontal_offset}
vertical_offset: {airing_next_vertical_offset}
status: airing_next
tmdb_discover:
air_date.gte: {airing_next_formatted}
air_date.lte: {airing_next_formatted}
Expand Down Expand Up @@ -2771,6 +2783,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{ended_color}"
vertical_align: {ended_vertical_align}
status: ended
plex_all: true
filters:
tmdb_status:
Expand All @@ -2788,6 +2801,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {ended_vertical_align}
horizontal_offset: {ended_horizontal_offset}
vertical_offset: {ended_vertical_offset}
status: ended
plex_all: true
filters:
tmdb_status:
Expand Down Expand Up @@ -2815,7 +2829,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{canceled_color}"
vertical_align: {canceled_vertical_align}
status: canceled
plex_all: true
filters:
tmdb_status:
Expand All @@ -2833,6 +2847,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {canceled_vertical_align}
horizontal_offset: {canceled_horizontal_offset}
vertical_offset: {canceled_vertical_offset}
status: canceled
plex_all: true
filters:
tmdb_status:
Expand Down Expand Up @@ -2860,6 +2875,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{returning_color}"
vertical_align: {returning_vertical_align}
status: returning
plex_all: true
filters:
tmdb_status:
Expand All @@ -2879,6 +2895,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {returning_vertical_align}
horizontal_offset: {returning_horizontal_offset}
vertical_offset: {returning_vertical_offset}
status: returning
plex_all: true
filters:
tmdb_status:
Expand Down Expand Up @@ -2907,6 +2924,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
group: banner_backdrop
back_color: "{rs_color}"
vertical_align: {rs_vertical_align}
status: returning_soon
tmdb_discover:
air_date.gte: {this_day}
air_date.lte: {this_day}
Expand All @@ -2928,6 +2946,7 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
vertical_align: {rs_vertical_align}
horizontal_offset: {rs_horizontal_offset}
vertical_offset: {rs_vertical_offset}
status: returning_soon
tmdb_discover:
air_date.gte: {this_day}
air_date.lte: {this_day}
Expand Down Expand Up @@ -3111,8 +3130,8 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat

if not in_history_file_exists:
try:
print(f"Creating {this_library} 'In History' metadata file..")
logging.info(f"Creating {this_library} 'In History' metadata file..")
print(f"Creating {this_library} 'In History' collection file..")
logging.info(f"Creating {this_library} 'In History' collection file..")
create_in_history_file = open(in_history_file, "x")
create_in_history_file.write(in_history_meta_str)
create_in_history_file.close()
Expand All @@ -3124,8 +3143,8 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
except Exception as e:
print(f"An error occurred: {e}")
else:
print(f"Updating {this_library} 'In History' metadata file..")
logging.info(f"Updating {this_library} 'In History' metadata file..")
print(f"Updating {this_library} 'In History' collection file..")
logging.info(f"Updating {this_library} 'In History' collectioin file..")
in_history_file_location = f"config/{in_history_settings.save_folder}{library_clean_path}-in-history.yml"
print(f"{in_history_file_location}")
logging.info(f"{in_history_file_location}")
Expand Down Expand Up @@ -3341,8 +3360,8 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat

if not by_size_file_exists:
try:
print(f"Creating {this_library} 'By Size' metadata file..")
logging.info(f"Creating {this_library} 'By Size' metadata file..")
print(f"Creating {this_library} 'By Size' collection file..")
logging.info(f"Creating {this_library} 'By Size' collection file..")
creata_by_size_file = open(by_size_file, "x")
creata_by_size_file.write(by_size_meta_str)
creata_by_size_file.close()
Expand All @@ -3354,8 +3373,8 @@ def __init__(self, id, title, first_air_date, last_air_date, next_air_date, stat
except Exception as e:
print(f"An error occurred: {e}")
else:
print(f"Updating {this_library} 'By Size' metadata file..")
logging.info(f"Updating {this_library} 'By Size' metadata file..")
print(f"Updating {this_library} 'By Size' collection file..")
logging.info(f"Updating {this_library} 'By Size' collection file..")
by_size_file_location = f"config/{by_size_settings.save_folder}{library_clean_path}-by-size.yml"
print(f"{by_size_file_location}")
logging.info(f"{by_size_file_location}")
Expand Down

0 comments on commit 2d73b33

Please sign in to comment.