2022-06-07 09:16:43 +02:00
|
|
|
import zipfile
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
import os
|
2023-01-19 22:21:46 +01:00
|
|
|
import re
|
2022-06-07 09:16:43 +02:00
|
|
|
|
2023-01-19 22:33:11 +01:00
|
|
|
import extras
|
2023-01-19 22:21:46 +01:00
|
|
|
import config
|
2023-01-17 15:01:16 +01:00
|
|
|
|
2022-06-07 09:16:43 +02:00
|
|
|
class Entry(object):
|
|
|
|
valid_keys = (
|
|
|
|
"id",
|
|
|
|
"url",
|
|
|
|
"title",
|
|
|
|
"content",
|
|
|
|
"downloadsPerMonth",
|
|
|
|
"updated",
|
|
|
|
"identifier",
|
|
|
|
"date",
|
|
|
|
"rights",
|
|
|
|
"summary",
|
|
|
|
"dcterms_source",
|
|
|
|
"provider",
|
|
|
|
"publishers",
|
|
|
|
"contributors",
|
|
|
|
"languages",
|
|
|
|
"subjects",
|
|
|
|
"oai_updatedates",
|
|
|
|
"authors",
|
|
|
|
"formats",
|
2023-01-17 15:01:16 +01:00
|
|
|
"size",
|
2022-06-07 09:16:43 +02:00
|
|
|
"links",
|
2023-01-17 15:01:16 +01:00
|
|
|
"cover",
|
|
|
|
"covertype"
|
2022-06-07 09:16:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
required_keys = ("id", "title", "links")
|
|
|
|
|
|
|
|
def validate(self, key, value):
|
|
|
|
if key not in Entry.valid_keys:
|
|
|
|
raise KeyError("invalid key in opds.catalog.Entry: %s" % (key))
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
for key, val in kwargs.items():
|
|
|
|
self.validate(key, val)
|
|
|
|
|
|
|
|
for req_key in Entry.required_keys:
|
|
|
|
if not req_key in kwargs:
|
|
|
|
raise KeyError("required key %s not supplied for Entry!" % (req_key))
|
|
|
|
self.id = kwargs["id"]
|
|
|
|
self.title = kwargs["title"]
|
|
|
|
self.links = kwargs["links"]
|
|
|
|
self._data = kwargs
|
|
|
|
|
|
|
|
#print(">>entry.py")
|
|
|
|
#print(kwargs)
|
2023-05-17 21:47:14 +02:00
|
|
|
print(kwargs["title"])
|
2022-06-07 09:16:43 +02:00
|
|
|
#print(kwargs["links"][0].get("rpath"))
|
|
|
|
#print("--end entry.py")
|
2023-05-17 20:29:52 +02:00
|
|
|
try:
|
|
|
|
if kwargs["links"][0].get("type") == 'application/x-cbz':
|
|
|
|
f=self.links[0].get("rpath")+"/"+self.title+".cbz"
|
|
|
|
if os.path.exists(f):
|
|
|
|
s = zipfile.ZipFile(f)
|
2023-05-17 21:47:14 +02:00
|
|
|
self.size = extras.get_size(f, 'mb')
|
|
|
|
data=BeautifulSoup(s.open('ComicInfo.xml').read(), features="html.parser")
|
2023-05-17 20:29:52 +02:00
|
|
|
#self.cover=s.open('P00001.jpg').read()
|
2022-06-07 09:16:43 +02:00
|
|
|
|
2023-05-17 20:29:52 +02:00
|
|
|
if data.select('Writer') != []:
|
|
|
|
self.authors = data.select('Writer')[0].text.split(",")
|
|
|
|
else:
|
|
|
|
config._print("No Writer found: " + str(data.select('Writer')))
|
|
|
|
|
|
|
|
#self.cover = "/image/" + extras.get_cvdb(data.select('Notes')) + ".jpg"
|
2023-05-17 21:47:14 +02:00
|
|
|
#if data.select('Title') != []:
|
|
|
|
# self.title = data.select('Title')[0]
|
|
|
|
|
|
|
|
# print(data.select('Title')[0])
|
|
|
|
title = data.select('Title')[0].text.replace("&","&")
|
|
|
|
kwargs["title"] = title
|
|
|
|
print(title)
|
2023-05-17 20:29:52 +02:00
|
|
|
if data.select('Summary') != []:
|
2023-05-17 21:47:14 +02:00
|
|
|
#print(data.select('Summary')[0].text)
|
|
|
|
self.summary = data.select('Summary')[0]
|
2023-05-17 20:29:52 +02:00
|
|
|
else:
|
|
|
|
config._print("No Summary found: " + str(data.select('Summary')))
|
2023-01-20 09:26:53 +01:00
|
|
|
|
|
|
|
|
2023-05-17 20:29:52 +02:00
|
|
|
#print(data)
|
|
|
|
#print(kwargs["links"][0])
|
|
|
|
#print(data.select('Series')[0].text)
|
|
|
|
#print(kwargs["links"][0].get("rpath"))
|
|
|
|
if data.select('Series')[0].text in kwargs["links"][0].get("rpath"):
|
|
|
|
releasedate=data.select('Year')[0].text+"-"+data.select('Month')[0].text.zfill(2)+"-"+data.select('Day')[0].text.zfill(2)
|
|
|
|
try:
|
2023-05-17 21:47:14 +02:00
|
|
|
self.title = "#"+data.select('Number')[0].text.zfill(2) + ": " + title + " (" + releasedate + ") [" + str(self.size) + "MB]"
|
2023-05-17 20:29:52 +02:00
|
|
|
except:
|
|
|
|
self.title = "#"+data.select('Number')[0].text.zfill(2) + " (" + releasedate + ") [" + str(self.size) + "MB]"
|
|
|
|
#print(self.title)
|
|
|
|
else:
|
2023-05-17 21:47:14 +02:00
|
|
|
self.title = title
|
2023-01-19 22:33:11 +01:00
|
|
|
|
2022-06-07 09:16:43 +02:00
|
|
|
else:
|
|
|
|
self.title = kwargs["title"]
|
2023-05-17 20:29:52 +02:00
|
|
|
#self.title = data.select('Title')[0].text
|
|
|
|
except Exception as e:
|
|
|
|
config._print(e)
|
2022-06-07 09:16:43 +02:00
|
|
|
def get(self, key):
|
|
|
|
return self._data.get(key, None)
|
|
|
|
|
|
|
|
def set(self, key, value):
|
|
|
|
self.validate(key, value)
|
|
|
|
self._data[key] = value
|