Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 17 additions & 48 deletions usr/lib/linuxmint/mintinstall/imaging.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 2 additions & 16 deletions usr/lib/linuxmint/mintinstall/mintinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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, ''):
Expand Down
1 change: 0 additions & 1 deletion usr/lib/linuxmint/mintinstall/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down