Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
67736fe1
Commit
67736fe1
authored
Apr 18, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch errors on loading pickle file
Fix for cover images without Pillow
parent
89516fc2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
8 deletions
+25
-8
book_formats.py
cps/book_formats.py
+10
-2
helper.py
cps/helper.py
+7
-3
web.py
cps/web.py
+8
-3
No files found.
cps/book_formats.py
View file @
67736fe1
...
...
@@ -64,6 +64,7 @@ except ImportError as e:
try
:
from
PIL
import
Image
from
PIL
import
__version__
as
PILversion
use_PIL
=
True
except
ImportError
:
use_PIL
=
False
...
...
@@ -175,7 +176,6 @@ def pdf_preview(tmp_file_path, tmp_dir):
cover_file_name
=
os
.
path
.
splitext
(
tmp_file_path
)[
0
]
+
".cover.png"
img
.
save
(
filename
=
os
.
path
.
join
(
tmp_dir
,
cover_file_name
))
return
cover_file_name
# img.save(obj[1:] + ".png")
except
Exception
as
ex
:
print
(
ex
)
try
:
...
...
@@ -206,4 +206,12 @@ def get_versions():
XVersion
=
'v'
+
'.'
.
join
(
map
(
str
,
lxmlversion
))
else
:
XVersion
=
_
(
u'not installed'
)
return
{
'Image Magick'
:
IVersion
,
'PyPdf'
:
PVersion
,
'lxml'
:
XVersion
,
'Wand Version'
:
WVersion
}
if
use_PIL
:
PILVersion
=
'v'
+
PILversion
else
:
PILVersion
=
_
(
u'not installed'
)
return
{
'Image Magick'
:
IVersion
,
'PyPdf'
:
PVersion
,
'lxml'
:
XVersion
,
'Wand'
:
WVersion
,
'Pillow'
:
PILVersion
}
cps/helper.py
View file @
67736fe1
...
...
@@ -482,11 +482,11 @@ def save_cover_from_filestorage(filepath, saved_filename, img):
# saves book cover to gdrive or locally
def
save_cover
(
img
,
book_path
):
content_type
=
img
.
headers
.
get
(
'content-type'
)
if
content_type
not
in
(
'image/jpeg'
,
'image/png'
,
'image/webp'
):
web
.
app
.
logger
.
error
(
"Only jpg/jpeg/png/webp files are supported as coverfile"
)
return
False
if
use_PIL
:
if
content_type
not
in
(
'image/jpeg'
,
'image/png'
,
'image/webp'
):
web
.
app
.
logger
.
error
(
"Only jpg/jpeg/png/webp files are supported as coverfile"
)
return
False
# convert to jpg because calibre only supports jpg
if
content_type
in
(
'image/png'
,
'image/webp'
):
if
hasattr
(
img
,
'stream'
):
...
...
@@ -497,6 +497,10 @@ def save_cover(img, book_path):
tmp_bytesio
=
io
.
BytesIO
()
im
.
save
(
tmp_bytesio
,
format
=
'JPEG'
)
img
.
_content
=
tmp_bytesio
.
getvalue
()
else
:
if
content_type
not
in
(
'image/jpeg'
):
web
.
app
.
logger
.
error
(
"Only jpg/jpeg files are supported as coverfile"
)
return
False
if
ub
.
config
.
config_use_google_drive
:
tmpDir
=
gettempdir
()
...
...
cps/web.py
View file @
67736fe1
...
...
@@ -201,9 +201,14 @@ lm.anonymous_user = ub.Anonymous
app
.
secret_key
=
os
.
getenv
(
'SECRET_KEY'
,
'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
)
db
.
setup_db
()
with
open
(
os
.
path
.
join
(
config
.
get_main_dir
,
'cps/translations/iso639.pickle'
),
'rb'
)
as
f
:
language_table
=
cPickle
.
load
(
f
)
try
:
with
open
(
os
.
path
.
join
(
config
.
get_main_dir
,
'cps/translations/iso639.pickle'
),
'rb'
)
as
f
:
language_table
=
cPickle
.
load
(
f
)
except
cPickle
.
UnpicklingError
as
error
:
app
.
logger
.
error
(
"Can't read file cps/translations/iso639.pickle:
%
s"
,
error
)
print
(
"Can't read file cps/translations/iso639.pickle:
%
s"
%
error
)
helper
.
global_WorkerThread
.
stop
()
sys
.
exit
(
1
)
def
is_gdrive_ready
():
return
os
.
path
.
exists
(
os
.
path
.
join
(
config
.
get_main_dir
,
'settings.yaml'
))
and
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment