added windows fixes

This commit is contained in:
FrederikBaerentsen 2023-01-19 15:41:27 +01:00
parent 59256c35ac
commit 89e68e3f8e
4 changed files with 41 additions and 25 deletions

View File

@ -4,6 +4,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
WIN_DRIVE_LETTER = 'B'
DEFAULT_SEARCH_NUMBER = 10
TEENYOPDS_ADMIN_PASSWORD = os.getenv("TEENYOPDS_ADMIN_PASSWORD", None) TEENYOPDS_ADMIN_PASSWORD = os.getenv("TEENYOPDS_ADMIN_PASSWORD", None)

27
main.py
View File

@ -31,6 +31,7 @@ def verify_password(username, password):
@app.route("/") @app.route("/")
def startpage(): def startpage():
#result = "Hello, World!"
conn = sqlite3.connect('app.db') conn = sqlite3.connect('app.db')
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute("select * from comics;") cursor.execute("select * from comics;")
@ -50,7 +51,7 @@ def import2sql():
importcount = 0 importcount = 0
skippedcount = 0 skippedcount = 0
errorcount = 0 errorcount = 0
comics_with_errors = []
start_time = timeit.default_timer() start_time = timeit.default_timer()
for root, dirs, files in os.walk(os.path.abspath(config.CONTENT_BASE_DIR)): for root, dirs, files in os.walk(os.path.abspath(config.CONTENT_BASE_DIR)):
for file in files: for file in files:
@ -83,8 +84,14 @@ def import2sql():
#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[0]+",'"+ISSUE+"','"+SERIES+"','"+VOLUME+"','"+PUBLISHER+"','"+TITLE+"','"+file+"','" + f + "','" + UPDATED + "')"
#print(sql,file=sys.stdout) #print(sql,file=sys.stdout)
#conn.execute(sql); #conn.execute(sql);
query = "SELECT UPDATED FROM COMICS WHERE CVDB = '" + str(CVDB[0]) + "';"
savedmodtime = conn.execute(query).fetchone()[0] # 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]) + "';"
savedmodtime = conn.execute(query).fetchone()[0]
except:
savedmodtime = 0
#print(savedmodtime) #print(savedmodtime)
#print(float(savedmodtime)) #print(float(savedmodtime))
#print(type(savedmodtime)) #print(type(savedmodtime))
@ -92,24 +99,25 @@ def import2sql():
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[0]) + " - s: " + str(savedmodtime))
print(str(CVDB[0]) + " - f: " + str(filemodtime)) #print(str(CVDB[0]) + " - f: " + str(filemodtime))
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[0], ISSUE, SERIES, VOLUME, PUBLISHER, TITLE, file, f, UPDATED))
conn.commit() conn.commit()
print("Adding: " + str(CVDB[0])) #print("Adding: " + str(CVDB[0]))
importcount = importcount + 1 importcount = importcount + 1
else: else:
# print("Skipping: " + str(CVDB[0])) # print("Skipping: " + str(CVDB[0]))
skippedcount = skippedcount + 1 skippedcount = skippedcount + 1
except: except:
errorcount = errorcount + 1 errorcount = errorcount + 1
print(f,file=sys.stdout) comics_with_errors.append(f)
#print(f,file=sys.stdout)
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"
print(elapsed_time) import_stats = elapsed_time + "<br>Comics: " + str(comiccount) + "<br>Imported: " + str(importcount) + "<br>Skipped: " + str(skippedcount) + "<br>Errors: " + str(errorcount)
return elapsed_time + "<br>Comics: " + str(comiccount) + "<br>Imported: " + str(importcount) + "<br>Skipped: " + str(skippedcount) + "<br>Errors: " + str(errorcount) return import_stats #+ "<br>" + ['<li>' + x + '</li>' for x in comics_with_errors]
@app.route("/content/<path:path>") @app.route("/content/<path:path>")
@auth.login_required @auth.login_required
@ -118,6 +126,7 @@ def send_content(path):
return send_from_directory(config.CONTENT_BASE_DIR, path) return send_from_directory(config.CONTENT_BASE_DIR, path)
@app.route("/catalog") @app.route("/catalog")
@app.route("/catalog/")
@app.route("/catalog/<path:path>") @app.route("/catalog/<path:path>")
@auth.login_required @auth.login_required
def catalog(path=""): def catalog(path=""):

View File

