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
6c493df2
Commit
6c493df2
authored
Mar 26, 2019
by
Yijun Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support issue: #843
parent
8923e712
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
helper.py
cps/helper.py
+13
-2
requirements.txt
requirements.txt
+1
-0
No files found.
cps/helper.py
View file @
6c493df2
...
...
@@ -24,6 +24,7 @@ import ub
from
flask
import
current_app
as
app
from
tempfile
import
gettempdir
import
sys
import
io
import
os
import
re
import
unicodedata
...
...
@@ -34,6 +35,7 @@ from flask_babel import gettext as _
from
flask_login
import
current_user
from
babel.dates
import
format_datetime
from
datetime
import
datetime
from
PIL
import
Image
import
shutil
import
requests
try
:
...
...
@@ -445,10 +447,19 @@ def get_book_cover(cover_path):
# saves book cover to gdrive or locally
def
save_cover
(
url
,
book_path
):
img
=
requests
.
get
(
url
)
if
img
.
headers
.
get
(
'content-type'
)
!=
'image/jpeg'
:
web
.
app
.
logger
.
error
(
"Cover is no jpg file, can't save"
)
content_type
=
img
.
headers
.
get
(
'content-type'
)
if
content_type
not
in
(
'image/jpeg'
,
'image/png'
,
'image/webp'
):
web
.
app
.
logger
.
error
(
"Cover is only support jpg/png/webp file, can't save"
)
return
False
# convert to jpg because calibre just support jpg
if
content_type
in
(
'image/png'
,
'image/webp'
):
imgc
=
Image
.
open
(
io
.
BytesIO
(
img
.
content
))
im
=
imgc
.
convert
(
'RGB'
)
tmp_bytesio
=
io
.
BytesIO
()
im
.
save
(
tmp_bytesio
,
format
=
'JPEG'
)
img
.
content
=
tmp_bytesio
.
getvalue
()
if
ub
.
config
.
config_use_google_drive
:
tmpDir
=
gettempdir
()
f
=
open
(
os
.
path
.
join
(
tmpDir
,
"uploaded_cover.jpg"
),
"wb"
)
...
...
requirements.txt
View file @
6c493df2
...
...
@@ -13,3 +13,4 @@ SQLAlchemy>=1.1.0
tornado
>=4.1
Wand
>=0.4.4
unidecode
>=0.04.19
Pillow
>=5.4.0
\ No newline at end of file
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