From 8593efd32c529d871981c66c3b984e729ef0e0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Barroso=20Galindo?= Date: Sat, 21 Jan 2023 01:18:48 +0100 Subject: [PATCH] Handling wallpapers too --- .github/db_operator.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/db_operator.py b/.github/db_operator.py index 71d7b09ff..a3b8ba4d5 100755 --- a/.github/db_operator.py +++ b/.github/db_operator.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 -# Copyright (c) 2022 José Manuel Barroso Galindo +# Copyright (c) 2022-2023 José Manuel Barroso Galindo +import subprocess +import sys import time from typing import Any, Dict, Generator, Iterator, List, Optional, Set, Tuple from pathlib import Path @@ -10,7 +12,6 @@ import re import os import json import hashlib -import subprocess import shlex import tempfile from argparse import ArgumentParser @@ -294,6 +295,19 @@ class Tags: if parent in ['gamma', 'filters', 'shadow_masks']: self._append(result, self._use_term('filters_video')) + + elif parent in ['wallpapers']: + try: + ar = image_aspect_ratio(path) + if abs(ar - 1.77) < 0.1: + self._append(result, self._use_term('ar16:9')) + elif abs(ar - 1.33) < 0.1: + self._append(result, self._use_term('ar4:3')) + + except Exception as e: + print('wallpaper image not opened: ' + str(path)) + print(e) + self._append(result, self._use_term(stem)) return result @@ -421,6 +435,15 @@ class Tags: result.append(entry) return sorted(result) +def image_aspect_ratio(path: Path) -> float: + try: + from PIL import Image + except ImportError as _e: + subprocess.run([sys.executable, '-m', 'pip', 'install', 'Pillow'], stderr=subprocess.STDOUT, check=True) + from PIL import Image + img = Image.open(str(path)) + return float(img.width) / float(img.height) + class DatabaseBuilder: main_binaries = ['MiSTer', 'menu.rbf']