mirror of
https://github.com/ciromattia/kcc
synced 2026-05-30 03:03:21 +00:00
Added Manga Cover Database support
This commit is contained in:
committed by
Paweł Jastrzębski
parent
39fbbc42b3
commit
623f615dd9
+25
-4
@@ -25,7 +25,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from re import split, sub
|
from json import loads
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
|
from re import split, sub, compile
|
||||||
from stat import S_IWRITE, S_IREAD, S_IEXEC
|
from stat import S_IWRITE, S_IREAD, S_IEXEC
|
||||||
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
|
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
@@ -288,7 +290,7 @@ def buildOPF(dstdir, title, filelist, cover=None):
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def buildEPUB(path, chapterNames):
|
def buildEPUB(path, chapterNames, tomeNumber):
|
||||||
filelist = []
|
filelist = []
|
||||||
chapterlist = []
|
chapterlist = []
|
||||||
cover = None
|
cover = None
|
||||||
@@ -416,7 +418,7 @@ def buildEPUB(path, chapterNames):
|
|||||||
if cover is None:
|
if cover is None:
|
||||||
cover = os.path.join(os.path.join(path, 'OEBPS', 'Images'),
|
cover = os.path.join(os.path.join(path, 'OEBPS', 'Images'),
|
||||||
'cover' + getImageFileName(filelist[-1][1])[1])
|
'cover' + getImageFileName(filelist[-1][1])[1])
|
||||||
image.Cover(os.path.join(filelist[-1][0], filelist[-1][1]), cover)
|
image.Cover(os.path.join(filelist[-1][0], filelist[-1][1]), cover, options, tomeNumber)
|
||||||
buildNCX(path, options.title, chapterlist, chapterNames)
|
buildNCX(path, options.title, chapterlist, chapterNames)
|
||||||
# Ensure we're sorting files alphabetically
|
# Ensure we're sorting files alphabetically
|
||||||
convert = lambda text: int(text) if text.isdigit() else text
|
convert = lambda text: int(text) if text.isdigit() else text
|
||||||
@@ -621,6 +623,7 @@ def getOutputFilename(srcpath, wantedname, ext, tomeNumber):
|
|||||||
def getComicInfo(path, originalPath):
|
def getComicInfo(path, originalPath):
|
||||||
xmlPath = os.path.join(path, 'ComicInfo.xml')
|
xmlPath = os.path.join(path, 'ComicInfo.xml')
|
||||||
options.authors = ['KCC']
|
options.authors = ['KCC']
|
||||||
|
options.remoteCovers = {}
|
||||||
titleSuffix = ''
|
titleSuffix = ''
|
||||||
if options.title == 'defaulttitle':
|
if options.title == 'defaulttitle':
|
||||||
defaultTitle = True
|
defaultTitle = True
|
||||||
@@ -666,9 +669,27 @@ def getComicInfo(path, originalPath):
|
|||||||
options.authors.sort()
|
options.authors.sort()
|
||||||
else:
|
else:
|
||||||
options.authors = ['KCC']
|
options.authors = ['KCC']
|
||||||
|
if len(xml.getElementsByTagName('ScanInformation')) != 0:
|
||||||
|
coverId = xml.getElementsByTagName('ScanInformation')[0].firstChild.nodeValue
|
||||||
|
coverId = compile('(MCD\\()(\\d+)(\\))').search(coverId)
|
||||||
|
if coverId:
|
||||||
|
options.remoteCovers = getCoversFromMCB(coverId.group(2))
|
||||||
os.remove(xmlPath)
|
os.remove(xmlPath)
|
||||||
|
|
||||||
|
|
||||||
|
def getCoversFromMCB(mangaID):
|
||||||
|
covers = {}
|
||||||
|
try:
|
||||||
|
jsonRaw = urlopen(Request('http://manga.joentjuh.nl/json/series/' + mangaID + '/',
|
||||||
|
headers={'User-Agent': 'KindleComicConverter/' + __version__}))
|
||||||
|
jsonData = loads(jsonRaw.readall().decode('utf-8'))
|
||||||
|
for volume in jsonData['volumes']:
|
||||||
|
covers[int(volume['volume'])] = volume['releases'][0]['files']['front']['url']
|
||||||
|
except Exception:
|
||||||
|
return {}
|
||||||
|
return covers
|
||||||
|
|
||||||
|
|
||||||
def getDirectorySize(start_path='.'):
|
def getDirectorySize(start_path='.'):
|
||||||
total_size = 0
|
total_size = 0
|
||||||
for dirpath, dirnames, filenames in os.walk(start_path):
|
for dirpath, dirnames, filenames in os.walk(start_path):
|
||||||
@@ -1084,7 +1105,7 @@ def makeBook(source, qtGUI=None):
|
|||||||
makeZIP(tome + '_comic', os.path.join(tome, "OEBPS", "Images"))
|
makeZIP(tome + '_comic', os.path.join(tome, "OEBPS", "Images"))
|
||||||
else:
|
else:
|
||||||
print("\nCreating EPUB structure...")
|
print("\nCreating EPUB structure...")
|
||||||
buildEPUB(tome, chapterNames)
|
buildEPUB(tome, chapterNames, tomeNumber)
|
||||||
# actually zip the ePub
|
# actually zip the ePub
|
||||||
if len(tomes) > 1:
|
if len(tomes) > 1:
|
||||||
filepath.append(getOutputFilename(source, options.output, '.epub', ' ' + str(tomeNumber)))
|
filepath.append(getOutputFilename(source, options.output, '.epub', ' ' + str(tomeNumber)))
|
||||||
|
|||||||
+35
-8
@@ -16,11 +16,14 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
__version__ = '4.1'
|
||||||
__license__ = 'ISC'
|
__license__ = 'ISC'
|
||||||
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
|
__copyright__ = '2012-2014, Ciro Mattia Gonano <ciromattia@gmail.com>, Pawel Jastrzebski <pawelj@iosphe.re>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from io import BytesIO
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from PIL import Image, ImageOps, ImageStat, ImageChops
|
from PIL import Image, ImageOps, ImageStat, ImageChops
|
||||||
from .shared import md5Checksum
|
from .shared import md5Checksum
|
||||||
@@ -472,14 +475,37 @@ class ComicPage:
|
|||||||
|
|
||||||
|
|
||||||
class Cover:
|
class Cover:
|
||||||
def __init__(self, source, target):
|
def __init__(self, source, target, opt, tomeNumber):
|
||||||
|
self.options = opt
|
||||||
self.source = source
|
self.source = source
|
||||||
self.target = target
|
self.target = target
|
||||||
self.image = Image.open(source)
|
if tomeNumber == 0:
|
||||||
|
self.tomeNumber = 1
|
||||||
|
else:
|
||||||
|
self.tomeNumber = tomeNumber
|
||||||
|
if self.tomeNumber in self.options.remoteCovers:
|
||||||
|
try:
|
||||||
|
source = urlopen(Request(self.options.remoteCovers[self.tomeNumber],
|
||||||
|
headers={'User-Agent': 'KindleComicConverter/' + __version__})).read()
|
||||||
|
self.image = Image.open(BytesIO(source))
|
||||||
|
self.processExternal()
|
||||||
|
except Exception:
|
||||||
|
self.image = Image.open(source)
|
||||||
|
self.processInternal()
|
||||||
|
else:
|
||||||
|
self.image = Image.open(source)
|
||||||
|
self.processInternal()
|
||||||
|
|
||||||
|
def processInternal(self):
|
||||||
self.image = self.image.convert('RGB')
|
self.image = self.image.convert('RGB')
|
||||||
self.process()
|
self.image = self.trim()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def processExternal(self):
|
||||||
|
self.image = self.image.convert('RGB')
|
||||||
|
self.image.thumbnail(self.options.profileData[1], Image.ANTIALIAS)
|
||||||
|
self.save(True)
|
||||||
|
|
||||||
def trim(self):
|
def trim(self):
|
||||||
bg = Image.new(self.image.mode, self.image.size, self.image.getpixel((0, 0)))
|
bg = Image.new(self.image.mode, self.image.size, self.image.getpixel((0, 0)))
|
||||||
diff = ImageChops.difference(self.image, bg)
|
diff = ImageChops.difference(self.image, bg)
|
||||||
@@ -490,12 +516,13 @@ class Cover:
|
|||||||
else:
|
else:
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
def process(self):
|
def save(self, external=False):
|
||||||
self.image = self.trim()
|
if external:
|
||||||
|
source = self.options.remoteCovers[self.tomeNumber].split('/')[-1]
|
||||||
def save(self):
|
else:
|
||||||
|
source = self.source
|
||||||
try:
|
try:
|
||||||
if os.path.splitext(self.source)[1].lower() == '.png':
|
if os.path.splitext(source)[1].lower() == '.png':
|
||||||
self.image.save(self.target, "PNG", optimize=1)
|
self.image.save(self.target, "PNG", optimize=1)
|
||||||
else:
|
else:
|
||||||
self.image.save(self.target, "JPEG", optimize=1)
|
self.image.save(self.target, "JPEG", optimize=1)
|
||||||
|
|||||||
Reference in New Issue
Block a user