1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 09:46:25 +00:00
This commit is contained in:
Paweł Jastrzębski
2014-01-15 22:03:48 +01:00
parent cf3df581e1
commit d76a624a82
7 changed files with 76 additions and 75 deletions

4
kcc.py
View File

@@ -120,8 +120,8 @@ class QApplicationMessaging(QtWidgets.QApplication):
# Adding signals to QMainWindow # Adding signals to QMainWindow
class QMainWindowKCC(QtWidgets.QMainWindow): class QMainWindowKCC(QtWidgets.QMainWindow):
progressBarTick = QtCore.pyqtSignal(str, str) progressBarTick = QtCore.pyqtSignal(str)
modeConvert = QtCore.pyqtSignal(str) modeConvert = QtCore.pyqtSignal(bool)
addMessage = QtCore.pyqtSignal(str, str, bool) addMessage = QtCore.pyqtSignal(str, str, bool)
addTrayMessage = QtCore.pyqtSignal(str, str) addTrayMessage = QtCore.pyqtSignal(str, str)
showDialog = QtCore.pyqtSignal(str) showDialog = QtCore.pyqtSignal(str)

View File

@@ -89,7 +89,7 @@ class HTMLStripper(HTMLParser):
class WebServerHandler(BaseHTTPRequestHandler): class WebServerHandler(BaseHTTPRequestHandler):
#noinspection PyAttributeOutsideInit # noinspection PyAttributeOutsideInit, PyArgumentList
def do_GET(self): def do_GET(self):
if self.path == '/': if self.path == '/':
self.path = '/index.html' self.path = '/index.html'
@@ -109,7 +109,7 @@ class WebServerHandler(BaseHTTPRequestHandler):
self.send_response(200) self.send_response(200)
self.send_header('Content-type', 'text/html') self.send_header('Content-type', 'text/html')
self.end_headers() self.end_headers()
self.wfile.write('<!DOCTYPE html>\n' self.wfile.write(bytes('<!DOCTYPE html>\n'
'<html lang="en">\n' '<html lang="en">\n'
'<head><meta charset="utf-8">\n' '<head><meta charset="utf-8">\n'
'<link href="' + GUI.webContent.favicon + '" rel="icon" type="image/x-icon" />\n' '<link href="' + GUI.webContent.favicon + '" rel="icon" type="image/x-icon" />\n'
@@ -118,16 +118,16 @@ class WebServerHandler(BaseHTTPRequestHandler):
'<body>\n' '<body>\n'
'<div style="text-align: center; font-size:25px">\n' '<div style="text-align: center; font-size:25px">\n'
'<p style="font-size:50px">- <img style="vertical-align: middle" ' '<p style="font-size:50px">- <img style="vertical-align: middle" '
'alt="KCC Logo" src="' + GUI.webContent.logo + '" /> -</p>\n') 'alt="KCC Logo" src="' + GUI.webContent.logo + '" /> -</p>\n', 'UTF-8'))
if len(GUI.completedWork) > 0 and not GUI.conversionAlive: if len(GUI.completedWork) > 0 and not GUI.conversionAlive:
for key in sorted(GUI.completedWork.keys()): for key in sorted(GUI.completedWork.keys()):
self.wfile.write('<p><a href="' + key + '">' + key.split('.')[0] + '</a></p>\n') self.wfile.write(bytes('<p><a href="' + key + '">' + key.split('.')[0] + '</a></p>\n', 'UTF-8'))
else: else:
self.wfile.write('<p style="font-weight: bold">No downloads are available.<br/>' self.wfile.write(bytes('<p style="font-weight: bold">No downloads are available.<br/>'
'Convert some files and refresh this page.</p>\n') 'Convert some files and refresh this page.</p>\n', 'UTF-8'))
self.wfile.write('</div>\n' self.wfile.write(bytes('</div>\n'
'</body>\n' '</body>\n'
'</html>\n') '</html>\n', 'UTF-8'))
elif sendReply: elif sendReply:
outputFile = GUI.completedWork[urllib.parse.unquote(self.path[1:])].decode('utf-8') outputFile = GUI.completedWork[urllib.parse.unquote(self.path[1:])].decode('utf-8')
fp = open(outputFile, 'rb') fp = open(outputFile, 'rb')
@@ -314,6 +314,8 @@ class WorkerThread(QtCore.QThread):
# Let's make sure that we don't use too many threads # Let's make sure that we don't use too many threads
if self.threadNumber > QtCore.QThread.idealThreadCount(): if self.threadNumber > QtCore.QThread.idealThreadCount():
self.threadNumber = QtCore.QThread.idealThreadCount() self.threadNumber = QtCore.QThread.idealThreadCount()
self.progressBarTick = MW.progressBarTick
self.addMessage = MW.addMessage
def __del__(self): def __del__(self):
self.wait() self.wait()
@@ -331,7 +333,7 @@ class WorkerThread(QtCore.QThread):
MW.modeConvert.emit(True) MW.modeConvert.emit(True)
def addResult(self, output): def addResult(self, output):
MW.progressBarTick.emit(False, False) MW.progressBarTick.emit('tick')
self.workerOutput.append(output) self.workerOutput.append(output)
def run(self): def run(self):
@@ -433,9 +435,9 @@ class WorkerThread(QtCore.QThread):
else: else:
MW.addMessage.emit('Creating EPUB files... <b>Done!</b>', 'info', True) MW.addMessage.emit('Creating EPUB files... <b>Done!</b>', 'info', True)
if str(GUI.FormatBox.currentText()) == 'MOBI': if str(GUI.FormatBox.currentText()) == 'MOBI':
MW.progressBarTick.emit('status', 'Creating MOBI files') MW.progressBarTick.emit('Creating MOBI files')
MW.progressBarTick.emit(len(outputPath)*2+1, False) MW.progressBarTick.emit(str(len(outputPath)*2+1))
MW.progressBarTick.emit(False, False) MW.progressBarTick.emit('tick')
MW.addMessage.emit('Creating MOBI files', 'info', False) MW.addMessage.emit('Creating MOBI files', 'info', False)
GUI.progress.content = 'Creating MOBI files' GUI.progress.content = 'Creating MOBI files'
self.workerOutput = [] self.workerOutput = []
@@ -463,8 +465,6 @@ class WorkerThread(QtCore.QThread):
if self.kindlegenErrorCode[0] == 0: if self.kindlegenErrorCode[0] == 0:
GUI.progress.content = '' GUI.progress.content = ''
MW.addMessage.emit('Creating MOBI files... <b>Done!</b>', 'info', True) MW.addMessage.emit('Creating MOBI files... <b>Done!</b>', 'info', True)
MW.addMessage.emit('Cleaning MOBI files is currently disabled in this branch', 'info', False)
GUI.progress.content = 'Cleaning MOBI files is currently disabled in this branch'
MW.addMessage.emit('Cleaning MOBI files', 'info', False) MW.addMessage.emit('Cleaning MOBI files', 'info', False)
GUI.progress.content = 'Cleaning MOBI files' GUI.progress.content = 'Cleaning MOBI files'
self.workerOutput = [] self.workerOutput = []
@@ -528,7 +528,7 @@ class WorkerThread(QtCore.QThread):
class SystemTrayIcon(QtWidgets.QSystemTrayIcon): class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
def __init__(self): def __init__(self):
if not sys.platform.startswith('darwin') and self.isSystemTrayAvailable(): if self.isSystemTrayAvailable():
QtWidgets.QSystemTrayIcon.__init__(self, GUI.icons.programIcon, MW) QtWidgets.QSystemTrayIcon.__init__(self, GUI.icons.programIcon, MW)
self.activated.connect(self.catchClicks) self.activated.connect(self.catchClicks)
@@ -538,23 +538,22 @@ class SystemTrayIcon(QtWidgets.QSystemTrayIcon):
MW.activateWindow() MW.activateWindow()
def addTrayMessage(self, message, icon): def addTrayMessage(self, message, icon):
if not sys.platform.startswith('darwin'): icon = eval('QtWidgets.QSystemTrayIcon.' + icon)
icon = eval('QtGui.QSystemTrayIcon.' + icon) if self.supportsMessages() and not MW.isActiveWindow():
if self.supportsMessages() and not MW.isActiveWindow(): self.showMessage('Kindle Comic Converter', message, icon)
self.showMessage('Kindle Comic Converter', message, icon)
class KCCGUI(KCC_ui.Ui_KCC): class KCCGUI(KCC_ui.Ui_KCC):
# TODO: Check dialog
def selectDir(self): def selectDir(self):
if self.needClean: if self.needClean:
self.needClean = False self.needClean = False
GUI.JobList.clear() GUI.JobList.clear()
# Dirty, dirty way but OS native QFileDialogs don't support directory multiselect # Dirty, dirty way but OS native QFileDialogs don't support directory multiselect
dirDialog = QtWidgets.QFileDialog(MW, 'Select directory', self.lastPath) dirDialog = QtWidgets.QFileDialog(MW, 'Select directory', self.lastPath, 'Directory (*.abcdefg)')
dirDialog.setFileMode(dirDialog.Directory) dirDialog.setFileMode(dirDialog.Directory)
dirDialog.setOption(dirDialog.ShowDirsOnly, True) dirDialog.setOption(dirDialog.ShowDirsOnly, True)
dirDialog.setOption(dirDialog.DontUseNativeDialog, True) dirDialog.setOption(dirDialog.DontUseNativeDialog, True)
dirDialog.setOption(dirDialog.HideNameFilterDetails, True)
l = dirDialog.findChild(QtWidgets.QListView, "listView") l = dirDialog.findChild(QtWidgets.QListView, "listView")
t = dirDialog.findChild(QtWidgets.QTreeView) t = dirDialog.findChild(QtWidgets.QTreeView)
if l: if l:
@@ -573,7 +572,6 @@ class KCCGUI(KCC_ui.Ui_KCC):
GUI.JobList.addItem(dname) GUI.JobList.addItem(dname)
MW.setFocus() MW.setFocus()
# TODO: Check dialog
def selectFile(self): def selectFile(self):
if self.needClean: if self.needClean:
self.needClean = False self.needClean = False
@@ -581,20 +579,22 @@ class KCCGUI(KCC_ui.Ui_KCC):
if self.UnRAR: if self.UnRAR:
if self.sevenza: if self.sevenza:
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath, fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf') 'Comic (*.cbz *.cbr *.cb7 *.zip *.rar *.7z *.pdf)')
else: else:
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath, fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.cbr *.zip *.rar *.pdf') 'Comic (*.cbz *.cbr *.zip *.rar *.pdf)')
else: else:
if self.sevenza: if self.sevenza:
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath, fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.cb7 *.zip *.7z *.pdf') 'Comic (*.cbz *.cb7 *.zip *.7z *.pdf)')
else: else:
fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath, fnames = QtWidgets.QFileDialog.getOpenFileNames(MW, 'Select file', self.lastPath,
'*.cbz *.zip *.pdf') 'Comic (*.cbz *.zip *.pdf)')
for fname in fnames: for fname in fnames[0]:
if str(fname) != "": if fname != '':
self.lastPath = os.path.abspath(os.path.join(str(fname), os.pardir)) if sys.platform.startswith('win'):
fname = fname.replace('/', '\\')
self.lastPath = os.path.abspath(os.path.join(fname, os.pardir))
GUI.JobList.addItem(fname) GUI.JobList.addItem(fname)
def clearJobs(self): def clearJobs(self):
@@ -849,8 +849,8 @@ class KCCGUI(KCC_ui.Ui_KCC):
s.feed(html) s.feed(html)
return s.get_data() return s.get_data()
def addMessage(self, message, icon=None, replace=False): def addMessage(self, message, icon, replace=False):
if icon: if icon != '':
icon = eval('self.icons.' + icon) icon = eval('self.icons.' + icon)
item = QtWidgets.QListWidgetItem(icon, ' ' + self.stripTags(message)) item = QtWidgets.QListWidgetItem(icon, ' ' + self.stripTags(message))
else: else:
@@ -873,15 +873,15 @@ class KCCGUI(KCC_ui.Ui_KCC):
def showDialog(self, message): def showDialog(self, message):
QtWidgets.QMessageBox.critical(MW, 'KCC - Error', message, QtWidgets.QMessageBox.Ok) QtWidgets.QMessageBox.critical(MW, 'KCC - Error', message, QtWidgets.QMessageBox.Ok)
def updateProgressbar(self, new=False, status=False): def updateProgressbar(self, command):
if new == "status": if command == 'tick':
GUI.ProgressBar.setFormat(status) GUI.ProgressBar.setValue(GUI.ProgressBar.value() + 1)
elif new: elif command.isdigit():
GUI.ProgressBar.setMaximum(new - 1) GUI.ProgressBar.setMaximum(int(command) - 1)
GUI.ProgressBar.reset() GUI.ProgressBar.reset()
GUI.ProgressBar.show() GUI.ProgressBar.show()
else: else:
GUI.ProgressBar.setValue(GUI.ProgressBar.value() + 1) GUI.ProgressBar.setFormat(command)
def convertStart(self): def convertStart(self):
if self.conversionAlive: if self.conversionAlive:
@@ -923,6 +923,7 @@ class KCCGUI(KCC_ui.Ui_KCC):
if not GUI.ConvertButton.isEnabled(): if not GUI.ConvertButton.isEnabled():
event.ignore() event.ignore()
self.contentServer.stop() self.contentServer.stop()
self.tray.hide()
self.settings.setValue('settingsVersion', __version__) self.settings.setValue('settingsVersion', __version__)
self.settings.setValue('lastPath', self.lastPath) self.settings.setValue('lastPath', self.lastPath)
self.settings.setValue('lastDevice', GUI.DeviceBox.currentIndex()) self.settings.setValue('lastDevice', GUI.DeviceBox.currentIndex())

