diff --git a/opds_catalog/sopdscan.py b/opds_catalog/sopdscan.py index e61dc1acf33db14aaa32678820a52fe1a102d4bc..01bcb57cd1afb3df58e1a45faf95773718c1584c 100644 --- a/opds_catalog/sopdscan.py +++ b/opds_catalog/sopdscan.py @@ -203,49 +203,54 @@ class opdsScanner: 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) - if opdsdb.findbook(name, rel_path, 1) == None: - if archive==0: - cat=opdsdb.addcattree(rel_path,archive) - - try: - book_data = create_bookfile(file, name) - except Exception as err: - book_data = None - self.logger.warning(rel_path + ' - ' + name + ' Book parse error, skipping... (Error: %s)'%err) - self.bad_books += 1 - - if book_data: - lang = book_data.language_code.strip(strip_symbols) if book_data.language_code else '' - title = book_data.title.strip(strip_symbols) if book_data.title else n - annotation = book_data.description if book_data.description else '' - annotation = annotation.strip(strip_symbols) if isinstance(annotation, str) else annotation.decode('utf8').strip(strip_symbols) - docdate = book_data.docdate if book_data.docdate else '' - - 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.") - - for a in book_data.authors: - author_name = a.get('name',_('Unknown author')).strip(strip_symbols) - # Если в имени автора нет запятой, то фамилию переносим из конца в начало - if author_name and author_name.find(',')<0: - author_names = author_name.split() - author_name = ' '.join([author_names[-1],' '.join(author_names[:-1])]) - author=opdsdb.addauthor(author_name) - opdsdb.addbauthor(book,author) - - for genre in book_data.tags: - opdsdb.addbgenre(book,opdsdb.addgenre(genre.lower().strip(strip_symbols))) - - - if book_data.series_info: - ser = opdsdb.addseries(book_data.series_info['title']) - ser_no = book_data.series_info['index'] or '0' - ser_no = int(ser_no) if ser_no.isdigit() else 0 - opdsdb.addbseries(book,ser,ser_no) - else: - self.books_skipped+=1 - self.logger.debug("Book "+rel_path+"/"+name+" Already in DB.") + try: + if opdsdb.findbook(name, rel_path, 1) == None: + if archive==0: + cat=opdsdb.addcattree(rel_path,archive) + + try: + book_data = create_bookfile(file, name) + except Exception as err: + book_data = None + self.logger.warning(rel_path + ' - ' + name + ' Book parse error, skipping... (Error: %s)'%err) + self.bad_books += 1 + + if book_data: + lang = book_data.language_code.strip(strip_symbols) if book_data.language_code else '' + title = book_data.title.strip(strip_symbols) if book_data.title else n + annotation = book_data.description if book_data.description else '' + annotation = annotation.strip(strip_symbols) if isinstance(annotation, str) else annotation.decode('utf8').strip(strip_symbols) + docdate = book_data.docdate if book_data.docdate else '' + + 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.") + + for a in book_data.authors: + author_name = a.get('name',_('Unknown author')).strip(strip_symbols) + # Если в имени автора нет запятой, то фамилию переносим из конца в начало + if author_name and author_name.find(',')<0: + author_names = author_name.split() + author_name = ' '.join([author_names[-1],' '.join(author_names[:-1])]) + author=opdsdb.addauthor(author_name) + opdsdb.addbauthor(book,author) + + for genre in book_data.tags: + opdsdb.addbgenre(book,opdsdb.addgenre(genre.lower().strip(strip_symbols))) + + + if book_data.series_info: + ser = opdsdb.addseries(book_data.series_info['title']) + ser_no = book_data.series_info['index'] or '0' + ser_no = int(ser_no) if ser_no.isdigit() else 0 + opdsdb.addbseries(book,ser,ser_no) + else: + self.books_skipped+=1 + self.logger.debug("Book "+rel_path+"/"+name+" Already in DB.") + except UnicodeEncodeError as err: + self.logger.warning(rel_path + ' - ' + name + ' Book UnicodeEncodeError error, skipping... (Error: %s)' % err) + self.bad_books += 1 + diff --git a/raspberry.txt b/raspberry.txt new file mode 100644 index 0000000000000000000000000000000000000000..4365619e627b4faf30b7db311ad9ca1dcbf31ac1 --- /dev/null +++ b/raspberry.txt @@ -0,0 +1,76 @@ +## +## ��������� �� RaspberryPI +## �� SQLITE +## +sudo apt-get update +sudo apt-get install git +sudo apt-get install python3-pip +sudo apt-get install python3-lxml +sudo apt-get install libopenjp2-7-dev +sudo apt-get install libtiff5 +cd /home +sudo git clone https://github.com/mitshel/sopds.git +cd /home/sopds +sudo python3 -m pip install -r requirements.txt +sudo python3 manage.py migrate +sudo python3 manage.py sopds_util clear +sudo python3 manage.py createsuperuser +sudo python3 manage.py sopds_util setconf SOPDS_ROOT_LIB /home/sopds/opds_catalog/tests/data +sudo python3 manage.py sopds_util setconf SOPDS_LANGUAGE ru-RU +sudo python3 manage.py sopds_util setconf SOPDS_SCAN_START_DIRECTLY True +sudo python3 manage.py sopds_scanner start --daemon +sudo python3 manage.py sopds_server start --daemon + +## +## ����������� MYSQL +## +## +sudo apt-get install mysql-server +sudo apt-get install python3-mysqldb +sudo mysql mysql +mysql > create database if not exists sopds default charset=utf8; +mysql > grant all on sopds.* to 'sopds'@'localhost' identified by 'sopds'; +mysql > commit; +mysql > ^C +cd /home/sopds +sudo vi sopds/settings.py + +# ������� ����������� � ��������� �� Mysql +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'sopds', + 'HOST': 'localhost', + 'USER': 'sopds', + 'PASSWORD' : 'sopds', + 'OPTIONS' : {^M + 'init_command': "SET default_storage_engine=MyISAM;\ + SET sql_mode='';" + } + } +} + + +# ������������ ��������� �� SQLITE +# +# +#DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +# } +#} + +## +## ������ ��� ��� ������ +## ��� �������� ���������� �������� ������ Warning - ������ ��������� +## +## +sudo python3 manage.py migrate +sudo python3 manage.py sopds_util clear +sudo python3 manage.py createsuperuser +sudo python3 manage.py sopds_util setconf SOPDS_ROOT_LIB /home/sopds/opds_catalog/tests/data +sudo python3 manage.py sopds_util setconf SOPDS_LANGUAGE ru-RU +sudo python3 manage.py sopds_util setconf SOPDS_SCAN_START_DIRECTLY True +sudo python3 manage.py sopds_scanner start --daemon +sudo python3 manage.py sopds_server start --daemon \ No newline at end of file