Now returning metadata and cover images

This commit is contained in:
Mike
2019-10-04 13:17:12 -04:00
parent 547e1b632a
commit b3e3ddc072
3 changed files with 10 additions and 7 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@ books/*
*.json *.json
*.pyc *.pyc
content.opf content.opf
.vscode/.editorconfig

View File

@@ -9,5 +9,5 @@
"python.testing.pytestEnabled": false, "python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false, "python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true, "python.testing.unittestEnabled": true,
"python.pythonPath": "/home/raelon/.virtualenvs/spyder/bin/python" "python.pythonPath": "/home/raelon/.virtualenvs/pyShelf/bin/python"
} }

View File

@@ -3,6 +3,7 @@ import json
import os import os
import re import re
import zipfile import zipfile
from PIL import Image
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from config import Config from config import Config
config = Config() config = Config()
@@ -78,19 +79,20 @@ class Catalogue:
book['files'] == list of files from self.process_book(book) book['files'] == list of files from self.process_book(book)
""" """
book_zip = zipfile.ZipFile(book['path'], 'r') book_zip = zipfile.ZipFile(book['path'], 'r')
opf_regx, cover_regx = re.compile(r'\.opf'), re.compile(r'\.jpg|\.png|\.bmp|\.gif') opf_regx, cover_regx = re.compile(r'\.opf'), re.compile(r'\.jpg|\.jpeg|\.png|\.bmp|\.gif')
with book_zip as f: with book_zip as f:
content = list(filter(opf_regx.search, book['files'])) content = book_zip.open(list(filter(opf_regx.search, book['files']))[0])
content = book_zip.open(content[0]) cover = book_zip.open(list(filter(cover_regx.search, book['files']))[0])
soup = BeautifulSoup(content, "xml") soup = BeautifulSoup(content, "xml")
title = soup.find("dc:title") title = soup.find("dc:title")
author = soup.find("dc:creator") author = soup.find("dc:creator")
cover = soup.find("meta", attrs={"name" : "cover"}) book_details = [title.contents[0], author.contents[0], cover]
return title return book_details
def compare_shelf_current(self): def compare_shelf_current(self):
try: try:
self.books self.books
except Exception: except Exception:
self.filter_books() self.filter_books()
unique = set(self.books) - set(self.catalogue) unique = set(self.books) - set(self.catalogue)
return unique return unique