From f458307674ce9011e4ab49df06e18f07e792d751 Mon Sep 17 00:00:00 2001 From: Yozora Date: Sun, 22 Dec 2024 09:44:19 +0000 Subject: [PATCH] [Config] Detect/Copy/Download config.yml from `config.yml.template` so users do not have to rename file. --- CHANGELOG | 7 ++++++- docs/config/overview.md | 9 ++++++--- kometa.py | 43 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 65b8c56e..54a9c998 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,11 +3,15 @@ Update pillow requirement to 11.0.0 Update psutil requirement to 6.1.0 Update setuptools requirement to 75.3.0 +# Important Changes +Python 3.8 is no longer supported. The minimum version of Python required is now 3.9. + # New Features Added the `character` search option to the `imdb_search` builder Added ability to use Show-level ratings at the season and episode level for Overlays if the original source does not provide ratings at the season or episode level. This is accomplished using (Special Text Variables)[https://kometa.wiki/en/latest/files/overlays/#special-text-variables] but is not yet available for the `Ratings` Defaults file. Add `show_unfiltered` setting to display items which make it through a filter Allow `sync_to_trakt_list` on episode-level collections +Logic added to Kometa to create `config.yml` if it does not exist from the `config.yml.template` file. If the template file cannot be found, Kometa will attempt to download it from GitHub. # Docs Added "getting started" page @@ -21,6 +25,7 @@ Fixes an issue where Prime Video overlays/collections would not be built when th Fixes an issue where Rotten Tomatoes Verified Hot wasn't working Updates `Alien vs Predator` and `X-Men` lists to new lists which include most recent releases Adds `style` template variable for Streaming and Chart defaults, allowing user to choose color or white logos for collection posters +Added `Paramount+ with Showtime` to both `Paramount+` and `Showtime` for Networks and Streaming, any existing weighting is unchanged. # Bug Fixes Fixed the `cast` search option for the `imdb_search` builder @@ -38,4 +43,4 @@ Fixes an issue causing IMDB collection to fail due to duplicate keys Removed Blog from the Navigation due to lack of time for updating/maintaining it Fixes #2354 by updating version of tmdbapi dependency Added Start Time, Finished and Run Time to Summary of run. -Fixed an issue where custom repositories would not work correctly if the URL did not end in a trailing `/` character. +Fixed an issue where custom repositories would not work correctly if the URL did not end in a trailing `/` character. \ No newline at end of file diff --git a/docs/config/overview.md b/docs/config/overview.md index bc9b374f..7e361dc9 100644 --- a/docs/config/overview.md +++ b/docs/config/overview.md @@ -5,9 +5,11 @@ connection details needed to connect to Plex Media Server, Radarr, Sonarr, and o By default, and unless otherwise stated, Kometa looks for the configuration file at `/config/config.yml`. -A template Configuration File can be found in the +A template Configuration Template File can be found in the [GitHub Repo](https://github.com/Kometa-Team/Kometa/blob/master/config/config.yml.template). +If Kometa cannot find the `config.yml` at the default location, it will attempt to rename `config.yml.template` for the user. If the template file cannot be found, Kometa will attempt to download a copy from the GitHub repository in line with the user's current branch. If this also fails, the user will have to download the Configuration Template File from the above link and manually rename it to `config.yml` + This table outlines the third-party services that Kometa can make use of. Each service has specific requirements for setup that can be found by clicking the links within the table or in the sidebar. @@ -31,9 +33,10 @@ requirements for setup that can be found by clicking the links within the table | [`trakt`](trakt.md) | :fontawesome-solid-circle-xmark:{ .red } | | [`mal`](myanimelist.md) | :fontawesome-solid-circle-xmark:{ .red } | -## Configuration File Example +## Configuration Template File Example -This example outlines what a "standard" config.yml file might look like when in use. +The below in an extract of the `config.yml.template` and is the initial values that are set if you follow any of the +installation guides. ~~~yaml {% diff --git a/kometa.py b/kometa.py index 0e88a668..615da6a4 100644 --- a/kometa.py +++ b/kometa.py @@ -1,4 +1,4 @@ -import argparse, os, platform, re, sys, time, uuid +import argparse, os, platform, re, sys, time, uuid, requests from collections import Counter from concurrent.futures import ProcessPoolExecutor from datetime import datetime @@ -194,8 +194,45 @@ elif run_args["config"] and not os.path.exists(run_args["config"]): print(f"Config Error: config not found at {os.path.abspath(run_args['config'])}") sys.exit(0) elif not os.path.exists(os.path.join(default_dir, "config.yml")): - print(f"Config Error: config not found at {os.path.abspath(default_dir)}") - sys.exit(0) + template_path = os.path.join(default_dir, "config.yml.template") + config_path = os.path.join(default_dir, "config.yml") + + if os.path.exists(template_path): + try: + with open(template_path, 'r') as template_file: + content = template_file.read() + with open(config_path, 'w') as config_file: + config_file.write(content) + print(f"Configuration file (config.yml) created at {config_path}. Please open this file and update it with your API keys etc.") + sys.exit(1) + except Exception as e: + print(f"Error: Unable to copy the configuration template file from {template_path} to {config_path}. Details: {e}") + sys.exit(1) + else: + if git_branch: + github_url = f"https://raw.githubusercontent.com/Kometa-Team/Kometa/{git_branch}/config/config.yml.template" + try: + response = requests.get(github_url, timeout=10) + if response.status_code == 200: + with open(template_path, 'w') as template_file: + template_file.write(response.text) + with open(config_path, 'w') as config_file: + config_file.write(response.text) + print(f"A Configuration file (config.yml) has been downloaded from GitHub and saved as {config_path}. Please update this file with your API keys and other required settings.") + sys.exit(1) + else: + print(f"Error: No Configuration file (config.yml) found locally, and the template file(config.yml.template) could not be downloaded from GitHub. Please visit the GitHub repository to manually download the config.yml.template file.") + sys.exit(1) + except requests.RequestException as e: + print(f"Error: Failed to download the configuration template file (config.yml.template) from GitHub. Details: {e}") + sys.exit(1) + else: + print( + f"Configuration Error: The configuration file (config.yml) and its template (config.yml.template) are missing from {os.path.abspath(default_dir)}. " + "Additionally, the GitHub branch could not be determined. Please download the template file manually from the GitHub repository." + ) + sys.exit(0) + logger = MyLogger("Kometa", default_dir, run_args["width"], run_args["divider"][0], run_args["ignore-ghost"], run_args["tests"] or run_args["debug"], run_args["trace"], run_args["log-requests"])