diff --git a/calibre-plugin/ffdl_plugin.py b/calibre-plugin/ffdl_plugin.py index a5bf35c..213c865 100644 --- a/calibre-plugin/ffdl_plugin.py +++ b/calibre-plugin/ffdl_plugin.py @@ -19,6 +19,7 @@ from calibre.ptempfile import PersistentTemporaryFile from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata.meta import get_metadata from calibre.gui2 import error_dialog, warning_dialog, question_dialog, info_dialog +from calibre.gui2.tools import convert_single_ebook from calibre.gui2.actions import InterfaceAction from calibre.gui2.threaded_jobs import ThreadedJob @@ -385,7 +386,7 @@ class FanFictionDownLoaderPlugin(InterfaceAction): mi.comments = story.getMetadata("description") identicalbooks = self.db.find_identical_books(mi) - print(identicalbooks) + #print(identicalbooks) addedcount=0 if identicalbooks and collision != ADDNEW: ## more than one match? add to first off the list. @@ -436,6 +437,24 @@ class FanFictionDownLoaderPlugin(InterfaceAction): db.add_format_with_hooks(book_id, fileform, tmp, index_is_id=True) + # get all formats. + fmts = set([x.lower() for x in db.formats(book_id, index_is_id=True).split(',')]) + for fmt in fmts: + if fmt != fileform: + print("f:"+fmt) + ## calling convert doesn't work here because we're in a BG thread. + # (jobs,changed,bad)=convert_single_ebook(self.gui, + # db, + # [book_id], + # auto_conversion=True, + # out_format=fmt) + # print("jobs:%s changed:%s bad:%s"%(jobs,changed,bad)) + db.remove_format(book_id, fmt,index_is_id=True)#, notify=False + + for a in self.gui.iactions: # ['Convert Books'] + print("a:%s"%a) + + if updatemeta or collision == CALIBREONLY: db.set_metadata(book_id,mi) diff --git a/makezip.py b/makezip.py new file mode 100644 index 0000000..55a1019 --- /dev/null +++ b/makezip.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# epubmerge.py 1.0 + +# Copyright 2011, Jim Miller + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os, zipfile, sys +from glob import glob + +def addFolderToZip(myZipFile,folder,exclude=[]): + folder = folder.encode('ascii') #convert path to ascii for ZipFile Method + excludelist=[] + for ex in exclude: + excludelist.extend(glob(folder+"/"+ex)) + for file in glob(folder+"/*"): + if file in excludelist: + continue + if os.path.isfile(file): + #print file + myZipFile.write(file, file, zipfile.ZIP_DEFLATED) + elif os.path.isdir(file): + addFolderToZip(myZipFile,file,exclude=exclude) + +def createZipFile(filename,mode,files,exclude=[]): + myZipFile = zipfile.ZipFile( filename, mode ) # Open the zip file for writing + excludelist=[] + for ex in exclude: + excludelist.extend(glob(ex)) + for file in files: + if file in excludelist: + continue + file = file.encode('ascii') #convert path to ascii for ZipFile Method + if os.path.isfile(file): + (filepath, filename) = os.path.split(file) + #print file + myZipFile.write( file, filename, zipfile.ZIP_DEFLATED ) + if os.path.isdir(file): + addFolderToZip(myZipFile,file,exclude=exclude) + myZipFile.close() + return (1,filename) +