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
38a255e0
Commit
38a255e0
authored
Aug 18, 2019
by
Vincent Kriek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add automatic epub to kepub conversion using kepubify
parent
ff41775d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
4 deletions
+40
-4
admin.py
cps/admin.py
+4
-0
config_sql.py
cps/config_sql.py
+4
-0
helper.py
cps/helper.py
+15
-3
config_edit.html
cps/templates/config_edit.html
+12
-0
web.py
cps/web.py
+5
-1
No files found.
cps/admin.py
View file @
38a255e0
...
...
@@ -303,6 +303,10 @@ def _configuration_update_helper():
_config_string
(
"config_calibre"
)
_config_string
(
"config_converterpath"
)
_config_checkbox_int
(
"config_automatic_kepub"
)
_config_string
(
"config_kepubify_path"
)
_config_string
(
"config_kepub_cache_dir"
)
if
_config_int
(
"config_login_type"
):
reboot_required
|=
config
.
config_login_type
!=
constants
.
LOGIN_STANDARD
...
...
cps/config_sql.py
View file @
38a255e0
...
...
@@ -104,6 +104,10 @@ class _Settings(_Base):
config_calibre
=
Column
(
String
)
config_rarfile_location
=
Column
(
String
)
config_automatic_kepub
=
Column
(
Boolean
,
default
=
False
)
config_kepubify_path
=
Column
(
String
)
config_kepub_cache_dir
=
Column
(
String
)
config_updatechannel
=
Column
(
Integer
,
default
=
constants
.
UPDATE_STABLE
)
def
__repr__
(
self
):
...
...
cps/helper.py
View file @
38a255e0
...
...
@@ -523,7 +523,7 @@ def save_cover(img, book_path):
def
do_download_file
(
book
,
book_format
,
data
,
headers
):
def
do_download_file
(
book
,
book_format
,
client
,
data
,
headers
):
if
config
.
config_use_google_drive
:
startTime
=
time
.
time
()
df
=
gd
.
getFileFromEbooksFolder
(
book
.
path
,
data
.
name
+
"."
+
book_format
)
...
...
@@ -537,7 +537,18 @@ def do_download_file(book, book_format, data, headers):
if
not
os
.
path
.
isfile
(
os
.
path
.
join
(
filename
,
data
.
name
+
"."
+
book_format
)):
# ToDo: improve error handling
log
.
error
(
'File not found:
%
s'
,
os
.
path
.
join
(
filename
,
data
.
name
+
"."
+
book_format
))
if
client
==
"kobo"
and
book_format
==
"epub"
:
filename
=
config
.
config_kepub_cache_dir
os
.
system
(
'{0} "{1}" -o {2}'
.
format
(
config
.
config_kepubify_path
,
os
.
path
.
join
(
filename
,
data
.
name
+
"."
+
book_format
),
filename
))
book_format
=
"kepub.epub"
headers
[
"Content-Disposition"
]
=
headers
[
"Content-Disposition"
]
.
replace
(
".epub"
,
".kepub.epub"
)
response
=
make_response
(
send_from_directory
(
filename
,
data
.
name
+
"."
+
book_format
))
response
.
headers
=
headers
return
response
...
...
@@ -756,7 +767,7 @@ def get_cc_columns():
cc
=
tmpcc
return
cc
def
get_download_link
(
book_id
,
book_format
):
def
get_download_link
(
book_id
,
book_format
,
client
):
book_format
=
book_format
.
split
(
"."
)[
0
]
book
=
db
.
session
.
query
(
db
.
Books
)
.
filter
(
db
.
Books
.
id
==
book_id
)
.
filter
(
common_filters
())
.
first
()
if
book
:
...
...
@@ -776,7 +787,8 @@ def get_download_link(book_id, book_format):
headers
[
"Content-Type"
]
=
mimetypes
.
types_map
.
get
(
'.'
+
book_format
,
"application/octet-stream"
)
headers
[
"Content-Disposition"
]
=
"attachment; filename*=UTF-8''
%
s.
%
s"
%
(
quote
(
file_name
.
encode
(
'utf-8'
)),
book_format
)
return
do_download_file
(
book
,
book_format
,
data
,
headers
)
return
do_download_file
(
book
,
book_format
,
client
,
data
,
headers
)
else
:
abort
(
404
)
...
...
cps/templates/config_edit.html
View file @
38a255e0
...
...
@@ -309,6 +309,18 @@
<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"
>
</div>
{% endif %}
<div
class=
"form-group"
>
<input
type=
"checkbox"
id=
"config_automatic_kepub"
name=
"config_automatic_kepub"
{%
if
config
.
config_automatic_kepub
%}
checked
{%
endif
%}
>
<label
for=
"config_uploading"
>
{{_('Enable automatic kobo epub conversion')}}
</label>
</div>
<div
class=
"form-group"
>
<label
for=
"config_kepubify_path"
>
{{_('Path to kepubify')}}
</label>
<input
type=
"text"
class=
"form-control"
id=
"config_kepubify_path"
name=
"config_kepubify_path"
value=
"{% if config.config_kepubify_path != None %}{{ config.config_kepubify_path }}{% endif %}"
autocomplete=
"off"
>
</div>
<div
class=
"form-group"
>
<label
for=
"config_kepub_cache_dir"
>
{{_('Path to kepubify')}}
</label>
<input
type=
"text"
class=
"form-control"
id=
"config_kepub_cache_dir"
name=
"config_kepub_cache_dir"
value=
"{% if config.config_kepub_cache_dir != None %}{{ config.config_kepub_cache_dir }}{% endif %}"
autocomplete=
"off"
>
</div>
</div>
</div>
</div>
...
...
cps/web.py
View file @
38a255e0
...
...
@@ -1010,7 +1010,11 @@ def serve_book(book_id, book_format):
@
login_required_if_no_ano
@
download_required
def
download_link
(
book_id
,
book_format
,
anyname
):
return
get_download_link
(
book_id
,
book_format
)
if
(
config
.
config_automatic_kepub
and
"Kobo"
in
request
.
headers
.
get
(
'User-Agent'
)):
client
=
"kobo"
return
get_download_link
(
book_id
,
book_format
,
client
)
@
web
.
route
(
'/send/<int:book_id>/<book_format>/<int:convert>'
)
...
...
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