From 227d8dbd929c61b356ebe9e0023afd8f68eb997f Mon Sep 17 00:00:00 2001 From: Allen <64094914+allendema@users.noreply.github.com> Date: Sun, 25 Jan 2026 06:46:46 +0100 Subject: [PATCH] fix: refactor app screenshots Fix the debian community screenshots and remove own community + third party screenshots. Also use the json api instead of scraping. Remove not needed imports like bs4, gi{...} etc. Double the allowed screenshots to now allow 8. Signed-off-by: Allen <64094914+allendema@users.noreply.github.com> --- usr/lib/linuxmint/mintinstall/imaging.py | 65 +++++--------------- usr/lib/linuxmint/mintinstall/mintinstall.py | 18 +----- usr/lib/linuxmint/mintinstall/prefs.py | 1 - 3 files changed, 19 insertions(+), 65 deletions(-) diff --git a/usr/lib/linuxmint/mintinstall/imaging.py b/usr/lib/linuxmint/mintinstall/imaging.py index cec7166..9dab7b1 100644 --- a/usr/lib/linuxmint/mintinstall/imaging.py +++ b/usr/lib/linuxmint/mintinstall/imaging.py @@ -1,17 +1,12 @@ #!/usr/bin/python3 import os -import threading import requests -import urllib -import re import logging from concurrent.futures import ThreadPoolExecutor from gi.repository import GObject, Gtk, GLib, Gio, Gdk, GdkPixbuf -import prefs - SCREENSHOT_DIR = os.path.join(GLib.get_user_cache_dir(), "mintinstall", "screenshots") FLATHUB_MEDIA_BASE_URL = "https://dl.flathub.org/media/" FALLBACK_PACKAGE_ICON_PATH = "/usr/share/linuxmint/mintinstall/data/fallback-package-icon.svg" @@ -247,59 +242,33 @@ def _download_screenshots_thread(self): self.add_screenshot(self.pkginfo, None, 0) return - try: - link = "https://community.linuxmint.com/img/screenshots/%s.png" % self.pkginfo.name - if requests.head(link, timeout=5).status_code < 400: - num_screenshots += 1 - local_name = os.path.join(SCREENSHOT_DIR, "%s_%s.png" % (self.pkginfo.name, num_screenshots)) - self.save_to_file(link, None, local_name) + """ + Community screenshots are ~95% from 2014 and severly outdated! + https://community.linuxmint.com/img/screenshots/ - self.add_screenshot(self.pkginfo, local_name, num_screenshots) - except Exception as e: - print(e) + So add screenshots from Debshots. + Documentation: https://screenshots.debian.net/about + """ - try: - # Add additional screenshots from Debian - from bs4 import BeautifulSoup - page = BeautifulSoup(urllib.request.urlopen("https://screenshots.debian.net/package/%s" % self.pkginfo.name, timeout=5), "lxml") - images = page.findAll(href=re.compile(r"/shrine/screenshot[/\d\w]*large-[\w\d]*.png")) - for image in images: - if num_screenshots >= 4: + DEBSHOTS_HOST = "https://screenshots.debian.net" + debshots_api = f"{DEBSHOTS_HOST}/json/package/{self.pkginfo.name}" + + response = requests.get(debshots_api) + if response.status_code == 200: + data = response.json() + for image in data.get("screenshots", []): + if num_screenshots >= 8: break num_screenshots += 1 - thumb = "https://screenshots.debian.net%s" % image['href'] - local_name = os.path.join(SCREENSHOT_DIR, "%s_%s.png" % (self.pkginfo.name, num_screenshots)) + # image in "thumb_image_url" is too small + thumb = image.get("screenshot_image_url") + local_name = os.path.join(SCREENSHOT_DIR, f"{self.pkginfo.name}_{num_screenshots}.png") self.save_to_file(thumb, None, local_name) self.add_screenshot(self.pkginfo, local_name, num_screenshots) - except Exception as e: - pass - - if self.settings.get_boolean(prefs.HAMONIKR_SCREENSHOTS): - try: - # Add additional screenshots from Hamonikr - from bs4 import BeautifulSoup - hamonikrpkgname = self.pkginfo.name.replace("-","_") - page = BeautifulSoup(urllib.request.urlopen("https://hamonikr.org/%s" % hamonikrpkgname, timeout=5), "lxml") - images = page.findAll('img') - for image in images: - if num_screenshots >= 4: - break - if image['src'].startswith('https://hamonikr.org'): - num_screenshots += 1 - - thumb = "%s" % image['src'] - link = thumb - - local_name = os.path.join(SCREENSHOT_DIR, "%s_%s.png" % (self.pkginfo.name, num_screenshots)) - self.save_to_file(link, None, local_name) - - self.add_screenshot(self.pkginfo, local_name, num_screenshots) - except Exception as e: - pass if num_screenshots == 0: self.add_screenshot(self.pkginfo, None, 0) diff --git a/usr/lib/linuxmint/mintinstall/mintinstall.py b/usr/lib/linuxmint/mintinstall/mintinstall.py index 044d0b9..2cf7a78 100755 --- a/usr/lib/linuxmint/mintinstall/mintinstall.py +++ b/usr/lib/linuxmint/mintinstall/mintinstall.py @@ -23,7 +23,7 @@ import gi gi.require_version('Gtk', '3.0') gi.require_version('XApp', '1.0') -from gi.repository import Gtk, Gdk, GdkPixbuf, GObject, GLib, Gio, XApp, Pango +from gi.repository import Gtk, Gdk, GLib, Gio, XApp import cairo from mintcommon.installer import installer @@ -400,7 +400,6 @@ class PackageTile(Gtk.FlowBoxChild): def __init__(self, pkginfo, installer, show_package_type=False, review_info=None): super(PackageTile, self).__init__() - self.button = Gtk.Button(); self.button.connect("clicked", self._activate_fb_child) self.button.set_can_focus(False) self.add(self.button) @@ -1671,7 +1670,7 @@ def add_screenshot(self, pkginfo, ss_path, n): except AttributeError: pass - if ss_path is None: + if ss_path is None or not os.path.exists(ss_path): box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6, valign=Gtk.Align.CENTER) image = Gtk.Image(icon_name="xsi-face-uncertain-symbolic", icon_size=Gtk.IconSize.DIALOG) label = Gtk.Label(label=_("No screenshots available")) @@ -2829,19 +2828,6 @@ def show_package(self, pkginfo, previous_page): self.builder.get_object("application_help_page").hide() description = self.installer.get_description(pkginfo) - - if self.settings.get_boolean(prefs.HAMONIKR_SCREENSHOTS): - try: - from bs4 import BeautifulSoup - hamonikrpkgname = pkginfo.name.replace("-","_") - page = BeautifulSoup(urllib.request.urlopen("https://hamonikr.org/%s" % hamonikrpkgname, timeout=5), "lxml") - texts = page.find("div","xe_content") - text = texts.get_text() - if text is not None: - description = text - except Exception as e: - pass - app_description = self.builder.get_object("application_description") if description not in (None, ''): diff --git a/usr/lib/linuxmint/mintinstall/prefs.py b/usr/lib/linuxmint/mintinstall/prefs.py index 0dcb841..5c1dde7 100644 --- a/usr/lib/linuxmint/mintinstall/prefs.py +++ b/usr/lib/linuxmint/mintinstall/prefs.py @@ -14,7 +14,6 @@ SEARCH_IN_DESCRIPTION = "search-in-description" INSTALLED_APPS = "installed-apps" SEARCH_IN_CATEGORY = "search-in-category" -HAMONIKR_SCREENSHOTS = "hamonikr-screenshots" PACKAGE_TYPE_PREFERENCE = "search-package-type-preference" ALLOW_UNVERIFIED_FLATPAKS = "allow-unverified-flatpaks"