mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-06 20:55:10 +01:00
Support for fallback icon, clear empty icon; don't re-download existing
This commit is contained in:
15
digimarks.py
15
digimarks.py
@@ -306,7 +306,6 @@ class Bookmark(BaseModel):
|
|||||||
|
|
||||||
def _set_favicon_with_iconsbetterideaorg(self, domain):
|
def _set_favicon_with_iconsbetterideaorg(self, domain):
|
||||||
""" Fetch favicon for the domain """
|
""" Fetch favicon for the domain """
|
||||||
# TODO: if file exists, don't re-download it
|
|
||||||
fileextension = '.png'
|
fileextension = '.png'
|
||||||
meta = requests.head('http://icons.better-idea.org/icon?size=60&url=' + domain, allow_redirects=True, headers={'User-Agent': DIGIMARKS_USER_AGENT})
|
meta = requests.head('http://icons.better-idea.org/icon?size=60&url=' + domain, allow_redirects=True, headers={'User-Agent': DIGIMARKS_USER_AGENT})
|
||||||
if meta.url[-3:].lower() == 'ico':
|
if meta.url[-3:].lower() == 'ico':
|
||||||
@@ -329,7 +328,6 @@ class Bookmark(BaseModel):
|
|||||||
|
|
||||||
def _set_favicon_with_realfavicongenerator(self, domain):
|
def _set_favicon_with_realfavicongenerator(self, domain):
|
||||||
""" Fetch favicon for the domain """
|
""" Fetch favicon for the domain """
|
||||||
# TODO: if file exists, don't re-download it
|
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
'https://realfavicongenerator.p.mashape.com/favicon/icon?platform=android_chrome&site=' + domain,
|
'https://realfavicongenerator.p.mashape.com/favicon/icon?platform=android_chrome&site=' + domain,
|
||||||
stream=True,
|
stream=True,
|
||||||
@@ -374,6 +372,14 @@ class Bookmark(BaseModel):
|
|||||||
""" Fetch favicon for the domain """
|
""" Fetch favicon for the domain """
|
||||||
u = urlparse(self.url)
|
u = urlparse(self.url)
|
||||||
domain = u.netloc
|
domain = u.netloc
|
||||||
|
if os.path.isfile(os.path.join(MEDIA_ROOT, 'favicons/' + domain + '.png')):
|
||||||
|
# If file exists, don't re-download it
|
||||||
|
self.favicon = domain + '.png'
|
||||||
|
return
|
||||||
|
if os.path.isfile(os.path.join(MEDIA_ROOT, 'favicons/' + domain + '.ico')):
|
||||||
|
# If file exists, don't re-download it
|
||||||
|
self.favicon = domain + '.ico'
|
||||||
|
return
|
||||||
#self._set_favicon_with_iconsbetterideaorg(domain)
|
#self._set_favicon_with_iconsbetterideaorg(domain)
|
||||||
self._set_favicon_with_realfavicongenerator(domain)
|
self._set_favicon_with_realfavicongenerator(domain)
|
||||||
|
|
||||||
@@ -963,7 +969,12 @@ def findmissingfavicons(systemkey):
|
|||||||
try:
|
try:
|
||||||
if not bookmark.favicon or not os.path.isfile(os.path.join(MEDIA_ROOT, 'favicons/' + bookmark.favicon)):
|
if not bookmark.favicon or not os.path.isfile(os.path.join(MEDIA_ROOT, 'favicons/' + bookmark.favicon)):
|
||||||
# This favicon is missing
|
# This favicon is missing
|
||||||
|
# Clear favicon, so fallback can be used instead of showing a broken image
|
||||||
|
bookmark.favicon = None
|
||||||
|
bookmark.save()
|
||||||
|
# Try to fetch and save new favicon
|
||||||
bookmark.set_favicon()
|
bookmark.set_favicon()
|
||||||
|
bookmark.save()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print(e)
|
print(e)
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|||||||
BIN
static/faviconfallback.png
Normal file
BIN
static/faviconfallback.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 243 B |
@@ -5,6 +5,8 @@
|
|||||||
<div class="card-image">
|
<div class="card-image">
|
||||||
{% if bookmark.favicon %}
|
{% if bookmark.favicon %}
|
||||||
<div><img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" class="favicon" /></div>
|
<div><img src="{{ url_for('static', filename='favicons/' + bookmark.favicon) }}" class="favicon" /></div>
|
||||||
|
{% else %}
|
||||||
|
<div><img src="{{ url_for('static', filename='faviconfallback.png') }}" class="favicon" /></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if bookmark.http_status != 200 and bookmark.http_status != 304 %}
|
{% if bookmark.http_status != 200 and bookmark.http_status != 304 %}
|
||||||
<div><i class="small material-icons {{ theme.PROBLEM }}" title="HTTP status {{ bookmark.http_status }}">report_problem</i></div>
|
<div><i class="small material-icons {{ theme.PROBLEM }}" title="HTTP status {{ bookmark.http_status }}">report_problem</i></div>
|
||||||
|
|||||||
Reference in New Issue
Block a user