Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Allow custom icon images / Fix empty image squares for titles #442

Open
gritstub opened this issue Sep 8, 2022 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@gritstub
Copy link

gritstub commented Sep 8, 2022

Is your feature request related to a problem? Please describe.
If a file doesn't have an iconUrl property in titledb, it will show up as a blank square

Describe the solution you'd like
Allow the user to override this with a local file. Possibly check for a cached local file first, otherwise download a new version of the image.

@gritstub gritstub added the enhancement New feature or request label Sep 8, 2022
@gritstub
Copy link
Author

gritstub commented Sep 8, 2022

Here is a quick workaround that I made. It might be better to store an override image in a different folder, in case the user wants to clear their image cache at some time.

diff --git a/nut/Title.py b/nut/Title.py
index d4fbcaa..43c4c1f 100644
--- a/nut/Title.py
+++ b/nut/Title.py
@@ -619,7 +619,7 @@ class Title:

        def download(self, base, fileName, url):
                path = os.path.join(base, fileName)
-               if os.path.isfile(path):
+               if os.path.isfile(path) or url is None:
                        return path
                os.makedirs(base, exist_ok=True)
                urllib.request.urlretrieve(url, path)
@@ -664,10 +664,13 @@ class Title:
                if 'iconUrl' not in self.__dict__:
                        self.iconUrl = None

-               if not self.iconUrl or self.iconUrl.startswith('cocoon:/'):
+               if not self.iconUrl:
+                       baseName = self.id
+                       ext = ".jpg"
+               elif self.iconUrl.startswith('cocoon:/'):
                        return None
-
-               baseName, ext = os.path.splitext(self.iconUrl)
+               else:
+                       baseName, ext = os.path.splitext(self.iconUrl)
                return self.getResizedImage(self.download(Config.paths.titleImages + self.id, 'icon' + ext, self.iconUrl), width, height)

        def screenshotFile(self, i, width=None, height=None):```

@gritstub gritstub changed the title [Feature] Allow custom icon images [Feature] Allow custom icon images / Fix empty image squares for titles Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant