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
319077ae
Commit
319077ae
authored
Dec 02, 2017
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Import covers from comic files during upload
parent
5809acfa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
book_formats.py
cps/book_formats.py
+4
-0
cli.py
cps/cli.py
+3
-0
comic.py
cps/comic.py
+43
-0
No files found.
cps/book_formats.py
View file @
319077ae
...
...
@@ -5,6 +5,7 @@ import logging
import
uploader
import
os
from
flask_babel
import
gettext
as
_
import
comic
__author__
=
'lemmsh'
...
...
@@ -49,6 +50,9 @@ 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
)
if
".FB2"
==
original_file_extension
.
upper
()
and
use_fb2_meta
is
True
:
meta
=
fb2
.
get_fb2_info
(
tmp_file_path
,
original_file_extension
)
if
original_file_extension
.
upper
()
in
[
'.CBZ'
,
'.CBT'
]:
meta
=
comic
.
get_comic_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
)
except
Exception
as
ex
:
logger
.
warning
(
'cannot parse metadata, using default:
%
s'
,
ex
)
...
...
cps/cli.py
View file @
319077ae
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
argparse
import
os
...
...
cps/comic.py
0 → 100644
View file @
319077ae
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
zipfile
import
tarfile
import
os
import
uploader
def
extractCover
(
tmp_file_name
,
original_file_extension
):
if
original_file_extension
.
upper
()
==
'.CBZ'
:
cf
=
zipfile
.
ZipFile
(
tmp_file_name
)
compressed_name
=
cf
.
namelist
()[
0
]
cover_data
=
cf
.
read
(
compressed_name
)
elif
original_file_extension
.
upper
()
==
'.CBT'
:
cf
=
tarfile
.
TarFile
(
tmp_file_name
)
compressed_name
=
cf
.
getnames
()[
0
]
cover_data
=
cf
.
extractfile
(
compressed_name
)
.
read
()
prefix
=
os
.
path
.
dirname
(
tmp_file_name
)
tmp_cover_name
=
prefix
+
'/cover'
+
os
.
path
.
splitext
(
compressed_name
)[
1
]
image
=
open
(
tmp_cover_name
,
'wb'
)
image
.
write
(
cover_data
)
image
.
close
()
return
tmp_cover_name
def
get_comic_info
(
tmp_file_path
,
original_file_name
,
original_file_extension
):
coverfile
=
extractCover
(
tmp_file_path
,
original_file_extension
)
return
uploader
.
BookMeta
(
file_path
=
tmp_file_path
,
extension
=
original_file_extension
,
title
=
original_file_name
,
author
=
u"Unknown"
,
cover
=
coverfile
,
description
=
""
,
tags
=
""
,
series
=
""
,
series_id
=
""
,
languages
=
""
)
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