diff --git a/README.md b/README.md index d3cc2ea..eb9f217 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,39 @@ -# pattrmm:develop -[Join our Discord](https://discord.com/invite/7yUYdqgxkn) +# PATTRMM ![returning_soon](https://github.com/InsertDisc/pattrmm-develop/assets/31751462/13fe4fba-eab9-4e3b-be86-fa55e5dedf38) -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. -Extensions have been added to further PATTRMM's capabilities. +[![GitHub release (latest by date)](https://img.shields.io/github/v/release/InsertDisc/pattrmm?style=plastic)](https://github.com/InsertDisc/pattrmm/releases) +[![Docker Nightly](https://img.shields.io/badge/Docker-develop-blue?style=plastic)](https://github.com/users/insertdisc/packages/container/package/pattrmm?tag=nightly) +[![Discord](https://img.shields.io/discord/1171872202858188910?style=plastic&label=Discord&color=%252300bc8c)](https://discord.com/invite/7yUYdqgxkn) -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. +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. -Requirements: - Trakt MUST be setup in your PMM installation to post 'returning soon' series and various 'extensions' to. - This is also what the *-returning-soon.yml and *-in-history.yml files will pull from. - The only must-have module is ruamel.yaml. This is included in requirements.txt. - Note, some environments may also need 'requests' installed. - If you want to use the default template font you will also need the font - from the extras folder in your pmm fonts folder. +> **_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. -For stand-alone setup: + +## Installation + + +### Requirements + +Obviously, Plex-Meta-Manager (PMM) must be installed and setup on your machine. Additionally, Trakt MUST be setup in your PMM installation to post 'returning soon' series and various 'extensions' to. This is also what the *-returning-soon-metadata.yml and *-in-history.yml files will pull from. The only must-have module is ruamel.yaml. This is included in requirements.txt. Note, some environments may also need 'requests' installed. If you want to use the default template font you will also need the font from the extras folder in your pmm fonts folder. + + +### Stand-alone setup - Just drop pattrymm.py in a subfolder of your Plex Meta Manager config folder - (i.e. Plex-meta-manager/config/pattrmm/pattrmm.py) and run it. - A settings file will be created in the newly created preferences folder. - The script will stop so you can fill in the appropriate settings in preferences/settings.yml. - You can modify the appearance of the generated overlays file using the - preferences/*-returning-soon-template.yml files. - Run the script again after you make your changes to initiate a full cycle. +1. Drop pattrymm.py in a subfolder of your Plex Meta Manager config folder (i.e. Plex-meta-manager/config/pattrmm/pattrmm.py) and run it. A settings file will be created in the newly created preferences folder. The script will stop. +2. Fill in the appropriate settings in preferences/settings.yml (see [Settings file](#settings-file)). You can modify the appearance of the generated overlays file using the preferences/*-returning-soon-template.yml files. +3. Run the script again after you make your changes to initiate a full cycle. - UPDATING: To update the stand-alone version, you need to delete OR replace vars.py and replace pattrmm.py. +To update the stand-alone version, you need to delete OR replace vars.py and replace pattrmm.py. -Docker Compose: -``` + +### Docker setup + +```yaml services: pattrmm: - image: ghcr.io/insertdisc/pattrmm:develop + image: ghcr.io/insertdisc/pattrmm:nightly container_name: pattrmm environment: - PUID=1000 @@ -43,31 +41,78 @@ services: - TZ=America/New_York - PATTRMM_TIME=02:00 # Schedule run time volumes: - - ./pattrmm/data:/data - - ./pattrmm/preferences:/preferences - - ./pmm/config:/config + - /path/to/pattrmm/data:/data + - /path/to/pattrmm/preferences:/preferences + - /path/to/pmm/config:/config restart: unless-stopped ``` -If using the docker version, you can initialize the settings file with this command. -``` -docker run --rm -it -v "./pattrmm/preferences:/preferences" ghcr.io/insertdisc/pattrmm:develop --run + +You can initialize the settings file for the docker version with this command: + +*Replace the paths below with the appropriate location for the directories used.* + +```bash +docker run --rm -it -v "/path/to/pattrmm/preferences:/preferences" ghcr.io/insertdisc/pattrmm:nightly --run ``` -The DEVELOP branch is slightly ahead of the latest branch. -Extensions have been added and will continue to expand. + +If you want to run Pattrmm now and not wait for `PATTRMM_TIME`, use this command: + +*Replace the paths below with the appropriate location for the directories used.* + +```bash +docker run --rm -it -v "/path/to/pattrmm/preferences:/preferences" -v "/path/to/pattrmm/data:/data" -v "/path/to/pmm/config:/config" ghcr.io/insertdisc/pattrmm:nightly --run ``` -Extensions Available: - in-history - This extension uses the Originally Available At date within Plex to create Trakt lists - based on a specified range per library and a corresponding 'in-history' metadata file - for use with that library. - by_size - This extension uses information available within Plex to approximate Movie sizes, without - needing access to the filesystem, to create an ordered and filtered trakt list and accompanying - 'by-size' metadata file for use with each corresponding 'Movie' library. + +The Docker version runs daily at the specified PATTRMM_TIME. This is a 24 hour format. + +### unRAID setup + +Pattrmm now has a template available in the Community Applications for unRAID. This should be the easiest way to use Pattrmm in unRAID. + +1. Head over to the `Apps` tab in your unRAID instance and search for `Pattrmm`. There should only be one template from Droppisalt. +2. Select the `Install` button +3. Choose which branch you want to run `latest`, `develop`, or `nightly`. +4. Fill-in the required Paths and Environment Variables. **Make sure of the following:** The `/config` points to your `Plex-Meta-Manager` config.yml and NOT to the default folder that unRAID might point to (often `.../appdata/pattrmm`) + - See below for an example. +5. Select `Apply`. + +You can initialize the settings file for the docker version with this command: + +*Replace the paths below with the appropriate location for the directories used.* + +```bash +docker run --rm -it -v "/path/to/pattrmm/preferences:/preferences" ghcr.io/insertdisc/pattrmm:nightly --run ``` -Settings +If you want to run Pattrmm now and not wait for `PATTRMM_TIME`, use this command: + +*Replace the paths below with the appropriate location for the directories used.* + +```bash +docker run --rm -it -v "/path/to/pattrmm/preferences:/preferences" -v "/path/to/pattrmm/data:/data" -v "/path/to/pmm/config:/config" ghcr.io/insertdisc/pattrmm:nightly --run ``` + +![image](https://github.com/InsertDisc/pattrmm/assets/67336980/24e23d34-8d92-4afc-a0bc-138ecfcc3067) + + +## Extensions + +Extensions have been added and will continue to expand. Extensions Available: + +1. In-History + + This extension uses the Originally Available At date within Plex to create Trakt lists based on a specified range per library and a corresponding 'in-history' metadata file for use with that library. + +2. By-Size + + This extension uses information available within Plex to approximate Movie sizes, without needing access to the filesystem, to create an ordered and filtered trakt list and accompanying 'by-size' metadata file for use with each corresponding 'Movie' library. + + +## Settings file + +This is an example PATTRMM settings file: + +```yaml libraries: Anime: save_folder: metadata/anime/ @@ -174,138 +219,149 @@ extra_overlays: font_color: "#FFFFFF" text: "C A N C E L E D" ``` -Standard library options: -``` + + +### Standard library options + +```yaml save_folder: collections/ - Specify a location to write the returning soon metadata file to. Your PMM config folder - (where your config.yml is), will always be the BASE location. - So, a save_folder of 'collections/' - would put your file in a 'collections' sub-folder. If this directory does not exist - PATTRMM will ATTEMPT to create it. - Default location is beside your config.yml and does not need specified. - -overlay_save_folder: overlay-files/ - Specify a location to write the returning soon overlay file to. Your PMM config folder - (where your config.yml is), will always be the BASE location. - So, a save_folder of 'overlay-files/' - would put your file in a 'overlay-files' sub-folder. If this directory does not exist - PATTRMM will ATTEMPT to create it. - Default location is the default PMM 'overlays' folder and does not need specified. + # Specify a location to write the returning soon metadata file to. Your PMM config folder + # (where your config.yml is), will always be the BASE location. + # So, a save_folder of 'collections/' + # would put your file in a 'collections' sub-folder. If this directory does not exist + # PATTRMM will ATTEMPT to create it. + # Default location is beside your config.yml and does not need specified. + +overlay_save_folder: overlays/ + # Specify a location to write the returning soon overlay file to. Your PMM config folder + # (where your config.yml is), will always be the BASE location. + # So, a save_folder of 'overlays/' + # would put your file in a 'overlays' sub-folder. If this directory does not exist + # PATTRMM will ATTEMPT to create it. + # Default location is the default PMM 'overlays' folder and does not need specified. trakt_list_privacy: private - Specify public/private trakt list privacy for returning soon list. Can be set per library. - Default is private and does not need specified. + # Specify public/private trakt list privacy for returning soon list. Can be set per library. + # Default is private and does not need specified. refresh: 30 - Invterval in days to do a full refresh of the libraries airing status. - Sometimes things change. - This makes sure you stay up to date. + # Invterval in days to do a full refresh of the libraries airing status. + # Sometimes things change. + # This makes sure you stay up to date. days_ahead: 45 - How far ahead a title should still be considered 'Returning Soon'. - For example, 45, would consider any title that has a 'Returning' status - and airs again within the next 45 days to be 'Returning Soon'. + # How far ahead a title should still be considered 'Returning Soon'. + # For example, 45, would consider any title that has a 'Returning' status + # and airs again within the next 45 days to be 'Returning Soon'. returning-soon: False - For those that would like to only run extensions on a 'show' library. - This will disable PATTRMM's default 'Returning Soon' operations on this library. - The default setting is True and does not need declared. -``` -Standard PATTRMM options + # For those that would like to only run extensions on a 'show' library. + # This will disable PATTRMM's default 'Returning Soon' operations on this library. + # The default setting is True and does not need declared. ``` + + +### Standard PATTRMM options + +```yaml date_style: 1 - This changes how the dates are formatted in the generated overlay files. - 1 - Will display dates as mm/dd (12/31) for December 31st - 2 - Will display dates as dd/mm (31/12) for December 31st + # This changes how the dates are formatted in the generated overlay files. + # 1 + # Will display dates as mm/dd (12/31) for December 31st + # 2 + # Will display dates as dd/mm (31/12) for December 31st date_delimiter: "/" - Delimiter for dates. Can be "/", "-", "." or "_", e.g. 01/14, 01-14, 01.14, 01_14 - Default is '/' + # Delimiter for dates. Can be "/", "-", "." or "_", e.g. 01/14, 01-14, 01.14, 01_14 + # Default is '/' year_in_dates: False - Show year in dates: 01/14/22 vs 01/14. True or False - Default is False + # Show year in dates: 01/14/22 vs 01/14. True or False + # Default is False extra_overlays: -Included here are various settings used to customize additional 'airing status' overlays -to be included in the generated overlay yml. -If they are not wanted they will need to be disabled with -use: False -as the default behavior is to have them enabled. - -Note: These do not need disabled in a 'Movies' only setup. -'Returning Soon' is not compatible with 'Movies' libraries and will skip those libraries. + # Included here are various settings used to customize additional 'airing status' overlays + # to be included in the generated overlay yml. + # If they are not wanted they will need to be disabled with + # use: False + # as the default behavior is to have them enabled. ``` -Extension settings -in-history: -Enables the 'In History' extension for a library. +> **_NOTE:_** These do not need disabled in a 'Movies' only setup. 'Returning Soon' is not compatible with 'Movies' libraries and will skip those libraries. + + +## Extension settings + +Each extension can only be used within a library ONCE, otherwise an error will occur. +In-History supports ONE range per library. + + +### In-History specific settings + ![this_month_in_history](https://github.com/InsertDisc/pattrmm-develop/assets/31751462/71575460-c575-4b12-9e77-77ec6a8a59e5) ![this_week_in_history](https://github.com/InsertDisc/pattrmm-develop/assets/31751462/f412f703-1d81-4bd1-9a0b-87b10789f271) -``` - In History specific settings - - range: month - This sets the range you would like to filter for. - Options are month, week, day. - For example - - In 'December', having a 'month' range would filter items throughout the years - that were released in December - - During the first week of December, December 1st - December 7th, having a range of 'week' - would filter items released on December 1st - December 7th of qualified years. - - On December 5th, having a range of 'day' would filter items releasd on December 5th - of qualified years. - - starting: 1975 - Allows you to specify the 'earliest' year the filter will go back till. - A setting of 1975 would not include anything released prior to 1975. - If this declaration is missing then all items up to the 'earliest' will be included. - - ending: 1999 - Allows you to specify the 'latest' year the filter will go up to. - 1999 Would not include anything released after that year. - If this delcaration is missing then up to the current year will be included. - - increment: 10 - Allows you to specify the 'spacing' between valid years. - Given an 'ending' year of 2003, would only match to titles released every 10 years out. - So, 2003, 1993, 1983, 1973 - If an 'ending' year is not specified then the current year will be used as the initial year. - - save_folder: collections/ - Specify a location to write the extension metadata file to. Your PMM config folder - (where your config.yml is), will always be the BASE location. - So, a save_folder of 'collections/' - would put your file in a 'collections' sub-folder. If this directory does not exist - PATTRMM will ATTEMPT to create it. - - trakt_list_privacy: private - Specify public/private trakt list privacy for this extension list. Can be set per library. - Default is private and does not need specified. - - collection_title: Released this {{range}} in history. - Title for the collection in the generated metadata yml file. - This can be manually written entirely or you can use {{range}} - to fill in the range automatically. - Given a range of 'month', - Released this {{range}} in history, would generate: - Released this month in history - {{Range}} can be used instead for a capitalized range. - Released This {{Range}} In History, would generate: - Released This Month In History - The {{range}} and {{Range}} placeholders will also work in a 'summary' - if you decide to add one to meta options. - - meta: - Here's where you can apply your 'touch'. - - A default generated metadata yml, with no meta options might look something like: + +```yaml +in-history: #Enables the 'In History' extension for a library. + + range: month + # This sets the range you would like to filter for. + # Options are month, week, day. + # For example + + # In 'December', having a 'month' range would filter items throughout the years + # that were released in December + + # During the first week of December, December 1st - December 7th, having a range of 'week' + # would filter items released on December 1st - December 7th of qualified years. + + # On December 5th, having a range of 'day' would filter items releasd on December 5th + # of qualified years. + + starting: 1975 + # Allows you to specify the 'earliest' year the filter will go back till. + # A setting of 1975 would not include anything released prior to 1975. + # If this declaration is missing then all items up to the 'earliest' will be included. + + ending: 1999 + # Allows you to specify the 'latest' year the filter will go up to. + # 1999 Would not include anything released after that year. + # If this delcaration is missing then up to the current year will be included. + + increment: 10 + # Allows you to specify the 'spacing' between valid years. + # Given an 'ending' year of 2003, would only match to titles released every 10 years out. + # So, 2003, 1993, 1983, 1973 + # If an 'ending' year is not specified then the current year will be used as the initial year. + + save_folder: collections/ + # Specify a location to write the extension metadata file to. Your PMM config folder + # (where your config.yml is), will always be the BASE location. + # So, a save_folder of 'collections/' + # would put your file in a 'collections' sub-folder. If this directory does not exist + # PATTRMM will ATTEMPT to create it. + + trakt_list_privacy: private + # Specify public/private trakt list privacy for this extension list. Can be set per library. + # Default is private and does not need specified. + + collection_title: Released this {{range}} in history. + # Title for the collection in the generated metadata yml file. + # This can be manually written entirely or you can use {{range}} + # to fill in the range automatically. + # Given a range of 'month', + # Released this {{range}} in history, would generate: + # Released this month in history + # {{Range}} can be used instead for a capitalized range. + # Released This {{Range}} In History, would generate: + # Released This Month In History + # The {{range}} and {{Range}} placeholders will also work in a 'summary' + # if you decide to add one to meta options. + + meta: + # Here's where you can apply your 'touch'. + # A default generated metadata yml, with no meta options might look something like: collections: Released This Month In History: @@ -315,13 +371,14 @@ Enables the 'In History' extension for a library. collection_order: custom sync_mode: sync - Any of the options under 'Released This Month In History' - can be overwritten with meta options. + # Any of the options under 'Released This Month In History' + # can be overwritten with meta options. + meta: visible_home: false collection_order: critic_rating.desc - Would generate: + # Would generate: collections: Released This Month In History: @@ -331,15 +388,15 @@ Enables the 'In History' extension for a library. collection_order: critic_rating.desc sync_mode: sync - Notice how the two options were overwritten. Take care not to overwrite your trakt_list. - You can also use meta to ADD any additional in-line options. + # Notice how the two options were overwritten. Take care not to overwrite your trakt_list. + # You can also use meta to ADD any additional in-line options. meta: visible_home: false collection_order: critic_rating.desc sort_title: "!+007" - Generates: + # Generates: collections: Released This Month In History: @@ -348,59 +405,56 @@ Enables the 'In History' extension for a library. visible_shared: true collection_order: critic_rating.desc sync_mode: sync - sort_title: "!+007" + sort_title: "!+007" # As of now, only 'sort_title' will correctly carry over the " around the values. +``` - Note: - As of now, only 'sort_title' will correctly carry over the " around the values. -``` -by_size: -Enables the 'By Size' extension for a library. -![sorted_by_size](https://github.com/InsertDisc/pattrmm/assets/31751462/e53b748e-8ffc-461f-88b3-b752289f7b3e) -``` - By Size specific settings +### By-Size specific settings - minimum: 25 - This sets the minimum filesize to be included in the filtered list. - The default value is 0 and does not need specified. +![sorted_by_size](https://github.com/InsertDisc/pattrmm/assets/31751462/e53b748e-8ffc-461f-88b3-b752289f7b3e) - maximum: 90 - This sets the maximum filesize to be included in the filtered list. - The default value has no upper limit. To use this extension with no - top limit, leave out this setting. - - order_by: size.desc - Further sorting of the filtered list is possible with this option. - The default value is size.desc and does not need specified. - Available options are: - size, title, added (date added to Plex), released (Movie release date) - Each option is compatible with two sort directions but are not required. - asc - Sort items by ascending order - desc - Sort items by descending order - Default sort direction is 'desc' for everything but 'title'. - - For example, to sort by a Movie's 'added to plex' date, with the oldest appearing first - order_by: added.asc - - save_folder: collections/ - Specify a location to write the extension metadata file to. Your PMM config folder - (where your config.yml is), will always be the BASE location. - So, a save_folder of 'collections/' - would put your file in a 'collections' sub-folder. If this directory does not exist - PATTRMM will ATTEMPT to create it. - - trakt_list_privacy: private - Specify public/private trakt list privacy for this extension list. Can be set per library. - Default is private and does not need specified. - - collection_title: Sorted by size - Title for the collection in the generated metadata yml file. - +```yaml +by_size: #Enables the 'By Size' extension for a library. - meta: - Here's where you can apply your 'touch'. + minimum: 25 + # This sets the minimum filesize to be included in the filtered list. + # The default value is 0 and does not need specified. - A default generated metadata yml, with no meta options might look something like: + maximum: 90 + # This sets the maximum filesize to be included in the filtered list. + # The default value has no upper limit. To use this extension with no + # top limit, leave out this setting. + + order_by: size.desc + # Further sorting of the filtered list is possible with this option. + # The default value is size.desc and does not need specified. + # Available options are: + # size, title, added (date added to Plex), released (Movie release date) + # Each option is compatible with two sort directions but are not required. + # asc - Sort items by ascending order + # desc - Sort items by descending order + # Default sort direction is 'desc' for everything but 'title'. + + # For example, to sort by a Movie's 'added to plex' date, with the oldest appearing first + # order_by: added.asc + + save_folder: collections/ + # Specify a location to write the extension metadata file to. Your PMM config folder + # (where your config.yml is), will always be the BASE location. + # So, a save_folder of 'collections/' + # would put your file in a 'collections' sub-folder. If this directory does not exist + # PATTRMM will ATTEMPT to create it. + + trakt_list_privacy: private + # Specify public/private trakt list privacy for this extension list. Can be set per library. + # Default is private and does not need specified. + + collection_title: Sorted by size + # Title for the collection in the generated metadata yml file. + + meta: + # Here's where you can apply your 'touch'. + # A default generated metadata yml, with no meta options might look something like: collections: Sorted by size: @@ -410,13 +464,14 @@ Enables the 'By Size' extension for a library. collection_order: custom sync_mode: sync - Any of the options under 'Sorted by size' - can be overwritten with meta options. + # Any of the options under 'Sorted by size' + # can be overwritten with meta options. + meta: visible_home: false collection_order: critic_rating.desc - Would generate: + # Would generate: collections: Sorted by size: @@ -426,15 +481,15 @@ Enables the 'By Size' extension for a library. collection_order: critic_rating.desc sync_mode: sync - Notice how the two options were overwritten. Take care not to overwrite your trakt_list. - You can also use meta to ADD any additional in-line options. + # Notice how the two options were overwritten. Take care not to overwrite your trakt_list. + # You can also use meta to ADD any additional in-line options. meta: visible_home: false collection_order: critic_rating.desc sort_title: "!+007" - Generates: + # Generates: collections: Sorted by size: @@ -443,33 +498,103 @@ Enables the 'By Size' extension for a library. visible_shared: true collection_order: critic_rating.desc sync_mode: sync - sort_title: "!+007" - - Note: - As of now, only 'sort_title' will correctly carry over the " around the values. - -Each extension can only be used within a library ONCE, otherwise an error will occur. -In-History supports ONE range per library. + sort_title: "!+007" # As of now, only 'sort_title' will correctly carry over the " around the values. ``` -What now: - Add the ?-returning-soon.yml under the appropriate metadata section - of the corresponding library you are having it scan. - Add the overlays/?-returning-soon-overlay.yml - under the appropriate overlay section of the same library. - Don't forget to add any additional metadata files - that any 'extensions' you are using create as well. -When to run: +## What now + +- Add the ?-returning-soon-metadata.yml under the appropriate metadata section of the corresponding library you are having it scan. +- Add the overlays/?-returning-soon-overlay.yml under the appropriate overlay section of the same library. +- Don't forget to add any additional metadata files that any 'extensions' you are using create as well. + + +## When to run + +I've tried my best to optimize how PATTRMM runs, meaning, you can run it on a daily basis using whatever scheduling service your OS utilizes. + +After the initial full cycle, only new entries in Plex will get detailed searches. + +Any series that are not considered a returning series will not be updated upon following runs. Any series that loses it's 'Returning Series' status will be updated accordingly and removed from further searches. This greatly speeds up the process of daily executions. + +Docker version runs daily at the specified PATTRMM_TIME value. + +When creating a schedule or running manually, make sure to run PATTRMM before running Plex-Meta-Manager to get the latest overlay data into Plex. + + +### Linux Scheduling Example + +When using the standalone version you can create a service and run it using a timer (e.g. on a daily basis). + +1. Setup a virtual environment for PATTRMM. Navigate to your pattrmm install folder (`/path/to/pattrmm`) and execute: + ```bash + python3 -m venv pmm-venv + ``` +2. Install the requirements: + ```bash + python -m pip install -r requirements.txt + ``` +4. Create a service file for PATTRMM: + + ```bash + sudo nano /etc/systemd/system/pattrmm.service + ``` + + Put the following into the file: + + ``` + # /etc/systemd/system/pattrmm.service + + [Unit] + Description=PATTRM + + [Service] + User=USER + Group=GROUP + Type=simple + Environment=LC_ALL=C.UTF-8 + Environment=LANG=C.UTF-8 + WorkingDirectory=/path/to/pattrmm + ExecStart=/path/to/pattrmm/pmm-venv/bin/python /path/to/pattrmm/pattrmm.py + ``` + + Change USER and GROUP to reflect your user and group. + + Change /path/to/pattrmm to reflect where you’ve copied/installed PATTRMM. + +5. Create a timer file for PATTRMM: + + ```bash + sudo nano /etc/systemd/system/pattrmm.timer + ``` + + And put the following into the file: + + ``` + # /etc/systemd/system/pattrmm.timer + + [Unit] + Description=PATTRM Timer + + [Timer] + OnCalendar=*-*-* 02:00:00 + Persistent=true + Unit=pattrmm.service + + [Install] + WantedBy=multi-user.target + ``` + +6. Enable and start the timer/service: - I've tried my best to optimize how PATTRMM runs, meaning, - you can run it on a daily basis using whatever scheduling service your OS utilizes. - After the initial full cycle, only new entries in Plex will get detailed searches. - Any series that are not considered a returning series will not be - updated upon following runs. - Any series that loses it's 'Returning Series' status will be updated accordingly - and removed from further searches. - This greatly speeds up the process of daily executions. + ``` + sudo systemctl enable pattrmm.timer + sudo systemctl start pattrmm.timer + ``` + + The `pattrmm.timer` will trigger the `pattrmm.service`. This will run pattrmm.py every day at 2 a.m. + - Docker version runs daily at the specified PATTRMM_TIME. This is a 24 hour format. +## Support, ideas and feedback +Feel free to [join our Discord](https://discord.com/invite/7yUYdqgxkn) to get support or give feedback! diff --git a/pattrmm.py b/pattrmm.py index 648ece3..6f028d4 100644 --- a/pattrmm.py +++ b/pattrmm.py @@ -21,8 +21,11 @@ from io import StringIO import xml.etree.ElementTree as ET import logging +from logging.handlers import RotatingFileHandler import sys +LOG_DIR = "data/logs" +MAIN_LOG = "pattrmm.log" # functions def verify_or_create_folder(folder_path, folder_name_for_logging): @@ -47,6 +50,21 @@ def verify_or_create_file(file_path, file_name_for_logging): else: print(file_name_for_logging.capitalize() + " file present...") +def log_setup(): + """Setup log formatter and handler""" + log_path = LOG_DIR + '/' + MAIN_LOG + need_roll = os.path.isfile(log_path) + + logger = logging.getLogger() + logger.setLevel(logging.INFO) + log_handler = RotatingFileHandler(log_path, backupCount=5) + log_formatter = logging.Formatter('%(asctime)s - %(levelname)s: %(message)s', "%Y-%m-%d %H:%M:%S") + log_handler.setFormatter(log_formatter) + logger.addHandler(log_handler) + + # roll log if already present + if need_roll: + logger.handlers[0].doRollover() print("Verifying files...") @@ -57,14 +75,9 @@ def verify_or_create_file(file_path, file_name_for_logging): # history folder for timestamps verify_or_create_folder("./data/history", "stats") -# logs folder +# logs setup verify_or_create_folder("data/logs", "logs") - -# pattrmm log file -log_file = "data/logs/pattrmm.log" -verify_or_create_file(log_file, "log") - -logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s', datefmt="%Y-%m-%d %H:%M:%S") +log_setup() # preferences folder verify_or_create_folder("preferences", "preferences")