moved cvdb extractor to extras.py

This commit is contained in:
FrederikBaerentsen 2023-01-19 22:33:11 +01:00
parent e8e2ef20d5
commit 7f33098f5e
4 changed files with 22 additions and 17 deletions

View File

@ -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", "/library") #docker
#CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "/home/drudoo/ComicsTest/Comics") #linux #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", "/Comics/ComicRack") #windows
#CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "testlibrary") #windows test library CONTENT_BASE_DIR = os.getenv("CONTENT_BASE_DIR", "testlibrary") #windows test library
THUMBNAIL_DIR = os.getenv("THUMBNAIL_DIR",'thumbnails') THUMBNAIL_DIR = os.getenv("THUMBNAIL_DIR",'thumbnails')

View File

@ -1,4 +1,4 @@
import os import os,re
def get_size(file_path, unit='bytes'): def get_size(file_path, unit='bytes'):
file_size = os.path.getsize(file_path) file_size = os.path.getsize(file_path)
@ -9,3 +9,6 @@ def get_size(file_path, unit='bytes'):
else: else:
size = file_size / 1024 ** exponents_map[unit] size = file_size / 1024 ** exponents_map[unit]
return round(size, 1) return round(size, 1)
def get_cvdb(string):
return re.findall('(?<=\[CVDB)(.*)(?=].)', string[0].text)[0]

23
main.py
View File

@ -14,7 +14,7 @@ import sys
import time import time
from opds import fromdir from opds import fromdir
import config import config,extras
app = Flask(__name__, static_url_path="", static_folder="static") app = Flask(__name__, static_url_path="", static_folder="static")
auth = HTTPBasicAuth() auth = HTTPBasicAuth()
@ -71,10 +71,10 @@ def import2sql():
#print(Bs_data.select('Series')[0].text, file=sys.stderr) #print(Bs_data.select('Series')[0].text, file=sys.stderr)
#print(Bs_data.select('Title')[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) #print(list, file=sys.stdout)
ISSUE=Bs_data.select('Number')[0].text ISSUE=Bs_data.select('Number')[0].text
@ -88,14 +88,14 @@ def import2sql():
PATH=f PATH=f
UPDATED=filemodtime UPDATED=filemodtime
#print(UPDATED,file=sys.stdout) #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) #print(sql,file=sys.stdout)
#conn.execute(sql); #conn.execute(sql);
# CREATE TABLE IF MISSING # CREATE TABLE IF MISSING
# create table COMICS (CVDB, ISSUE, SERIES,VOLUME,PUBLISHER,TITLE,FILE,PATH,UPDATED,PRIMARY KEY(CVDB)) # create table COMICS (CVDB, ISSUE, SERIES,VOLUME,PUBLISHER,TITLE,FILE,PATH,UPDATED,PRIMARY KEY(CVDB))
try: 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] savedmodtime = conn.execute(query).fetchone()[0]
except: except:
savedmodtime = 0 savedmodtime = 0
@ -103,23 +103,24 @@ def import2sql():
#print(float(savedmodtime)) #print(float(savedmodtime))
#print(type(savedmodtime)) #print(type(savedmodtime))
#print(type(filemodtime)) #print(type(filemodtime))
if savedmodtime < filemodtime: if savedmodtime < filemodtime:
#print(str(savedmodtime) + " is less than " + str(filemodtime)) #print(str(savedmodtime) + " is less than " + str(filemodtime))
#print(str(CVDB[0]) + " - s: " + str(savedmodtime)) #print(str(CVDB) + " - s: " + str(savedmodtime))
#print(str(CVDB[0]) + " - f: " + str(filemodtime)) #print(str(CVDB) + " - f: " + str(filemodtime))
cover = s.open(filelist[1]).read() 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.write(cover)
c.close() 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() conn.commit()
#print("Adding: " + str(CVDB[0])) #print("Adding: " + str(CVDB))
importcount = importcount + 1 importcount = importcount + 1
else: else:
# print("Skipping: " + str(CVDB[0])) # print("Skipping: " + str(CVDB))
skippedcount = skippedcount + 1 skippedcount = skippedcount + 1
except Exception as e: except Exception as e:
errorcount = errorcount + 1 errorcount = errorcount + 1

View File

@ -3,7 +3,7 @@ from bs4 import BeautifulSoup
import os import os
import re import re
from extras import get_size import extras
import config import config
class Entry(object): class Entry(object):
@ -60,12 +60,13 @@ class Entry(object):
f=self.links[0].get("rpath")+"/"+self.title+".cbz" f=self.links[0].get("rpath")+"/"+self.title+".cbz"
if os.path.exists(f): if os.path.exists(f):
s = zipfile.ZipFile(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") data=BeautifulSoup(s.open('ComicInfo.xml').read(), "xml")
#self.cover=s.open('P00001.jpg').read() #self.cover=s.open('P00001.jpg').read()
self.authors = data.select('Writer')[0].text.split(",") 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(data)
#print(kwargs["links"][0]) #print(kwargs["links"][0])
#print(data.select('Series')[0].text) #print(data.select('Series')[0].text)