Fixed #6. Imported files should now generate covers on import instead of being skipped

This commit is contained in:
FrederikBaerentsen 2023-01-20 10:07:05 +01:00
parent dd3cce602c
commit b7aa41025a

21
main.py
View File

@ -12,6 +12,7 @@ import re
import datetime import datetime
import sys import sys
import time import time
from pathlib import Path
from opds import fromdir from opds import fromdir
import config,extras import config,extras
@ -49,6 +50,7 @@ def import2sql():
list = [] list = []
comiccount = 0 comiccount = 0
importcount = 0 importcount = 0
coverscount = 0
skippedcount = 0 skippedcount = 0
errorcount = 0 errorcount = 0
comics_with_errors = [] comics_with_errors = []
@ -110,17 +112,22 @@ def import2sql():
#print(str(CVDB) + " - s: " + str(savedmodtime)) #print(str(CVDB) + " - s: " + str(savedmodtime))
#print(str(CVDB) + " - f: " + str(filemodtime)) #print(str(CVDB) + " - f: " + str(filemodtime))
conn.execute("INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES (?,?,?,?,?,?,?,?,?)", (CVDB, ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED))
conn.commit()
print("Adding: " + str(CVDB))
importcount = importcount + 1
elif Path(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg").exists() == False:
#print(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg")
cover = s.open(filelist[1]).read() cover = s.open(filelist[1]).read()
c = open(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg", 'wb+') c = open(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg", 'wb+')
c.write(cover) c.write(cover)
c.close() c.close()
coverscount = coverscount + 1
conn.execute("INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES (?,?,?,?,?,?,?,?,?)", (CVDB, ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED))
conn.commit()
#print("Adding: " + str(CVDB))
importcount = importcount + 1
else: else:
# print("Skipping: " + str(CVDB))
print("Skipping: " + f)
skippedcount = skippedcount + 1 skippedcount = skippedcount + 1
except Exception as e: except Exception as e:
errorcount = errorcount + 1 errorcount = errorcount + 1
@ -131,7 +138,7 @@ def import2sql():
conn.close() conn.close()
elapsed = timeit.default_timer() - start_time elapsed = timeit.default_timer() - start_time
elapsed_time = "IMPORTED IN: " + str(round(elapsed,2)) + "s" elapsed_time = "IMPORTED IN: " + str(round(elapsed,2)) + "s"
import_stats = elapsed_time + "<br>Comics: " + str(comiccount) + "<br>Imported: " + str(importcount) + "<br>Skipped: " + str(skippedcount) + "<br>Errors: " + str(errorcount) import_stats = elapsed_time + "<br>Comics: " + str(comiccount) + "<br>Imported: " + str(importcount) + "<br>Covers: " + str(coverscount) + "<br>Skipped: " + str(skippedcount) + "<br>Errors: " + str(errorcount)
return import_stats #+ "<br>" + ['<li>' + x + '</li>' for x in comics_with_errors] return import_stats #+ "<br>" + ['<li>' + x + '</li>' for x in comics_with_errors]
@app.route("/content/<path:path>") @app.route("/content/<path:path>")