View File

@@ -375,4 +375,4 @@ class Ui_KCC(object):
self.ActionBasic.setText(_translate("KCC", "Basic")) self.ActionBasic.setText(_translate("KCC", "Basic"))
self.ActionAdvanced.setText(_translate("KCC", "Advanced")) self.ActionAdvanced.setText(_translate("KCC", "Advanced"))
import KCC_rc from . import KCC_rc

View File

@@ -393,4 +393,4 @@ class Ui_KCC(object):
self.ActionBasic.setText(_translate("KCC", "Basic")) self.ActionBasic.setText(_translate("KCC", "Basic"))
self.ActionAdvanced.setText(_translate("KCC", "Advanced")) self.ActionAdvanced.setText(_translate("KCC", "Advanced"))
import KCC_rc from . import KCC_rc

View File

@@ -343,7 +343,7 @@ def dirImgProcess(path):
pagenumber += 1 pagenumber += 1
work.append([afile, dirpath, options]) work.append([afile, dirpath, options])
if GUI: if GUI:
GUI.progressBarTick.emit(pagenumber, False) GUI.progressBarTick.emit(str(pagenumber))
if len(work) > 0: if len(work) > 0:
for i in work: for i in work:
workerPool.apply_async(func=fileImgProcess, args=(i, ), callback=fileImgProcess_tick) workerPool.apply_async(func=fileImgProcess, args=(i, ), callback=fileImgProcess_tick)
@@ -365,7 +365,7 @@ def fileImgProcess_tick(output):
workerOutput.append(output) workerOutput.append(output)
workerPool.terminate() workerPool.terminate()
if GUI: if GUI:
GUI.progressBarTick.emit(False, False) GUI.progressBarTick.emit('tick')
if not GUI.conversionAlive: if not GUI.conversionAlive:
workerPool.terminate() workerPool.terminate()
@@ -793,11 +793,11 @@ def preSplitDirectory(path):
if filesNumber > 0: if filesNumber > 0:
print('\nWARNING: Automatic output splitting failed.') print('\nWARNING: Automatic output splitting failed.')
if GUI: if GUI:
GUI.progressBarTick.emit('Automatic output splitting failed. <a href=' GUI.addMessage.emit('Automatic output splitting failed. <a href='
'"https://github.com/ciromattia/kcc/wiki' '"https://github.com/ciromattia/kcc/wiki'
'/Automatic-output-splitting">' '/Automatic-output-splitting">'
'More details.</a>', 'warning', False) 'More details.</a>', 'warning', False)
GUI.progressBarTick.emit('', False, False) GUI.addMessage.emit('', '', False)
return [path] return [path]
detectedSubSubdirectories = False detectedSubSubdirectories = False
detectedFilesInSubdirectories = False detectedFilesInSubdirectories = False
@@ -808,11 +808,11 @@ def preSplitDirectory(path):
elif len(dirs) == 0 and detectedSubSubdirectories: elif len(dirs) == 0 and detectedSubSubdirectories:
print('\nWARNING: Automatic output splitting failed.') print('\nWARNING: Automatic output splitting failed.')
if GUI: if GUI:
GUI.progressBarTick.emit('Automatic output splitting failed. <a href=' GUI.addMessage.emit('Automatic output splitting failed. <a href='
'"https://github.com/ciromattia/kcc/wiki' '"https://github.com/ciromattia/kcc/wiki'
'/Automatic-output-splitting">' '/Automatic-output-splitting">'
'More details.</a>', 'warning', False) 'More details.</a>', 'warning', False)
GUI.progressBarTick.emit('', False, False) GUI.addMessage.emit('', '', False)
return [path] return [path]
if len(files) != 0: if len(files) != 0:
detectedFilesInSubdirectories = True detectedFilesInSubdirectories = True
@@ -825,11 +825,11 @@ def preSplitDirectory(path):
if detectedFilesInSubdirectories and detectedSubSubdirectories: if detectedFilesInSubdirectories and detectedSubSubdirectories:
print('\nWARNING: Automatic output splitting failed.') print('\nWARNING: Automatic output splitting failed.')
if GUI: if GUI:
GUI.progressBarTick.emit('Automatic output splitting failed. <a href=' GUI.addMessage.emit('Automatic output splitting failed. <a href='
'"https://github.com/ciromattia/kcc/wiki' '"https://github.com/ciromattia/kcc/wiki'
'/Automatic-output-splitting">' '/Automatic-output-splitting">'
'More details.</a>', 'warning', False) 'More details.</a>', 'warning', False)
GUI.progressBarTick.emit('', False, False) GUI.addMessage.emit('', '', False)
return [path] return [path]
# Split directories # Split directories
split = splitDirectory(os.path.join(path, 'OEBPS', 'Images'), mode) split = splitDirectory(os.path.join(path, 'OEBPS', 'Images'), mode)
@@ -949,7 +949,7 @@ def main(argv=None, qtGUI=None):
checkOptions() checkOptions()
if qtGUI: if qtGUI:
GUI = qtGUI GUI = qtGUI
GUI.progressBarTick.emit(1, False) GUI.progressBarTick.emit('1')
else: else:
GUI = None GUI = None
if len(args) != 1: if len(args) != 1:
@@ -966,10 +966,10 @@ def main(argv=None, qtGUI=None):
if options.imgproc: if options.imgproc:
print("\nProcessing images...") print("\nProcessing images...")
if GUI: if GUI:
GUI.progressBarTick.emit('status', 'Processing images') GUI.progressBarTick.emit('Processing images')
dirImgProcess(path + "/OEBPS/Images/") dirImgProcess(path + "/OEBPS/Images/")
if GUI: if GUI:
GUI.progressBarTick.emit(1, False) GUI.progressBarTick.emit('1')
sanitizeTree(os.path.join(path, 'OEBPS', 'Images')) sanitizeTree(os.path.join(path, 'OEBPS', 'Images'))
if options.batchsplit: if options.batchsplit:
tomes = preSplitDirectory(path) tomes = preSplitDirectory(path)
@@ -979,11 +979,11 @@ def main(argv=None, qtGUI=None):
tomeNumber = 0 tomeNumber = 0
if GUI: if GUI:
if options.cbzoutput: if options.cbzoutput:
GUI.progressBarTick.emit('status', 'Compressing CBZ files') GUI.progressBarTick.emit('Compressing CBZ files')
else: else:
GUI.progressBarTick.emit('status', 'Compressing EPUB files') GUI.progressBarTick.emit('Compressing EPUB files')
GUI.progressBarTick.emit(len(tomes) + 1, False) GUI.progressBarTick.emit(str(len(tomes) + 1))
GUI.progressBarTick.emit(False, False) GUI.progressBarTick.emit('tick')
options.baseTitle = options.title options.baseTitle = options.title
for tome in tomes: for tome in tomes:
if len(tomes) > 1: if len(tomes) > 1:
@@ -1009,7 +1009,7 @@ def main(argv=None, qtGUI=None):
move(tome + '_comic.zip', filepath[-1]) move(tome + '_comic.zip', filepath[-1])
rmtree(tome, True) rmtree(tome, True)
if GUI: if GUI:
GUI.progressBarTick.emit(False, False) GUI.progressBarTick.emit('tick')
return filepath return filepath

