mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Now returning metadata and cover images
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ books/*
|
|||||||
*.json
|
*.json
|
||||||
*.pyc
|
*.pyc
|
||||||
content.opf
|
content.opf
|
||||||
|
.vscode/.editorconfig
|
||||||
|
|||||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -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"
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user