Added thumbnail scaling and opds thumbnail preview

This commit is contained in:
FrederikBaerentsen 2023-01-20 15:17:50 +01:00
parent 18377b474a
commit 3ba034ea02
4 changed files with 20 additions and 4 deletions

View File

@ -27,6 +27,9 @@ DEFAULT_SEARCH_NUMBER = 10
# True: logs are printet to terminal # True: logs are printet to terminal
DEBUG = True DEBUG = True
# Max thumbnail size
MAXSIZE = (500,500)
def _print(arg): def _print(arg):
if DEBUG: if DEBUG:
print(arg) print(arg)

17
main.py
View File

@ -5,6 +5,7 @@ from gevent.pywsgi import WSGIServer
import timeit import timeit
import sqlite3 import sqlite3
import os import os
from PIL import Image
import zipfile import zipfile
import gzip import gzip
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -13,6 +14,7 @@ import datetime
import sys import sys
import time import time
from pathlib import Path from pathlib import Path
from io import BytesIO
from opds import fromdir from opds import fromdir
import config,extras import config,extras
@ -65,9 +67,15 @@ def generate():
CVDB=extras.get_cvdb(Bs_data.select('Notes')) CVDB=extras.get_cvdb(Bs_data.select('Notes'))
if force == 'True': if force == 'True':
cover = s.open(filelist[1]).read() cover = s.open(filelist[1]).read()
c = open(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg", 'wb+')
c.write(cover) image = Image.open(BytesIO(cover))
c.close() image.thumbnail(config.MAXSIZE,Image.ANTIALIAS)
image.save(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg")
# Old way of saving without resize
#c = open(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg", 'wb+')
#c.write(cover)
#c.close()
generated = generated + 1 generated = generated + 1
elif Path(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg").exists() == False: elif Path(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg").exists() == False:
cover = s.open(filelist[1]).read() cover = s.open(filelist[1]).read()
@ -81,7 +89,8 @@ def generate():
files_withtout_comicinfo = files_without_comicinfo + 1 files_withtout_comicinfo = files_without_comicinfo + 1
except Exception as e: except Exception as e:
errorcount = errorcount + 1 errorcount = errorcount + 1
config._print("Error (/generate): " + e) config._print("Error (/generate): " + str(e))
config._print(f)
return "Forced generation: " + str(force) + "<br>Comics: " + str(comiccount) + "<br>Generated: " + str(generated) + "<br>CBZ files without ComicInfo.xml: " + str(files_without_comicinfo) + "<br>Errors: " + str(errorcount) + "<br>Skipped: " + str(skippedcount) return "Forced generation: " + str(force) + "<br>Comics: " + str(comiccount) + "<br>Generated: " + str(generated) + "<br>CBZ files without ComicInfo.xml: " + str(files_without_comicinfo) + "<br>Errors: " + str(errorcount) + "<br>Skipped: " + str(skippedcount)

View File

@ -37,6 +37,9 @@
<link rel="http://opds-spec.org/image" <link rel="http://opds-spec.org/image"
href="{{ entry.cover }}" href="{{ entry.cover }}"
type="image/jpg"/> type="image/jpg"/>
<link rel="http://opds-spec.org/image/thumbnail"
href="{{ entry.cover }}"
type="image/jpg"/>
{% for link in entry.links %} {% for link in entry.links %}
<link rel="{{ link.rel }}" <link rel="{{ link.rel }}"
href="{{ link.href }}" href="{{ link.href }}"

View File

@ -5,3 +5,4 @@ Flask-HTTPAuth==4.5.0
gevent==21.8.0 gevent==21.8.0
bs4 bs4
lxml lxml
Pillow