mirror of
https://github.com/ciromattia/kcc
synced 2026-05-31 11:43:14 +00:00
Added cover upload
This commit is contained in:
+15
-7
@@ -53,6 +53,7 @@ from . import cbxarchive
|
|||||||
from . import pdfjpgextract
|
from . import pdfjpgextract
|
||||||
from . import dualmetafix
|
from . import dualmetafix
|
||||||
from . import metadata
|
from . import metadata
|
||||||
|
from . import kindle
|
||||||
from . import __version__
|
from . import __version__
|
||||||
|
|
||||||
|
|
||||||
@@ -197,7 +198,6 @@ def buildHTML(path, imgfile, imgfilepath):
|
|||||||
|
|
||||||
|
|
||||||
def buildNCX(dstdir, title, chapters, chapterNames):
|
def buildNCX(dstdir, title, chapters, chapterNames):
|
||||||
options.uuid = str(uuid4())
|
|
||||||
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
|
ncxfile = os.path.join(dstdir, 'OEBPS', 'toc.ncx')
|
||||||
f = open(ncxfile, "w", encoding='UTF-8')
|
f = open(ncxfile, "w", encoding='UTF-8')
|
||||||
f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
|
f.writelines(["<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
|
||||||
@@ -465,7 +465,8 @@ def buildEPUB(path, chapterNames, tomeNumber):
|
|||||||
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, options, tomeNumber)
|
options.covers.append((image.Cover(os.path.join(filelist[-1][0], filelist[-1][1]), cover, options,
|
||||||
|
tomeNumber), options.uuid))
|
||||||
# Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks
|
# Overwrite chapternames if tree is flat and ComicInfo.xml has bookmarks
|
||||||
if not chapterNames and options.chapters:
|
if not chapterNames and options.chapters:
|
||||||
chapterlist = []
|
chapterlist = []
|
||||||
@@ -678,7 +679,7 @@ def getCoversFromMCB(mangaID):
|
|||||||
try:
|
try:
|
||||||
jsonRaw = urlopen(Request('http://mcd.iosphe.re/api/v1/series/' + mangaID + '/',
|
jsonRaw = urlopen(Request('http://mcd.iosphe.re/api/v1/series/' + mangaID + '/',
|
||||||
headers={'User-Agent': 'KindleComicConverter/' + __version__}))
|
headers={'User-Agent': 'KindleComicConverter/' + __version__}))
|
||||||
jsonData = loads(jsonRaw.readall().decode('utf-8'))
|
jsonData = loads(jsonRaw.read().decode('utf-8'))
|
||||||
for volume in jsonData['Covers']['a']:
|
for volume in jsonData['Covers']['a']:
|
||||||
if volume['Side'] == 'front':
|
if volume['Side'] == 'front':
|
||||||
covers[int(volume['Volume'])] = volume['Raw']
|
covers[int(volume['Volume'])] = volume['Raw']
|
||||||
@@ -1141,7 +1142,9 @@ def makeBook(source, qtGUI=None):
|
|||||||
GUI.progressBarTick.emit(str(len(tomes) + 1))
|
GUI.progressBarTick.emit(str(len(tomes) + 1))
|
||||||
GUI.progressBarTick.emit('tick')
|
GUI.progressBarTick.emit('tick')
|
||||||
options.baseTitle = options.title
|
options.baseTitle = options.title
|
||||||
|
options.covers = []
|
||||||
for tome in tomes:
|
for tome in tomes:
|
||||||
|
options.uuid = str(uuid4())
|
||||||
if len(tomes) > 9:
|
if len(tomes) > 9:
|
||||||
tomeNumber += 1
|
tomeNumber += 1
|
||||||
options.title = options.baseTitle + ' [' + str(tomeNumber).zfill(2) + '/' + str(len(tomes)).zfill(2) + ']'
|
options.title = options.baseTitle + ' [' + str(tomeNumber).zfill(2) + '/' + str(len(tomes)).zfill(2) + ']'
|
||||||
@@ -1168,8 +1171,9 @@ def makeBook(source, qtGUI=None):
|
|||||||
if GUI:
|
if GUI:
|
||||||
GUI.progressBarTick.emit('tick')
|
GUI.progressBarTick.emit('tick')
|
||||||
if not GUI and options.format == 'MOBI':
|
if not GUI and options.format == 'MOBI':
|
||||||
print("Creating MOBI file...")
|
print("Creating MOBI files...")
|
||||||
work = []
|
work = []
|
||||||
|
k = kindle.Kindle()
|
||||||
for i in filepath:
|
for i in filepath:
|
||||||
work.append([i])
|
work.append([i])
|
||||||
output = makeMOBI(work, GUI)
|
output = makeMOBI(work, GUI)
|
||||||
@@ -1178,22 +1182,26 @@ def makeBook(source, qtGUI=None):
|
|||||||
print('Error: KindleGen failed to create MOBI!')
|
print('Error: KindleGen failed to create MOBI!')
|
||||||
print(errors)
|
print(errors)
|
||||||
return filepath
|
return filepath
|
||||||
|
if k.path and k.coverSupport:
|
||||||
|
print("Kindle detected. Uploading covers...")
|
||||||
for i in filepath:
|
for i in filepath:
|
||||||
output = makeMOBIFix(i)
|
output = makeMOBIFix(i, options.covers[filepath.index(i)][1])
|
||||||
if not output[0]:
|
if not output[0]:
|
||||||
print('Error: Failed to tweak KindleGen output!')
|
print('Error: Failed to tweak KindleGen output!')
|
||||||
return filepath
|
return filepath
|
||||||
else:
|
else:
|
||||||
os.remove(i.replace('.epub', '.mobi') + '_toclean')
|
os.remove(i.replace('.epub', '.mobi') + '_toclean')
|
||||||
|
if k.path and k.coverSupport:
|
||||||
|
options.covers[filepath.index(i)][0].saveToKindle(k, options.covers[filepath.index(i)][1])
|
||||||
return filepath
|
return filepath
|
||||||
|
|
||||||
|
|
||||||
def makeMOBIFix(item):
|
def makeMOBIFix(item, uuid):
|
||||||
os.remove(item)
|
os.remove(item)
|
||||||
mobiPath = item.replace('.epub', '.mobi')
|
mobiPath = item.replace('.epub', '.mobi')
|
||||||
move(mobiPath, mobiPath + '_toclean')
|
move(mobiPath, mobiPath + '_toclean')
|
||||||
try:
|
try:
|
||||||
dualmetafix.DualMobiMetaFix(mobiPath + '_toclean', mobiPath, bytes(options.uuid, 'UTF-8'))
|
dualmetafix.DualMobiMetaFix(mobiPath + '_toclean', mobiPath, bytes(uuid, 'UTF-8'))
|
||||||
return [True]
|
return [True]
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
return [False, format(err)]
|
return [False, format(err)]
|
||||||
|
|||||||
@@ -453,3 +453,11 @@ class Cover:
|
|||||||
self.image.save(self.target, "JPEG", optimize=1, quality=80)
|
self.image.save(self.target, "JPEG", optimize=1, quality=80)
|
||||||
except IOError:
|
except IOError:
|
||||||
raise RuntimeError('Failed to process downloaded cover.')
|
raise RuntimeError('Failed to process downloaded cover.')
|
||||||
|
|
||||||
|
def saveToKindle(self, kindle, asin):
|
||||||
|
self.image = self.image.resize((300, 470), Image.ANTIALIAS).convert('L')
|
||||||
|
try:
|
||||||
|
self.image.save(os.path.join(kindle.path.split('documents')[0], 'system', 'thumbnails',
|
||||||
|
'thumbnail_' + asin + '_EBOK_portrait.jpg'), 'JPEG')
|
||||||
|
except IOError:
|
||||||
|
raise RuntimeError('Failed to upload cover.')
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013-2015 Pawel Jastrzebski <pawelj@iosphe.re>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and/or distribute this software for
|
||||||
|
# any purpose with or without fee is hereby granted, provided that the
|
||||||
|
# above copyright notice and this permission notice appear in all
|
||||||
|
# copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
||||||
|
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
||||||
|
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
||||||
|
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
|
||||||
|
# OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
|
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
# PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
import os.path
|
||||||
|
import psutil
|
||||||
|
|
||||||
|
|
||||||
|
class Kindle:
|
||||||
|
def __init__(self):
|
||||||
|
self.path = self.findDevice()
|
||||||
|
if self.path:
|
||||||
|
self.coverSupport = self.checkThumbnails()
|
||||||
|
else:
|
||||||
|
self.coverSupport = False
|
||||||
|
|
||||||
|
def findDevice(self):
|
||||||
|
for drive in psutil.disk_partitions(False):
|
||||||
|
if 'removable' in drive[3] or 'vfat' in drive[2] or 'msdos' in drive[2]:
|
||||||
|
if os.path.isdir(os.path.join(drive[1], 'system')) and \
|
||||||
|
os.path.isdir(os.path.join(drive[1], 'documents')):
|
||||||
|
return drive[1]
|
||||||
|
return False
|
||||||
|
|
||||||
|
def checkThumbnails(self):
|
||||||
|
if os.path.isdir(os.path.join(self.path, 'system', 'thumbnails')):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
Reference in New Issue
Block a user