Add Sonarr formats

This commit is contained in:
Johan van Eck 2025-07-26 17:13:45 +03:00
parent 8e2e83c509
commit dfe37a51a4
3889 changed files with 32544 additions and 17423 deletions

View file

@ -33,7 +33,7 @@ def collect_custom_format(service, file_name, input_json, output_dir):
conditions = []
for spec in input_json.get("specifications", []):
condition = {
"name": get_file_name(spec.get("name", "")),
"name": get_file_name(service, spec.get("name", "")),
"negate": spec.get("negate", False),
"required": spec.get("required", False),
"type": IMPLEMENTATION_TO_TYPE_MAPPING.get(
@ -63,7 +63,7 @@ def collect_custom_format(service, file_name, input_json, output_dir):
# Compose YAML structure
name = input_json.get("name", "")
yml_data = {
"name": get_file_name(name),
"name": get_file_name(service, name),
"description": f"""[Custom format from TRaSH-Guides.](https://trash-guides.info/{service.capitalize()}/{service.capitalize()}-collection-of-custom-formats/#{file_name})
{markdownify(input_json.get('description', ''))}""".strip(),
@ -80,7 +80,7 @@ def collect_custom_format(service, file_name, input_json, output_dir):
# yml_data["metadata"] = {"includeInRename": include_in_rename}
# Output path
output_path = os.path.join(output_dir, f"{get_file_name(name)}.yml")
output_path = os.path.join(output_dir, f"{get_file_name(service, name)}.yml")
with open(output_path, "w", encoding="utf-8") as f:
yaml.dump(yml_data, f, sort_keys=False, allow_unicode=True)
print(f"Generated: {output_path}")

View file

@ -1,21 +0,0 @@
import os
import yaml
# TODO: Consider not writing these values to the file and rather keeping track in runtime
def remove_trash_references(file_path):
with open(file_path, "r", encoding="utf-8") as f:
data = yaml.safe_load(f)
data.pop("trash_id", None)
data.pop("trash_scores", None)
def clean_files(dirs):
for dir in dirs:
for root, _, files in os.walk(dir):
for filename in files:
if not filename.endswith(".yaml"):
continue
file_path = os.path.join(root, filename)
remove_trash_references(file_path)

View file

@ -8,15 +8,17 @@ from utils.qualities import QUALITIES
from utils.strings import get_file_name
def collect_profile_formats(trash_score_set, format_items, trash_id_to_scoring_mapping):
def collect_profile_formats(
service, trash_score_name, format_items, trash_id_to_scoring_mapping
):
profile_formats = []
for name, trash_id in format_items.items():
scoring = trash_id_to_scoring_mapping[trash_id]
score = scoring.get(trash_score_set, scoring.get("default", 0))
score = scoring.get(trash_score_name, scoring.get("default", 0))
if score == 0:
continue
profile_formats.append({"name": get_file_name(name), "score": score})
profile_formats.append({"name": get_file_name(service, name), "score": score})
return sorted(
profile_formats,
key=lambda profile_format: (
@ -76,7 +78,7 @@ def collect_profile(service, input_json, output_dir, trash_id_to_scoring_mapping
name = input_json.get("name", "")
profile_qualities = collect_qualities(input_json.get("items", []))
yml_data = {
"name": get_file_name(name),
"name": get_file_name(service, name),
"description": f"""[Profile from TRaSH-Guides.](https://trash-guides.info/{service.capitalize()}/{service}-setup-quality-profiles)
{markdownify(input_json.get('trash_description', ''))}""".strip(),
@ -86,6 +88,7 @@ def collect_profile(service, input_json, output_dir, trash_id_to_scoring_mapping
"upgradeUntilScore": input_json.get("cutoffFormatScore", 0),
"minScoreIncrement": input_json.get("minUpgradeFormatScore", 0),
"custom_formats": collect_profile_formats(
service,
input_json.get("trash_score_set"),
input_json.get("formatItems", {}),
trash_id_to_scoring_mapping,
@ -96,7 +99,7 @@ def collect_profile(service, input_json, output_dir, trash_id_to_scoring_mapping
}
# Output path
output_path = os.path.join(output_dir, f"{get_file_name(name)}.yml")
output_path = os.path.join(output_dir, f"{get_file_name(service, name)}.yml")
with open(output_path, "w", encoding="utf-8") as f:
yaml.dump(yml_data, f, sort_keys=False, allow_unicode=True)
print(f"Generated: {output_path}")

View file

@ -27,8 +27,8 @@ def collect_regex_pattern(service, file_name, input_json, output_dir):
# Compose YAML structure
name = spec.get("name", "")
yml_data = {
"name": get_file_name(name),
"pattern": get_file_name(pattern),
"name": get_file_name(service, name),
"pattern": pattern,
"description": "",
"tags": [],
"tests": [],
@ -37,7 +37,7 @@ def collect_regex_pattern(service, file_name, input_json, output_dir):
# Output path
output_path = os.path.join(
output_dir,
f"{get_file_name(name)}.yml",
f"{get_file_name(service, name)}.yml",
)
with open(output_path, "w", encoding="utf-8") as f:
yaml.dump(yml_data, f, sort_keys=False, allow_unicode=True)

View file

@ -1,5 +1,5 @@
def get_file_name(profile_name):
return (
def get_file_name(service, profile_name):
safe_profile_name = (
profile_name.replace("/", "-")
.replace("[", "(")
.replace("]", ")")
@ -7,3 +7,4 @@ def get_file_name(profile_name):
.replace("10 bit", "10bit")
.replace("Atmos", "ATMOS")
)
return f"{service}-{safe_profile_name}"