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
bea7223a
Commit
bea7223a
authored
Apr 28, 2020
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renabled cbrimage extraction (via unrar and rarfile)
parent
0297823b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
36 deletions
+58
-36
admin.py
cps/admin.py
+5
-5
comic.py
cps/comic.py
+36
-17
editbooks.py
cps/editbooks.py
+1
-1
helper.py
cps/helper.py
+2
-2
config_edit.html
cps/templates/config_edit.html
+1
-1
uploader.py
cps/uploader.py
+8
-5
web.py
cps/web.py
+5
-5
No files found.
cps/admin.py
View file @
bea7223a
...
@@ -50,11 +50,11 @@ feature_support = {
...
@@ -50,11 +50,11 @@ feature_support = {
'kobo'
:
bool
(
services
.
kobo
)
'kobo'
:
bool
(
services
.
kobo
)
}
}
#
try:
try
:
#
import rarfile
import
rarfile
#
feature_support['rar'] = True
feature_support
[
'rar'
]
=
True
#
except ImportError:
except
ImportError
:
#
feature_support['rar'] = False
feature_support
[
'rar'
]
=
False
try
:
try
:
from
.oauth_bb
import
oauth_check
,
oauthblueprints
from
.oauth_bb
import
oauth_check
,
oauthblueprints
...
...
cps/comic.py
100755 → 100644
View file @
bea7223a
...
@@ -33,10 +33,16 @@ except ImportError as e:
...
@@ -33,10 +33,16 @@ except ImportError as e:
log
.
debug
(
'cannot import comicapi, extracting comic metadata will not work:
%
s'
,
e
)
log
.
debug
(
'cannot import comicapi, extracting comic metadata will not work:
%
s'
,
e
)
import
zipfile
import
zipfile
import
tarfile
import
tarfile
try
:
import
rarfile
use_rarfile
=
True
except
ImportError
as
e
:
log
.
debug
(
'cannot import rarfile, extracting cover files from rar files will not work:
%
s'
,
e
)
use_rarfile
=
False
use_comic_meta
=
False
use_comic_meta
=
False
def
extractCover
(
tmp_file_name
,
original_file_extension
):
def
_extractCover
(
tmp_file_name
,
original_file_extension
,
rarExceutable
):
cover_data
=
extension
=
None
cover_data
=
extension
=
None
if
use_comic_meta
:
if
use_comic_meta
:
archive
=
ComicArchive
(
tmp_file_name
)
archive
=
ComicArchive
(
tmp_file_name
)
...
@@ -66,6 +72,20 @@ def extractCover(tmp_file_name, original_file_extension):
...
@@ -66,6 +72,20 @@ def extractCover(tmp_file_name, original_file_extension):
if
extension
==
'.jpg'
or
extension
==
'.jpeg'
:
if
extension
==
'.jpg'
or
extension
==
'.jpeg'
:
cover_data
=
cf
.
extractfile
(
name
)
.
read
()
cover_data
=
cf
.
extractfile
(
name
)
.
read
()
break
break
elif
original_file_extension
.
upper
()
==
'.CBR'
and
use_rarfile
:
try
:
rarfile
.
UNRAR_TOOL
=
rarExceutable
cf
=
rarfile
.
RarFile
(
tmp_file_name
)
for
name
in
cf
.
getnames
():
ext
=
os
.
path
.
splitext
(
name
)
if
len
(
ext
)
>
1
:
extension
=
ext
[
1
]
.
lower
()
if
extension
==
'.jpg'
or
extension
==
'.jpeg'
:
cover_data
=
cf
.
read
(
name
)
break
except
Exception
as
e
:
log
.
debug
(
'Rarfile failed with error:
%
s'
,
e
)
prefix
=
os
.
path
.
dirname
(
tmp_file_name
)
prefix
=
os
.
path
.
dirname
(
tmp_file_name
)
if
cover_data
:
if
cover_data
:
tmp_cover_name
=
prefix
+
'/cover'
+
extension
tmp_cover_name
=
prefix
+
'/cover'
+
extension
...
@@ -77,9 +97,9 @@ def extractCover(tmp_file_name, original_file_extension):
...
@@ -77,9 +97,9 @@ def extractCover(tmp_file_name, original_file_extension):
return
tmp_cover_name
return
tmp_cover_name
def
get_comic_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
):
def
get_comic_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
,
rarExceutable
):
if
use_comic_meta
:
if
use_comic_meta
:
archive
=
ComicArchive
(
tmp_file_path
)
archive
=
ComicArchive
(
tmp_file_path
,
rar_exe_path
=
rarExceutable
)
if
archive
.
seemsToBeAComicArchive
():
if
archive
.
seemsToBeAComicArchive
():
if
archive
.
hasMetadata
(
MetaDataStyle
.
CIX
):
if
archive
.
hasMetadata
(
MetaDataStyle
.
CIX
):
style
=
MetaDataStyle
.
CIX
style
=
MetaDataStyle
.
CIX
...
@@ -100,27 +120,26 @@ def get_comic_info(tmp_file_path, original_file_name, original_file_extension):
...
@@ -100,27 +120,26 @@ def get_comic_info(tmp_file_path, original_file_name, original_file_extension):
else
:
else
:
loadedMetadata
.
language
=
""
loadedMetadata
.
language
=
""
return
BookMeta
(
return
BookMeta
(
file_path
=
tmp_file_path
,
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
extension
=
original_file_extension
,
title
=
loadedMetadata
.
title
or
original_file_name
,
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
),
cover
=
_extractCover
(
tmp_file_path
,
original_file_extension
,
rarExceutable
),
description
=
loadedMetadata
.
comments
or
""
,
description
=
loadedMetadata
.
comments
or
""
,
tags
=
""
,
tags
=
""
,
series
=
loadedMetadata
.
series
or
""
,
series
=
loadedMetadata
.
series
or
""
,
series_id
=
loadedMetadata
.
issue
or
""
,
series_id
=
loadedMetadata
.
issue
or
""
,
languages
=
loadedMetadata
.
language
)
languages
=
loadedMetadata
.
language
)
else
:
return
BookMeta
(
return
BookMeta
(
file_path
=
tmp_file_path
,
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
extension
=
original_file_extension
,
title
=
original_file_name
,
title
=
original_file_name
,
author
=
u'Unknown'
,
author
=
u'Unknown'
,
cover
=
extractCover
(
tmp_file_path
,
original_file_extension
),
cover
=
_extractCover
(
tmp_file_path
,
original_file_extension
,
rarExceutable
),
description
=
""
,
description
=
""
,
tags
=
""
,
tags
=
""
,
series
=
""
,
series
=
""
,
series_id
=
""
,
series_id
=
""
,
languages
=
""
)
languages
=
""
)
cps/editbooks.py
View file @
bea7223a
...
@@ -588,7 +588,7 @@ def upload():
...
@@ -588,7 +588,7 @@ def upload():
# extract metadata from file
# extract metadata from file
try
:
try
:
meta
=
uploader
.
upload
(
requested_file
)
meta
=
uploader
.
upload
(
requested_file
,
config
.
config_rarfile_location
)
except
(
IOError
,
OSError
):
except
(
IOError
,
OSError
):
log
.
error
(
"File
%
s could not saved to temp dir"
,
requested_file
.
filename
)
log
.
error
(
"File
%
s could not saved to temp dir"
,
requested_file
.
filename
)
flash
(
_
(
u"File
%(filename)
s could not saved to temp dir"
,
flash
(
_
(
u"File
%(filename)
s could not saved to temp dir"
,
...
...
cps/helper.py
View file @
bea7223a
...
@@ -583,7 +583,7 @@ def check_unrar(unrarLocation):
...
@@ -583,7 +583,7 @@ def check_unrar(unrarLocation):
return
return
if
not
os
.
path
.
exists
(
unrarLocation
):
if
not
os
.
path
.
exists
(
unrarLocation
):
return
'Unrar binary file not found'
return
_
(
'Unrar binary file not found'
)
try
:
try
:
if
sys
.
version_info
<
(
3
,
0
):
if
sys
.
version_info
<
(
3
,
0
):
...
@@ -596,7 +596,7 @@ def check_unrar(unrarLocation):
...
@@ -596,7 +596,7 @@ def check_unrar(unrarLocation):
log
.
debug
(
"unrar version
%
s"
,
version
)
log
.
debug
(
"unrar version
%
s"
,
version
)
except
OSError
as
err
:
except
OSError
as
err
:
log
.
exception
(
err
)
log
.
exception
(
err
)
return
'Error excecuting UnRar'
return
_
(
'Error excecuting UnRar'
)
...
...
cps/templates/config_edit.html
View file @
bea7223a
...
@@ -344,7 +344,7 @@
...
@@ -344,7 +344,7 @@
<input
type=
"text"
class=
"form-control"
id=
"config_converterpath"
name=
"config_converterpath"
value=
"{% if config.config_converterpath != None %}{{ config.config_converterpath }}{% endif %}"
autocomplete=
"off"
>
<input
type=
"text"
class=
"form-control"
id=
"config_converterpath"
name=
"config_converterpath"
value=
"{% if config.config_converterpath != None %}{{ config.config_converterpath }}{% endif %}"
autocomplete=
"off"
>
</div>
</div>
</div>
</div>
{% if
rarfile_support
%}
{% if
feature_support['rar']
%}
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"config_rarfile_location"
>
{{_('Location of Unrar binary')}}
</label>
<label
for=
"config_rarfile_location"
>
{{_('Location of Unrar binary')}}
</label>
<input
type=
"text"
class=
"form-control"
name=
"config_rarfile_location"
id=
"config_rarfile_location"
value=
"{% if config.config_rarfile_location != None %}{{ config.config_rarfile_location }}{% endif %}"
autocomplete=
"off"
>
<input
type=
"text"
class=
"form-control"
name=
"config_rarfile_location"
id=
"config_rarfile_location"
value=
"{% if config.config_rarfile_location != None %}{{ config.config_rarfile_location }}{% endif %}"
autocomplete=
"off"
>
...
...
cps/uploader.py
View file @
bea7223a
...
@@ -76,7 +76,7 @@ except ImportError as e:
...
@@ -76,7 +76,7 @@ except ImportError as e:
__author__
=
'lemmsh'
__author__
=
'lemmsh'
def
process
(
tmp_file_path
,
original_file_name
,
original_file_extension
):
def
process
(
tmp_file_path
,
original_file_name
,
original_file_extension
,
rarExcecutable
):
meta
=
None
meta
=
None
try
:
try
:
if
".PDF"
==
original_file_extension
.
upper
():
if
".PDF"
==
original_file_extension
.
upper
():
...
@@ -85,8 +85,11 @@ def process(tmp_file_path, original_file_name, original_file_extension):
...
@@ -85,8 +85,11 @@ def process(tmp_file_path, original_file_name, original_file_extension):
meta
=
epub
.
get_epub_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
)
meta
=
epub
.
get_epub_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
)
if
".FB2"
==
original_file_extension
.
upper
()
and
use_fb2_meta
is
True
:
if
".FB2"
==
original_file_extension
.
upper
()
and
use_fb2_meta
is
True
:
meta
=
fb2
.
get_fb2_info
(
tmp_file_path
,
original_file_extension
)
meta
=
fb2
.
get_fb2_info
(
tmp_file_path
,
original_file_extension
)
if
original_file_extension
.
upper
()
in
[
'.CBZ'
,
'.CBT'
]:
if
original_file_extension
.
upper
()
in
[
'.CBZ'
,
'.CBT'
,
'.CBR'
]:
meta
=
comic
.
get_comic_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
)
meta
=
comic
.
get_comic_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
,
rarExcecutable
)
except
Exception
as
ex
:
except
Exception
as
ex
:
log
.
warning
(
'cannot parse metadata, using default:
%
s'
,
ex
)
log
.
warning
(
'cannot parse metadata, using default:
%
s'
,
ex
)
...
@@ -194,7 +197,7 @@ def get_versions():
...
@@ -194,7 +197,7 @@ def get_versions():
'Comic_API'
:
ComicVersion
}
'Comic_API'
:
ComicVersion
}
def
upload
(
uploadfile
):
def
upload
(
uploadfile
,
rarExcecutable
):
tmp_dir
=
os
.
path
.
join
(
gettempdir
(),
'calibre_web'
)
tmp_dir
=
os
.
path
.
join
(
gettempdir
(),
'calibre_web'
)
if
not
os
.
path
.
isdir
(
tmp_dir
):
if
not
os
.
path
.
isdir
(
tmp_dir
):
...
@@ -206,5 +209,5 @@ def upload(uploadfile):
...
@@ -206,5 +209,5 @@ def upload(uploadfile):
tmp_file_path
=
os
.
path
.
join
(
tmp_dir
,
md5
.
hexdigest
())
tmp_file_path
=
os
.
path
.
join
(
tmp_dir
,
md5
.
hexdigest
())
log
.
debug
(
"Temporary file:
%
s"
,
tmp_file_path
)
log
.
debug
(
"Temporary file:
%
s"
,
tmp_file_path
)
uploadfile
.
save
(
tmp_file_path
)
uploadfile
.
save
(
tmp_file_path
)
meta
=
process
(
tmp_file_path
,
filename_root
,
file_extension
)
meta
=
process
(
tmp_file_path
,
filename_root
,
file_extension
,
rarExcecutable
)
return
meta
return
meta
cps/web.py
View file @
bea7223a
...
@@ -72,11 +72,11 @@ try:
...
@@ -72,11 +72,11 @@ try:
except
ImportError
:
except
ImportError
:
pass
# We're not using Python 3
pass
# We're not using Python 3
#
try:
#try:
#
import rarfile
# import rarfile
#
feature_support['rar'] = True
# feature_support['rar'] = True
#
except ImportError:
#except ImportError:
#
feature_support['rar'] = False
# feature_support['rar'] = False
try
:
try
:
from
natsort
import
natsorted
as
sort
from
natsort
import
natsorted
as
sort
...
...
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