Skip to content
Snippets Groups Projects
Commit b09edaa5 authored by Dmitry Shelepnev's avatar Dmitry Shelepnev
Browse files

Replace SOPDS_FB2PARSE to SOPDS_FB2SAX setting

parent da42b987
No related branches found
No related tags found
No related merge requests found
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.
......@@ -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:
......
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):
'''
......
#import PythonMagick
from PIL import Image, ImageFile
#from PIL import Image, ImageFile
strip_symbols = ' »«\'\"\&\n-.#\\\`'
......
......@@ -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.")
......@@ -177,7 +177,7 @@ CONSTANCE_CONFIG = OrderedDict([
('SOPDS_NOCOVER_PATH', (os.path.join(BASE_DIR,'static/images/nocover.jpg'),_('Path to image file showing for book without embedded cover'))),
('SOPDS_FB2PARSE', (True,_('This flag activate extraction metadata from fb2 files'))),
('SOPDS_FB2SAX', (True,_('This flag activate SAX Parser for FB2 instead of lxml.xpath'))),
('SOPDS_ZIPSCAN', (True,_('This flag activate zip files scanning'))),
('SOPDS_ZIPCODEPAGE', ('cp866',_('Set codepage for filenames inside zipfile'))),
('SOPDS_INPX_ENABLE', (False,_('Enables read metadata from inpx-file (and stop scanning deeper from ipx-file place)'))),
......@@ -205,7 +205,7 @@ CONSTANCE_CONFIG = OrderedDict([
CONSTANCE_CONFIG_FIELDSETS = {
'1. General Options': ('SOPDS_LANGUAGE', 'SOPDS_ROOT_LIB', 'SOPDS_BOOK_EXTENSIONS','SOPDS_SCAN_START_DIRECTLY'),
'2. Server Options': ('SOPDS_AUTH', 'SOPDS_ALPHABET_MENU', 'SOPDS_DOUBLES_HIDE', 'SOPDS_COVER_SHOW', 'SOPDS_SPLITITEMS', 'SOPDS_MAXITEMS', 'SOPDS_TITLE_AS_FILENAME', 'SOPDS_NOCOVER_PATH'),
'3. Scanner Options': ('SOPDS_FB2PARSE','SOPDS_ZIPSCAN','SOPDS_ZIPCODEPAGE', 'SOPDS_INPX_ENABLE', 'SOPDS_INPX_SKIP_UNCHANGED', 'SOPDS_INPX_TEST_ZIP', 'SOPDS_INPX_TEST_FILES', 'SOPDS_DELETE_LOGICAL'),
'3. Scanner Options': ('SOPDS_FB2SAX','SOPDS_ZIPSCAN','SOPDS_ZIPCODEPAGE', 'SOPDS_INPX_ENABLE', 'SOPDS_INPX_SKIP_UNCHANGED', 'SOPDS_INPX_TEST_ZIP', 'SOPDS_INPX_TEST_FILES', 'SOPDS_DELETE_LOGICAL'),
'4. Scanner Shedule': ('SOPDS_SCAN_SHED_MIN', 'SOPDS_SCAN_SHED_HOUR', 'SOPDS_SCAN_SHED_DAY','SOPDS_SCAN_SHED_DOW'),
'5. Converters Options': ('SOPDS_FB2TOEPUB', 'SOPDS_FB2TOMOBI', 'SOPDS_TEMP_DIR'),
'6. Log & PID Files': ('SOPDS_SERVER_LOG', 'SOPDS_SCANNER_LOG', 'SOPDS_SERVER_PID','SOPDS_SCANNER_PID'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment