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
2760a781
Commit
2760a781
authored
Mar 19, 2021
by
Ozzie Isaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix metadata recognition fb2 files
parent
8f5c649d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
183 deletions
+59
-183
fb2.py
cps/fb2.py
+12
-12
server.py
cps/server.py
+3
-2
uploader.py
cps/uploader.py
+19
-18
Calibre-Web TestSummary_Linux.html
test/Calibre-Web TestSummary_Linux.html
+25
-151
No files found.
cps/fb2.py
View file @
2760a781
...
@@ -30,50 +30,50 @@ def get_fb2_info(tmp_file_path, original_file_extension):
...
@@ -30,50 +30,50 @@ def get_fb2_info(tmp_file_path, original_file_extension):
}
}
fb2_file
=
open
(
tmp_file_path
)
fb2_file
=
open
(
tmp_file_path
)
tree
=
etree
.
fromstring
(
fb2_file
.
read
())
tree
=
etree
.
fromstring
(
fb2_file
.
read
()
.
encode
()
)
authors
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:title-info/fb:author'
,
namespaces
=
ns
)
authors
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:title-info/fb:author'
,
namespaces
=
ns
)
def
get_author
(
element
):
def
get_author
(
element
):
last_name
=
element
.
xpath
(
'fb:last-name/text()'
,
namespaces
=
ns
)
last_name
=
element
.
xpath
(
'fb:last-name/text()'
,
namespaces
=
ns
)
if
len
(
last_name
):
if
len
(
last_name
):
last_name
=
last_name
[
0
]
.
encode
(
'utf-8'
)
last_name
=
last_name
[
0
]
else
:
else
:
last_name
=
u''
last_name
=
u''
middle_name
=
element
.
xpath
(
'fb:middle-name/text()'
,
namespaces
=
ns
)
middle_name
=
element
.
xpath
(
'fb:middle-name/text()'
,
namespaces
=
ns
)
if
len
(
middle_name
):
if
len
(
middle_name
):
middle_name
=
middle_name
[
0
]
.
encode
(
'utf-8'
)
middle_name
=
middle_name
[
0
]
else
:
else
:
middle_name
=
u''
middle_name
=
u''
first_name
=
element
.
xpath
(
'fb:first-name/text()'
,
namespaces
=
ns
)
first_name
=
element
.
xpath
(
'fb:first-name/text()'
,
namespaces
=
ns
)
if
len
(
first_name
):
if
len
(
first_name
):
first_name
=
first_name
[
0
]
.
encode
(
'utf-8'
)
first_name
=
first_name
[
0
]
else
:
else
:
first_name
=
u''
first_name
=
u''
return
(
first_name
.
decode
(
'utf-8'
)
+
u' '
return
(
first_name
+
u' '
+
middle_name
.
decode
(
'utf-8'
)
+
u' '
+
middle_name
+
u' '
+
last_name
.
decode
(
'utf-8'
))
.
encode
(
'utf-8'
)
+
last_name
)
author
=
str
(
", "
.
join
(
map
(
get_author
,
authors
)))
author
=
str
(
", "
.
join
(
map
(
get_author
,
authors
)))
title
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:title-info/fb:book-title/text()'
,
namespaces
=
ns
)
title
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:title-info/fb:book-title/text()'
,
namespaces
=
ns
)
if
len
(
title
):
if
len
(
title
):
title
=
str
(
title
[
0
]
.
encode
(
'utf-8'
)
)
title
=
str
(
title
[
0
])
else
:
else
:
title
=
u''
title
=
u''
description
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:publish-info/fb:book-name/text()'
,
namespaces
=
ns
)
description
=
tree
.
xpath
(
'/fb:FictionBook/fb:description/fb:publish-info/fb:book-name/text()'
,
namespaces
=
ns
)
if
len
(
description
):
if
len
(
description
):
description
=
str
(
description
[
0
]
.
encode
(
'utf-8'
)
)
description
=
str
(
description
[
0
])
else
:
else
:
description
=
u''
description
=
u''
return
BookMeta
(
return
BookMeta
(
file_path
=
tmp_file_path
,
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
extension
=
original_file_extension
,
title
=
title
.
decode
(
'utf-8'
)
,
title
=
title
,
author
=
author
.
decode
(
'utf-8'
)
,
author
=
author
,
cover
=
None
,
cover
=
None
,
description
=
description
.
decode
(
'utf-8'
)
,
description
=
description
,
tags
=
""
,
tags
=
""
,
series
=
""
,
series
=
""
,
series_id
=
""
,
series_id
=
""
,
...
...
cps/server.py
View file @
2760a781
...
@@ -251,10 +251,11 @@ class WebServer(object):
...
@@ -251,10 +251,11 @@ class WebServer(object):
finally
:
finally
:
self
.
wsgiserver
=
None
self
.
wsgiserver
=
None
# prevent irritating log of pending tasks message from asyncio
logger
.
get
(
'asyncio'
)
.
setLevel
(
logger
.
logging
.
CRITICAL
)
if
not
self
.
restart
:
if
not
self
.
restart
:
log
.
info
(
"Performing shutdown of Calibre-Web"
)
log
.
info
(
"Performing shutdown of Calibre-Web"
)
# prevent irritating log of pending tasks message from asyncio
logger
.
get
(
'asyncio'
)
.
setLevel
(
logger
.
logging
.
CRITICAL
)
return
True
return
True
log
.
info
(
"Performing restart of Calibre-Web"
)
log
.
info
(
"Performing restart of Calibre-Web"
)
...
...
cps/uploader.py
View file @
2760a781
...
@@ -214,7 +214,7 @@ def parse_xmp(pdf_file):
...
@@ -214,7 +214,7 @@ def parse_xmp(pdf_file):
if
xmp_info
:
if
xmp_info
:
try
:
try
:
xmp_author
=
xmp_info
.
dc_creator
# list
xmp_author
=
xmp_info
.
dc_creator
# list
except
:
except
AttributeError
:
xmp_author
=
[
'Unknown'
]
xmp_author
=
[
'Unknown'
]
if
xmp_info
.
dc_title
:
if
xmp_info
.
dc_title
:
...
@@ -228,20 +228,22 @@ def parse_xmp(pdf_file):
...
@@ -228,20 +228,22 @@ def parse_xmp(pdf_file):
xmp_description
=
''
xmp_description
=
''
languages
=
[]
languages
=
[]
for
i
in
xmp_info
.
dc_language
:
try
:
#calibre-web currently only takes one language.
for
i
in
xmp_info
.
dc_language
:
languages
.
append
(
isoLanguages
.
get_lang3
(
i
))
languages
.
append
(
isoLanguages
.
get_lang3
(
i
))
except
AttributeError
:
languages
.
append
(
''
)
xmp_tags
=
', '
.
join
(
xmp_info
.
dc_subject
)
xmp_tags
=
', '
.
join
(
xmp_info
.
dc_subject
)
xmp_publisher
=
', '
.
join
(
xmp_info
.
dc_publisher
)
xmp_publisher
=
', '
.
join
(
xmp_info
.
dc_publisher
)
xmp_languages
=
xmp_info
.
dc_language
return
{
'author'
:
xmp_author
,
return
{
'author'
:
xmp_author
,
'title'
:
xmp_title
,
'title'
:
xmp_title
,
'subject'
:
xmp_description
,
'subject'
:
xmp_description
,
'tags'
:
xmp_tags
,
'languages'
:
languages
,
'tags'
:
xmp_tags
,
'publisher'
:
xmp_publisher
'languages'
:
languages
,
}
'publisher'
:
xmp_publisher
}
def
pdf_meta
(
tmp_file_path
,
original_file_name
,
original_file_extension
):
def
pdf_meta
(
tmp_file_path
,
original_file_name
,
original_file_extension
):
...
@@ -250,8 +252,6 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
...
@@ -250,8 +252,6 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
if
use_pdf_meta
:
if
use_pdf_meta
:
with
open
(
tmp_file_path
,
'rb'
)
as
f
:
with
open
(
tmp_file_path
,
'rb'
)
as
f
:
languages
=
[
""
]
publisher
=
""
pdf_file
=
PdfFileReader
(
f
)
pdf_file
=
PdfFileReader
(
f
)
doc_info
=
pdf_file
.
getDocumentInfo
()
doc_info
=
pdf_file
.
getDocumentInfo
()
xmp_info
=
parse_xmp
(
pdf_file
)
xmp_info
=
parse_xmp
(
pdf_file
)
...
@@ -263,6 +263,13 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
...
@@ -263,6 +263,13 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
tags
=
xmp_info
[
'tags'
]
tags
=
xmp_info
[
'tags'
]
languages
=
xmp_info
[
'languages'
]
languages
=
xmp_info
[
'languages'
]
publisher
=
xmp_info
[
'publisher'
]
publisher
=
xmp_info
[
'publisher'
]
else
:
author
=
u'Unknown'
title
=
''
languages
=
[
""
]
publisher
=
""
subject
=
""
tags
=
""
if
doc_info
:
if
doc_info
:
if
author
==
''
:
if
author
==
''
:
...
@@ -273,14 +280,8 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
...
@@ -273,14 +280,8 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
subject
=
doc_info
.
subject
subject
=
doc_info
.
subject
if
tags
==
''
and
'/Keywords'
in
doc_info
:
if
tags
==
''
and
'/Keywords'
in
doc_info
:
tags
=
doc_info
[
'/Keywords'
]
tags
=
doc_info
[
'/Keywords'
]
else
:
else
:
author
=
u'Unknown'
title
=
original_file_name
title
=
original_file_name
subject
=
""
tags
=
""
languages
=
[
""
]
publisher
=
""
return
BookMeta
(
return
BookMeta
(
file_path
=
tmp_file_path
,
file_path
=
tmp_file_path
,
...
...
test/Calibre-Web TestSummary_Linux.html
View file @
2760a781
This diff is collapsed.
Click to expand it.
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