From 7f33098f5e3ee35e7c1f8b3788f7256520e654d2 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Thu, 19 Jan 2023 22:33:11 +0100 Subject: [PATCH] moved cvdb extractor to extras.py --- config.py | 4 ++-- extras.py | 5 ++++- main.py | 23 ++++++++++++----------- opds/entry.py | 7 ++++--- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/config.py b/config.py index 990a05b..3d75855 100644 --- a/config.py +++ b/config.py @@ -3,8 +3,8 @@ from werkzeug.security import generate_password_hash #CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/library") #docker #CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/home/drudoo/ComicsTest/Comics") #linux -CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/Comics/ComicRack") #windows -#CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "testlibrary") #windows test library +#CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/Comics/ComicRack") #windows +CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "testlibrary") #windows test library THUMBNAIL_DIR = os.getenv("THUMBNAIL_DIR",'thumbnails') diff --git a/extras.py b/extras.py index 07e2f4c..8222b62 100644 --- a/extras.py +++ b/extras.py @@ -1,4 +1,4 @@ -import os +import os,re def get_size(file_path, unit='bytes'): file_size = os.path.getsize(file_path) @@ -9,3 +9,6 @@ def get_size(file_path, unit='bytes'): else: size = file_size / 1024 ** exponents_map[unit] return round(size, 1) + +def get_cvdb(string): + return re.findall('(?<=\[CVDB)(.*)(?=].)', string[0].text)[0] diff --git a/main.py b/main.py index 8ddeeed..62c7014 100644 --- a/main.py +++ b/main.py @@ -14,7 +14,7 @@ import sys import time from opds import fromdir -import config +import config,extras app = Flask(__name__, static_url_path="", static_folder="static") auth = HTTPBasicAuth() @@ -71,10 +71,10 @@ def import2sql(): #print(Bs_data.select('Series')[0].text, file=sys.stderr) #print(Bs_data.select('Title')[0].text, file=sys.stderr) - CVDB=re.findall('(?<=\[CVDB)(.*)(?=].)', Bs_data.select('Notes')[0].text) + CVDB=extras.get_cvdb(Bs_data.select('Notes')) - #list.append('CVDB'+CVDB[0] + ': ' + Bs_data.select('Series')[0].text + "(" + Bs_data.select('Volume')[0].text + ") : " + Bs_data.select('Number')[0].text ) + #list.append('CVDB'+CVDB + ': ' + Bs_data.select('Series')[0].text + "(" + Bs_data.select('Volume')[0].text + ") : " + Bs_data.select('Number')[0].text ) #print(list, file=sys.stdout) ISSUE=Bs_data.select('Number')[0].text @@ -88,14 +88,14 @@ def import2sql(): PATH=f UPDATED=filemodtime #print(UPDATED,file=sys.stdout) - #sql="INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES ("+CVDB[0]+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')" + #sql="INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES ("+CVDB+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')" #print(sql,file=sys.stdout) #conn.execute(sql); # CREATE TABLE IF MISSING # create table COMICS (CVDB, ISSUE, SERIES,VOLUME,PUBLISHER,TITLE,FILE,PATH,UPDATED,PRIMARY KEY(CVDB)) try: - query = "SELECT UPDATED FROM COMICS WHERE CVDB = '" + str(CVDB[0]) + "';" + query = "SELECT UPDATED FROM COMICS WHERE CVDB = '" + str(CVDB) + "';" savedmodtime = conn.execute(query).fetchone()[0] except: savedmodtime = 0 @@ -103,23 +103,24 @@ def import2sql(): #print(float(savedmodtime)) #print(type(savedmodtime)) #print(type(filemodtime)) + if savedmodtime < filemodtime: #print(str(savedmodtime) + " is less than " + str(filemodtime)) - #print(str(CVDB[0]) + " - s: " + str(savedmodtime)) - #print(str(CVDB[0]) + " - f: " + str(filemodtime)) + #print(str(CVDB) + " - s: " + str(savedmodtime)) + #print(str(CVDB) + " - f: " + str(filemodtime)) cover = s.open(filelist[1]).read() - c = open(config.THUMBNAIL_DIR + "/" + str(CVDB[0]) + ".jpg", 'wb+') + c = open(config.THUMBNAIL_DIR + "/" + str(CVDB) + ".jpg", 'wb+') c.write(cover) c.close() - conn.execute("INSERT OR REPLACE INTO COMICS (CVDB,ISSUE,SERIES,VOLUME, PUBLISHER, TITLE, FILE,PATH,UPDATED) VALUES (?,?,?,?,?,?,?,?,?)", (CVDB[0], ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED)) + 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[0])) + #print("Adding: " + str(CVDB)) importcount = importcount + 1 else: - # print("Skipping: " + str(CVDB[0])) + # print("Skipping: " + str(CVDB)) skippedcount = skippedcount + 1 except Exception as e: errorcount = errorcount + 1 diff --git a/opds/entry.py b/opds/entry.py index edd676e..cf4f458 100644 --- a/opds/entry.py +++ b/opds/entry.py @@ -3,7 +3,7 @@ from bs4 import BeautifulSoup import os import re -from extras import get_size +import extras import config class Entry(object): @@ -60,12 +60,13 @@ class Entry(object): f=self.links[0].get("rpath")+"/"+self.title+".cbz" if os.path.exists(f): s = zipfile.ZipFile(f) - self.size = get_size(f, 'mb') + self.size = extras.get_size(f, 'mb') data=BeautifulSoup(s.open('ComicInfo.xml').read(), "xml") #self.cover=s.open('P00001.jpg').read() self.authors = data.select('Writer')[0].text.split(",") - self.cover = "/image/" + re.findall('(?<=\[CVDB)(.*)(?=].)', data.select('Notes')[0].text)[0] + ".jpg" + self.cover = "/image/" + extras.get_cvdb(data.select('Notes')) + ".jpg" + #print(data) #print(kwargs["links"][0]) #print(data.select('Series')[0].text)