@ -5,7 +5,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape
from .entry import Entry from .entry import Entry
from .link import Link from .link import Link
import sqlite3,json import sqlite3,json
import config
class Catalog(object): class Catalog(object):
def __init__( def __init__(
@ -80,6 +80,8 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
###################### ######################
if not "search" in c.url: if not "search" in c.url:
onlydirs = [ onlydirs = [
f for f in os.listdir(path) if not os.path.isfile(os.path.join(path, f)) f for f in os.listdir(path) if not os.path.isfile(os.path.join(path, f))
@ -87,7 +89,7 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
#print(onlydirs) #print(onlydirs)
for dirname in onlydirs: for dirname in onlydirs:
link = Link( link = Link(
href=quote(f"/catalog/{content_relative_path}/{dirname}"), href=quote(f"/catalog/{content_relative_path}/{dirname}").replace('//','/'), #windows fix
rel="subsection", rel="subsection",
rpath=path, rpath=path,
type="application/atom+xml;profile=opds-catalog;kind=acquisition", type="application/atom+xml;profile=opds-catalog;kind=acquisition",
@ -105,7 +107,7 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
rpath=path, rpath=path,
type="application/atom+xml;profile=opds-catalog;kind=acquisition", type="application/atom+xml;profile=opds-catalog;kind=acquisition",
) )
c.add_entry(Entry(title="Search["+i+"]",id=uuid4(),links=[link2])) c.add_entry(Entry(title="["+i+"]",id=uuid4(),links=[link2]))
if not "search" in c.url: if not "search" in c.url:
onlyfiles = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))] onlyfiles = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
@ -135,7 +137,7 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
#print(data) #print(data)
for e in data: for e in data:
for key, value in e.items(): for key, value in e.items():
#print(key) print(key)
if key == i: if key == i:
query="SELECT * FROM COMICS where " query="SELECT * FROM COMICS where "
for i in value: for i in value:
@ -144,11 +146,11 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
if j == 'SQL': if j == 'SQL':
query = query + k query = query + k
if k != '' and j != "SQL": if k != '' and j != "SQL":
# print(j,k) print(j,k)
if not first: if not first:
query = query + "and " query = query + "and "
if type(k) == list: if type(k) == list:
# print(k) print(k)
if j == "series" or j == "title": if j == "series" or j == "title":
firstS = True firstS = True
query = query + "(" query = query + "("
@ -174,8 +176,12 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
query = query + j + " like '%" + k + "%' " query = query + j + " like '%" + k + "%' "
if first: if first:
first = False first = False
query = query + " order by series asc, cast(issue as unsigned) asc;" query = query + " order by series asc, cast(issue as unsigned) asc "
print("----> " + query) if config.DEFAULT_SEARCH_NUMBER != 0:
query = query + "LIMIT " + str(config.DEFAULT_SEARCH_NUMBER) + ";"
else:
query = query + ";"
print("----> " + query)
sql = query sql = query
#sql="SELECT * from COMICS where SERIES like '%" + i+ "%' or Title like '%" + i+ "%';" #sql="SELECT * from COMICS where SERIES like '%" + i+ "%' or Title like '%" + i+ "%';"
@ -184,7 +190,8 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
#list=[] #list=[]
for r in s: for r in s:
#print(r) #print(r)
tUrl=f""+r[7].replace("/home/drudoo/ComicsTest/Comics/","/content/") tUrl=f""+r[7].replace('\\','/').replace(config.WIN_DRIVE_LETTER + ':','').replace(config.CONTENT_BASE_DIR,"/content")
print(tUrl)
tTitle=r[6] tTitle=r[6]
link3 = Link( link3 = Link(
#href=quote(f"/content/DC Comics/Earth Cities/Gotham City/Batgirl/Annual/(2012) Batgirl Annual/Batgirl Annual #001 - The Blood That Moves Us [December, 2012].cbz"), #href=quote(f"/content/DC Comics/Earth Cities/Gotham City/Batgirl/Annual/(2012) Batgirl Annual/Batgirl Annual #001 - The Blood That Moves Us [December, 2012].cbz"),
@ -193,6 +200,7 @@ def fromdir(root_url, url, content_base_path, content_relative_path):
rpath=path, rpath=path,
type="application/x-cbz", type="application/x-cbz",
) )
print(link3.href)
c.add_entry( c.add_entry(
Entry( Entry(
title=tTitle, title=tTitle,

View File

@ -28,14 +28,13 @@
"issue": "" "issue": ""
} }
] ]
}, },{
{
"DC (BAT)": [ "DC (BAT)": [
{ {
"title": "", "title": "",
"volume": "", "volume": "",
"publisher": "DC Comics", "publisher": "DC Comics",
"series": "Bat", "series": "%bat%",
"issue": "" "issue": ""
} }
] ]
@ -49,8 +48,7 @@
"issue": "" "issue": ""
} }
] ]
}, },{
{
"Girl": [ "Girl": [
{ {
"title": ["girl","man","World"], "title": ["girl","man","World"],
@ -60,8 +58,7 @@
"issue": "" "issue": ""
} }
] ]
}, },{
{
"number 1": [ "number 1": [
{ {
"title": "", "title": "",