Commit b09edaa5 authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Replace SOPDS_FB2PARSE to SOPDS_FB2SAX setting

parent da42b987
Loading
Loading
Loading
Loading

book_tools/LICENSE

deleted100644 → 0
+0 −22
Original line number Diff line number Diff line
The MIT License (MIT)

Copyright (c) 2014 FBReader.ORG Limited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+2 −9
Original line number Diff line number Diff line
@@ -11,15 +11,9 @@ from book_tools.format.epub import EPub
from book_tools.format.fb2 import FB2, FB2Zip
from book_tools.format.fb2sax import FB2sax
from book_tools.format.other import Dummy
#from fbreader.format.pdf import PDF
#from fbreader.format.msword import MSWord
from book_tools.format.mobi import Mobipocket
#from fbreader.format.rtf import RTF
#from fbreader.format.djvu import DjVu
#from fbreader.format.dummy import Dummy

#__detector = magic.open(magic.MAGIC_MIME_TYPE)
#__detector.load()
from constance import config

class __detector:
    @staticmethod
@@ -83,8 +77,7 @@ def create_bookfile(file, original_filename):
    if mimetype == Mimetype.EPUB:
        return EPub(file, original_filename)
    elif mimetype == Mimetype.FB2:
        #return FB2(file, original_filename)
        return FB2sax(file, original_filename)
        return FB2sax(file, original_filename) if config.SOPDS_FB2SAX else FB2(file, original_filename)
    elif mimetype == Mimetype.FB2_ZIP:
        return FB2Zip(file, original_filename)
    elif mimetype == Mimetype.MOBI:
+2 −2
Original line number Diff line number Diff line
import gzip, os
#import gzip, os
#from Crypto.Cipher import AES
from tempfile import mktemp
#from tempfile import mktemp

def encrypt(file_name, key, working_dir):
    '''
+1 −1
Original line number Diff line number Diff line
#import PythonMagick
from PIL import Image, ImageFile
#from PIL import Image, ImageFile

strip_symbols = ' »«\'\"\&\n-.#\\\`'

+6 −78
Original line number Diff line number Diff line
@@ -48,10 +48,12 @@ class opdsScanner:
    def log_options(self):
        self.logger.info(' ***** Starting sopds-scan...')
        self.logger.debug('OPTIONS SET')
        if config.SOPDS_ROOT_LIB!=None:       self.logger.debug('root_lib = '+config.SOPDS_ROOT_LIB)
        if config.SOPDS_FB2TOEPUB!=None: self.logger.debug('fb2toepub = '+config.SOPDS_FB2TOEPUB)
        if config.SOPDS_FB2TOMOBI!=None: self.logger.debug('fb2tomobi = '+config.SOPDS_FB2TOMOBI)
        if config.SOPDS_TEMP_DIR!=None:       self.logger.debug('temp_dir = '+config.SOPDS_TEMP_DIR)
        if config.SOPDS_ROOT_LIB!=None:       self.logger.debug('root_lib = %s'%config.SOPDS_ROOT_LIB)
        if config.SOPDS_FB2TOEPUB!=None: self.logger.debug('fb2toepub = %s'%config.SOPDS_FB2TOEPUB)
        if config.SOPDS_FB2TOMOBI!=None: self.logger.debug('fb2tomobi = %s'%config.SOPDS_FB2TOMOBI)
        if config.SOPDS_TEMP_DIR!=None:       self.logger.debug('temp_dir = %s'%config.SOPDS_TEMP_DIR)
        if config.SOPDS_FB2SAX != None:       self.logger.debug('FB2SAX = %s'%config.SOPDS_FB2SAX)


    def log_stats(self):
        self.t2=datetime.timedelta(seconds=time.time())
@@ -195,7 +197,6 @@ class opdsScanner:
                zip_process_error = 1
            self.bad_archives+=zip_process_error

    # Новая версия (0.42) процедуры извлечения метаданных из файлов книг fb2, epub, mobi
    def processfile(self,name,full_path,file,cat,archive=0,file_size=0):
        (n, e) = os.path.splitext(name)
        if e.lower() in config.SOPDS_BOOK_EXTENSIONS.split():
@@ -246,76 +247,3 @@ class opdsScanner:
            else:
                self.books_skipped+=1
                self.logger.debug("Book "+rel_path+"/"+name+" Already in DB.")

    # Старая версия (до 0.41) процедуры извлечения метаданных из файлов книг только fb2
    def processfile0(self,name,full_path,file,cat,archive=0,file_size=0):
        (n,e)=os.path.splitext(name)
        if e.lower() in config.SOPDS_BOOK_EXTENSIONS.split():
            rel_path=os.path.relpath(full_path,config.SOPDS_ROOT_LIB)
            self.logger.debug("Attempt to add book "+rel_path+"/"+name)
            self.fb2parser.reset()
            if opdsdb.findbook(name,rel_path,1)==None:
                if archive==0:
                    cat=opdsdb.addcattree(rel_path,archive)
                title=''
                lang=''
                annotation=''
                docdate=''
                book_is_valid = True

                if e.lower()=='.fb2' and config.SOPDS_FB2PARSE:
                    if isinstance(file, str):
                        f=open(file,'rb')
                    else:
                        f=file
                    self.fb2parser.parse(f)
                    f.close()

                    if len(self.fb2parser.lang.getvalue())>0:
                        lang=self.fb2parser.lang.getvalue()[0].strip(strip_symbols)
                    if len(self.fb2parser.book_title.getvalue())>0:
                        title=self.fb2parser.book_title.getvalue()[0].strip(strip_symbols)
                    if len(self.fb2parser.annotation.getvalue())>0:
                        annotation=('\n'.join(self.fb2parser.annotation.getvalue()))
                    if len(self.fb2parser.docdate.getvalue())>0:
                        docdate=self.fb2parser.docdate.getvalue()[0].strip();

                    if self.fb2parser.parse_error!=0:
                        errormsg=''
                        self.logger.warning(rel_path+' - '+name+' fb2 parse error ['+errormsg+']')
                        book_is_valid = False
                        self.bad_books+=1

                if book_is_valid:
                    if title=='': title=n

                    book=opdsdb.addbook(name,rel_path,cat,e[1:],title,annotation,docdate,lang,file_size,archive)
                    self.books_added+=1

                    if archive!=0:
                        self.books_in_archives+=1
                    self.logger.debug("Book "+rel_path+"/"+name+" Added ok.")

                    idx=0
                    for l in self.fb2parser.author_last.getvalue():
                        last_name=l.strip(strip_symbols)
                        first_name=self.fb2parser.author_first.getvalue()[idx].strip(strip_symbols)
                        #author=opdsdb.addauthor(first_name,last_name)
                        author=opdsdb.addauthor("%s %s"%(last_name,first_name))
                        opdsdb.addbauthor(book,author)
                        idx+=1
                    for l in self.fb2parser.genre.getvalue():
                        opdsdb.addbgenre(book,opdsdb.addgenre(l.lower().strip(strip_symbols)))
                    for l in self.fb2parser.series.attrss:
                        ser_name=l.get('name')
                        if ser_name:
                            ser=opdsdb.addseries(ser_name.strip())
                            sser_no=l.get('number','0').strip()
                            if sser_no.isdigit():
                                ser_no=int(sser_no)
                            else:
                                ser_no=0
                            opdsdb.addbseries(book,ser,ser_no)
            else:
                self.books_skipped+=1
                self.logger.debug("Book "+rel_path+"/"+name+" Already in DB.")
Loading