View File

@@ -64,7 +64,7 @@ def mergeDirectory_tick(output):
mergeWorkerOutput.append(output) mergeWorkerOutput.append(output)
mergeWorkerPool.terminate() mergeWorkerPool.terminate()
if GUI: if GUI:
GUI.progressBarTick.emit(False, False) GUI.progressBarTick.emit('tick')
if not GUI.conversionAlive: if not GUI.conversionAlive:
mergeWorkerPool.terminate() mergeWorkerPool.terminate()
@@ -132,7 +132,7 @@ def splitImage_tick(output):
splitWorkerOutput.append(output) splitWorkerOutput.append(output)
splitWorkerPool.terminate() splitWorkerPool.terminate()
if GUI: if GUI:
GUI.progressBarTick.emit(False, False) GUI.progressBarTick.emit('tick')
if not GUI.conversionAlive: if not GUI.conversionAlive:
splitWorkerPool.terminate() splitWorkerPool.terminate()
@@ -278,8 +278,8 @@ def main(argv=None, qtGUI=None):
directoryNumer += 1 directoryNumer += 1
mergeWork.append([os.path.join(root, directory)]) mergeWork.append([os.path.join(root, directory)])
if GUI: if GUI:
GUI.progressBarTick.emit('status', 'Combining images') GUI.progressBarTick.emit('Combining images')
GUI.progressBarTick.emit(directoryNumer, False) GUI.progressBarTick.emit(str(directoryNumer))
for i in mergeWork: for i in mergeWork:
mergeWorkerPool.apply_async(func=mergeDirectory, args=(i, ), callback=mergeDirectory_tick) mergeWorkerPool.apply_async(func=mergeDirectory, args=(i, ), callback=mergeDirectory_tick)
mergeWorkerPool.close() mergeWorkerPool.close()
@@ -298,9 +298,9 @@ def main(argv=None, qtGUI=None):
else: else:
os.remove(os.path.join(root, name)) os.remove(os.path.join(root, name))
if GUI: if GUI:
GUI.progressBarTick.emit('status', 'Splitting images') GUI.progressBarTick.emit('Splitting images')
GUI.progressBarTick.emit(pagenumber, False) GUI.progressBarTick.emit(str(pagenumber))
GUI.progressBarTick.emit(False, False) GUI.progressBarTick.emit('tick')
if len(work) > 0: if len(work) > 0:
for i in work: for i in work:
splitWorkerPool.apply_async(func=splitImage, args=(i, ), callback=splitImage_tick) splitWorkerPool.apply_async(func=splitImage, args=(i, ), callback=splitImage_tick)

View File

@@ -40,7 +40,7 @@ class PdfJpgExtract:
return self.path return self.path
def extract(self): def extract(self):
pdf = open(self.origFileName, "rb").read() pdf = open(self.origFileName, "r").read()
startmark = "\xff\xd8" startmark = "\xff\xd8"
startfix = 0 startfix = 0
@@ -69,7 +69,7 @@ class PdfJpgExtract:
iend += endfix iend += endfix
jpg = pdf[istart:iend] jpg = pdf[istart:iend]
jpgfile = open(self.path + "/jpg%d.jpg" % njpg, "wb") jpgfile = open(self.path + "/jpg%d.jpg" % njpg, "wb")
jpgfile.write(jpg) jpgfile.write(bytearray(jpg, 'utf-8'))
jpgfile.close() jpgfile.close()
njpg += 1 njpg += 1