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
eede894e
Commit
eede894e
authored
Dec 09, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'merge-metadata'
parents
22add37b
c6146344
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
13 deletions
+36
-13
comic.py
cps/comic.py
+2
-2
editbooks.py
cps/editbooks.py
+22
-4
epub.py
cps/epub.py
+4
-4
uploader.py
cps/uploader.py
+8
-3
No files found.
cps/comic.py
View file @
eede894e
...
...
@@ -105,7 +105,7 @@ def get_comic_info(tmp_file_path, original_file_name, original_file_extension):
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
title
=
loadedMetadata
.
title
or
original_file_name
,
author
=
" & "
.
join
([
credit
[
"person"
]
for
credit
in
loadedMetadata
.
credits
if
credit
[
"role"
]
==
"Writer"
])
or
u
"Unknown"
,
author
=
" & "
.
join
([
credit
[
"person"
]
for
credit
in
loadedMetadata
.
credits
if
credit
[
"role"
]
==
"Writer"
])
or
u
'Unknown'
,
cover
=
extractCover
(
tmp_file_path
,
original_file_extension
),
description
=
loadedMetadata
.
comments
or
""
,
tags
=
""
,
...
...
@@ -118,7 +118,7 @@ def get_comic_info(tmp_file_path, original_file_name, original_file_extension):
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
title
=
original_file_name
,
author
=
u
"Unknown"
,
author
=
u
'Unknown'
,
cover
=
extractCover
(
tmp_file_path
,
original_file_extension
),
description
=
""
,
tags
=
""
,
...
...
cps/editbooks.py
View file @
eede894e
...
...
@@ -360,6 +360,9 @@ def upload_single_file(request, book, book_id):
worker
.
add_upload
(
current_user
.
nickname
,
"<a href=
\"
"
+
url_for
(
'web.show_book'
,
book_id
=
book
.
id
)
+
"
\"
>"
+
uploadText
+
"</a>"
)
return
uploader
.
process
(
saved_filename
,
*
os
.
path
.
splitext
(
requested_file
.
filename
))
def
upload_cover
(
request
,
book
):
if
'btn-upload-cover'
in
request
.
files
:
...
...
@@ -393,17 +396,18 @@ def edit_book(book_id):
flash
(
_
(
u"Error opening eBook. File does not exist or file is not accessible"
),
category
=
"error"
)
return
redirect
(
url_for
(
"web.index"
))
upload_single_file
(
request
,
book
,
book_id
)
meta
=
upload_single_file
(
request
,
book
,
book_id
)
if
upload_cover
(
request
,
book
)
is
True
:
book
.
has_cover
=
1
try
:
to_save
=
request
.
form
.
to_dict
()
merge_metadata
(
to_save
,
meta
)
# Update book
edited_books_id
=
None
#handle book title
if
book
.
title
!=
to_save
[
"book_title"
]
.
rstrip
()
.
strip
():
if
to_save
[
"book_title"
]
==
''
:
to_save
[
"book_title"
]
=
_
(
u'
u
nknown'
)
to_save
[
"book_title"
]
=
_
(
u'
U
nknown'
)
book
.
title
=
to_save
[
"book_title"
]
.
rstrip
()
.
strip
()
edited_books_id
=
book
.
id
...
...
@@ -412,7 +416,7 @@ def edit_book(book_id):
input_authors
=
list
(
map
(
lambda
it
:
it
.
strip
()
.
replace
(
','
,
'|'
),
input_authors
))
# we have all author names now
if
input_authors
==
[
''
]:
input_authors
=
[
_
(
u'
u
nknown'
)]
# prevent empty Author
input_authors
=
[
_
(
u'
U
nknown'
)]
# prevent empty Author
modify_database_object
(
input_authors
,
book
.
authors
,
db
.
Authors
,
db
.
session
,
'author'
)
...
...
@@ -531,6 +535,20 @@ def edit_book(book_id):
return
redirect
(
url_for
(
'web.show_book'
,
book_id
=
book
.
id
))
def
merge_metadata
(
to_save
,
meta
):
if
to_save
[
'author_name'
]
==
_
(
u'Unknown'
):
to_save
[
'author_name'
]
=
''
if
to_save
[
'book_title'
]
==
_
(
u'Unknown'
):
to_save
[
'book_title'
]
=
''
for
s_field
,
m_field
in
[
(
'tags'
,
'tags'
),
(
'author_name'
,
'author'
),
(
'series'
,
'series'
),
(
'series_index'
,
'series_id'
),
(
'languages'
,
'languages'
),
(
'book_title'
,
'title'
)]:
to_save
[
s_field
]
=
to_save
[
s_field
]
or
getattr
(
meta
,
m_field
,
''
)
to_save
[
"description"
]
=
to_save
[
"description"
]
or
Markup
(
getattr
(
meta
,
'description'
,
''
))
.
unescape
()
@
editbook
.
route
(
"/upload"
,
methods
=
[
"GET"
,
"POST"
])
@
login_required_if_no_ano
@
upload_required
...
...
@@ -573,7 +591,7 @@ def upload():
filepath
=
os
.
path
.
join
(
config
.
config_calibre_dir
,
author_dir
,
title_dir
)
saved_filename
=
os
.
path
.
join
(
filepath
,
title_dir
+
meta
.
extension
.
lower
())
if
title
!=
u'Unknown'
and
authr
!=
u'Unknown'
:
if
title
!=
_
(
u'Unknown'
)
and
authr
!=
_
(
u'Unknown'
)
:
entry
=
helper
.
check_exists_book
(
authr
,
title
)
if
entry
:
log
.
info
(
"Uploaded book probably exists in library"
)
...
...
cps/epub.py
View file @
eede894e
...
...
@@ -71,19 +71,19 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
else
:
epub_metadata
[
s
]
=
p
.
xpath
(
'dc:
%
s/text()'
%
s
,
namespaces
=
ns
)[
0
]
else
:
epub_metadata
[
s
]
=
"Unknown"
epub_metadata
[
s
]
=
u'Unknown'
if
epub_metadata
[
'subject'
]
==
"Unknown"
:
if
epub_metadata
[
'subject'
]
==
u'Unknown'
:
epub_metadata
[
'subject'
]
=
''
if
epub_metadata
[
'description'
]
==
"Unknown"
:
if
epub_metadata
[
'description'
]
==
u'Unknown'
:
description
=
tree
.
xpath
(
"//*[local-name() = 'description']/text()"
)
if
len
(
description
)
>
0
:
epub_metadata
[
'description'
]
=
description
else
:
epub_metadata
[
'description'
]
=
""
if
epub_metadata
[
'language'
]
==
"Unknown"
:
if
epub_metadata
[
'language'
]
==
u'Unknown'
:
epub_metadata
[
'language'
]
=
""
else
:
lang
=
epub_metadata
[
'language'
]
.
split
(
'-'
,
1
)[
0
]
.
lower
()
...
...
cps/uploader.py
View file @
eede894e
...
...
@@ -21,6 +21,8 @@ from __future__ import division, print_function, unicode_literals
import
os
import
hashlib
from
tempfile
import
gettempdir
from
flask_babel
import
gettext
as
_
from
.
import
logger
,
comic
from
.constants
import
BookMeta
...
...
@@ -91,6 +93,8 @@ def process(tmp_file_path, original_file_name, original_file_extension):
log
.
warning
(
'cannot parse metadata, using default:
%
s'
,
ex
)
if
meta
and
meta
.
title
.
strip
()
and
meta
.
author
.
strip
():
if
meta
.
author
.
lower
()
==
'unknown'
:
meta
=
meta
.
_replace
(
author
=
_
(
u'Unknown'
))
return
meta
else
:
return
default_meta
(
tmp_file_path
,
original_file_name
,
original_file_extension
)
...
...
@@ -101,7 +105,7 @@ def default_meta(tmp_file_path, original_file_name, original_file_extension):
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
title
=
original_file_name
,
author
=
u"Unknown"
,
author
=
_
(
u'Unknown'
)
,
cover
=
None
,
description
=
""
,
tags
=
""
,
...
...
@@ -119,13 +123,14 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
doc_info
=
None
if
doc_info
is
not
None
:
author
=
doc_info
.
author
if
doc_info
.
author
else
u
"Unknown"
author
=
doc_info
.
author
if
doc_info
.
author
else
u
'Unknown'
title
=
doc_info
.
title
if
doc_info
.
title
else
original_file_name
subject
=
doc_info
.
subject
else
:
author
=
u
"Unknown"
author
=
u
'Unknown'
title
=
original_file_name
subject
=
""
return
BookMeta
(
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
...
...
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