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
40c6ef3a
Commit
40c6ef3a
authored
Feb 24, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More generic aproach for postion of epub coverfile (#122)
parent
41a20fe3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
24 deletions
+14
-24
epub.py
cps/epub.py
+14
-7
book_edit.html
cps/templates/book_edit.html
+0
-17
No files found.
cps/epub.py
View file @
40c6ef3a
...
...
@@ -7,13 +7,14 @@ import os
import
uploader
def
extractCover
(
zip
,
coverFile
,
tmp_file_name
):
def
extractCover
(
zip
,
coverFile
,
coverpath
,
tmp_file_name
):
if
coverFile
is
None
:
return
None
else
:
cf
=
zip
.
read
(
"OPS/"
+
coverFile
)
zipCoverPath
=
os
.
path
.
join
(
coverpath
,
coverFile
)
.
replace
(
'
\\
'
,
'/'
)
cf
=
zip
.
read
(
zipCoverPath
)
prefix
=
os
.
path
.
splitext
(
tmp_file_name
)[
0
]
tmp_cover_name
=
prefix
+
"."
+
coverFile
tmp_cover_name
=
prefix
+
'.'
+
os
.
path
.
basename
(
zipCoverPath
)
image
=
open
(
tmp_cover_name
,
'wb'
)
image
.
write
(
cf
)
image
.
close
()
...
...
@@ -32,10 +33,11 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
txt
=
zip
.
read
(
'META-INF/container.xml'
)
tree
=
etree
.
fromstring
(
txt
)
cfname
=
tree
.
xpath
(
'n:rootfiles/n:rootfile/@full-path'
,
namespaces
=
ns
)[
0
]
cf
=
zip
.
read
(
cfname
)
tree
=
etree
.
fromstring
(
cf
)
coverpath
=
os
.
path
.
dirname
(
cfname
)
p
=
tree
.
xpath
(
'/pkg:package/pkg:metadata'
,
namespaces
=
ns
)[
0
]
epub_metadata
=
{}
...
...
@@ -46,11 +48,16 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
else
:
epub_metadata
[
s
]
=
"Unknown"
coversection
=
tree
.
xpath
(
"/pkg:package/pkg:manifest/pkg:item[@id='cover']/@href"
,
namespaces
=
ns
)
coversection
=
tree
.
xpath
(
"/pkg:package/pkg:manifest/pkg:item[@id='cover
-image
']/@href"
,
namespaces
=
ns
)
if
len
(
coversection
)
>
0
:
coverfile
=
extractCover
(
zip
,
coversection
[
0
],
tmp_file_path
)
coverfile
=
extractCover
(
zip
,
coversection
[
0
],
coverpath
,
tmp_file_path
)
else
:
coverfile
=
None
coversection
=
tree
.
xpath
(
"/pkg:package/pkg:manifest/pkg:item[@id='cover']/@href"
,
namespaces
=
ns
)
if
len
(
coversection
)
>
0
:
coverfile
=
extractCover
(
zip
,
coversection
[
0
],
coverpath
,
tmp_file_path
)
else
:
coverfile
=
None
if
epub_metadata
[
'title'
]
is
None
:
title
=
original_file_name
else
:
...
...
cps/templates/book_edit.html
View file @
40c6ef3a
...
...
@@ -109,28 +109,11 @@
</form>
</div>
{% endif %}
<div
class=
"modal fade"
id=
"metaModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"metaModalLabel"
>
<div
class=
"modal-dialog"
role=
"document"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
<h4
class=
"modal-title"
id=
"metaModalLabel"
>
{{_('Get meta data')}}
</h4>
</div>
<div
class=
"modal-body"
id=
"meta-info"
>
{{_("Loading...")}}
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
{{_('Close')}}
</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js %}
<script
src=
"{{ url_for('static', filename='js/libs/typeahead.bundle.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/edit_books.js') }}"
></script>
<script
src=
"{{ url_for('static', filename='js/douban_meta.js') }}"
></script>
{% endblock %}
{% block header %}
<link
href=
"{{ url_for('static', filename='css/libs/typeahead.css') }}"
rel=
"stylesheet"
media=
"screen"
>
...
...
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