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
cf35c9dc
Commit
cf35c9dc
authored
Aug 23, 2020
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'name/patch-2' into master
parents
45ff9394
969105b2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
13 deletions
+21
-13
editbooks.py
cps/editbooks.py
+2
-1
helper.py
cps/helper.py
+17
-11
uploader.py
cps/uploader.py
+2
-1
No files found.
cps/editbooks.py
View file @
cf35c9dc
...
@@ -375,7 +375,8 @@ def edit_book_publisher(to_save, book):
...
@@ -375,7 +375,8 @@ def edit_book_publisher(to_save, book):
if
to_save
[
"publisher"
]:
if
to_save
[
"publisher"
]:
publisher
=
to_save
[
"publisher"
]
.
rstrip
()
.
strip
()
publisher
=
to_save
[
"publisher"
]
.
rstrip
()
.
strip
()
if
len
(
book
.
publishers
)
==
0
or
(
len
(
book
.
publishers
)
>
0
and
publisher
!=
book
.
publishers
[
0
]
.
name
):
if
len
(
book
.
publishers
)
==
0
or
(
len
(
book
.
publishers
)
>
0
and
publisher
!=
book
.
publishers
[
0
]
.
name
):
changed
|=
modify_database_object
([
publisher
],
book
.
publishers
,
db
.
Publishers
,
calibre_db
.
session
,
'publisher'
)
changed
|=
modify_database_object
([
publisher
],
book
.
publishers
,
db
.
Publishers
,
calibre_db
.
session
,
'publisher'
)
elif
len
(
book
.
publishers
):
elif
len
(
book
.
publishers
):
changed
|=
modify_database_object
([],
book
.
publishers
,
db
.
Publishers
,
calibre_db
.
session
,
'publisher'
)
changed
|=
modify_database_object
([],
book
.
publishers
,
db
.
Publishers
,
calibre_db
.
session
,
'publisher'
)
return
changed
return
changed
...
...
cps/helper.py
View file @
cf35c9dc
...
@@ -237,22 +237,22 @@ def get_valid_filename(value, replace_whitespace=True):
...
@@ -237,22 +237,22 @@ def get_valid_filename(value, replace_whitespace=True):
value
=
value
[:
-
1
]
+
u'_'
value
=
value
[:
-
1
]
+
u'_'
value
=
value
.
replace
(
"/"
,
"_"
)
.
replace
(
":"
,
"_"
)
.
strip
(
'
\0
'
)
value
=
value
.
replace
(
"/"
,
"_"
)
.
replace
(
":"
,
"_"
)
.
strip
(
'
\0
'
)
if
use_unidecode
:
if
use_unidecode
:
value
=
(
unidecode
.
unidecode
(
value
))
.
strip
()
value
=
(
unidecode
.
unidecode
(
value
))
else
:
else
:
value
=
value
.
replace
(
u'§'
,
u'SS'
)
value
=
value
.
replace
(
u'§'
,
u'SS'
)
value
=
value
.
replace
(
u'ß'
,
u'ss'
)
value
=
value
.
replace
(
u'ß'
,
u'ss'
)
value
=
unicodedata
.
normalize
(
'NFKD'
,
value
)
value
=
unicodedata
.
normalize
(
'NFKD'
,
value
)
re_slugify
=
re
.
compile
(
r'[\W\s-]'
,
re
.
UNICODE
)
re_slugify
=
re
.
compile
(
r'[\W\s-]'
,
re
.
UNICODE
)
if
isinstance
(
value
,
str
):
# Python3 str, Python2 unicode
if
isinstance
(
value
,
str
):
# Python3 str, Python2 unicode
value
=
re_slugify
.
sub
(
''
,
value
)
.
strip
()
value
=
re_slugify
.
sub
(
''
,
value
)
else
:
else
:
value
=
unicode
(
re_slugify
.
sub
(
''
,
value
)
.
strip
()
)
value
=
unicode
(
re_slugify
.
sub
(
''
,
value
))
if
replace_whitespace
:
if
replace_whitespace
:
# *+:\"/<>? are replaced by _
# *+:\"/<>? are replaced by _
value
=
re
.
sub
(
r'[
\*\+:\\\"/<>\
?]+'
,
u'_'
,
value
,
flags
=
re
.
U
)
value
=
re
.
sub
(
r'[
*+:\\\"/<>
?]+'
,
u'_'
,
value
,
flags
=
re
.
U
)
# pipe has to be replaced with comma
# pipe has to be replaced with comma
value
=
re
.
sub
(
r'[
\
|]+'
,
u','
,
value
,
flags
=
re
.
U
)
value
=
re
.
sub
(
r'[|]+'
,
u','
,
value
,
flags
=
re
.
U
)
value
=
value
[:
128
]
value
=
value
[:
128
]
.
strip
()
if
not
value
:
if
not
value
:
raise
ValueError
(
"Filename cannot be empty"
)
raise
ValueError
(
"Filename cannot be empty"
)
if
sys
.
version_info
.
major
==
3
:
if
sys
.
version_info
.
major
==
3
:
...
@@ -269,11 +269,11 @@ def split_authors(values):
...
@@ -269,11 +269,11 @@ def split_authors(values):
commas
=
author
.
count
(
','
)
commas
=
author
.
count
(
','
)
if
commas
==
1
:
if
commas
==
1
:
author_split
=
author
.
split
(
','
)
author_split
=
author
.
split
(
','
)
authors_list
.
append
(
author_split
[
1
]
+
' '
+
author_split
[
0
]
)
authors_list
.
append
(
author_split
[
1
]
.
strip
()
+
' '
+
author_split
[
0
]
.
strip
()
)
elif
commas
>
1
:
elif
commas
>
1
:
authors_list
.
append
(
author
.
split
(
','
)
)
authors_list
.
extend
([
x
.
strip
()
for
x
in
author
.
split
(
','
)]
)
else
:
else
:
authors_list
.
append
(
author
)
authors_list
.
append
(
author
.
strip
()
)
return
authors_list
return
authors_list
...
@@ -284,7 +284,10 @@ def get_sorted_author(value):
...
@@ -284,7 +284,10 @@ def get_sorted_author(value):
combined
=
"("
+
")|("
.
join
(
regexes
)
+
")"
combined
=
"("
+
")|("
.
join
(
regexes
)
+
")"
value
=
value
.
split
(
" "
)
value
=
value
.
split
(
" "
)
if
re
.
match
(
combined
,
value
[
-
1
]
.
upper
()):
if
re
.
match
(
combined
,
value
[
-
1
]
.
upper
()):
value2
=
value
[
-
2
]
+
", "
+
" "
.
join
(
value
[:
-
2
])
+
" "
+
value
[
-
1
]
if
len
(
value
)
>
1
:
value2
=
value
[
-
2
]
+
", "
+
" "
.
join
(
value
[:
-
2
])
+
" "
+
value
[
-
1
]
else
:
value2
=
value
[
0
]
elif
len
(
value
)
==
1
:
elif
len
(
value
)
==
1
:
value2
=
value
[
0
]
value2
=
value
[
0
]
else
:
else
:
...
@@ -293,7 +296,10 @@ def get_sorted_author(value):
...
@@ -293,7 +296,10 @@ def get_sorted_author(value):
value2
=
value
value2
=
value
except
Exception
as
ex
:
except
Exception
as
ex
:
log
.
error
(
"Sorting author
%
s failed:
%
s"
,
value
,
ex
)
log
.
error
(
"Sorting author
%
s failed:
%
s"
,
value
,
ex
)
value2
=
value
if
isinstance
(
list
,
value2
):
value2
=
value
[
0
]
else
:
value2
=
value
return
value2
return
value2
...
...
cps/uploader.py
View file @
cf35c9dc
...
@@ -24,6 +24,7 @@ from flask_babel import gettext as _
...
@@ -24,6 +24,7 @@ from flask_babel import gettext as _
from
.
import
logger
,
comic
from
.
import
logger
,
comic
from
.constants
import
BookMeta
from
.constants
import
BookMeta
from
.helper
import
split_authors
log
=
logger
.
create
()
log
=
logger
.
create
()
...
@@ -131,7 +132,7 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
...
@@ -131,7 +132,7 @@ def pdf_meta(tmp_file_path, original_file_name, original_file_extension):
file_path
=
tmp_file_path
,
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
extension
=
original_file_extension
,
title
=
title
,
title
=
title
,
author
=
author
,
author
=
' & '
.
join
(
split_authors
([
author
]))
,
cover
=
pdf_preview
(
tmp_file_path
,
original_file_name
),
cover
=
pdf_preview
(
tmp_file_path
,
original_file_name
),
description
=
subject
,
description
=
subject
,
tags
=
""
,
tags
=
""
,
...
...
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