|
|
|
@ -21,7 +21,6 @@ from __future__ import division, print_function, unicode_literals
|
|
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
import io
|
|
|
|
|
import json
|
|
|
|
|
import mimetypes
|
|
|
|
|
import re
|
|
|
|
|
import shutil
|
|
|
|
@ -36,7 +35,7 @@ from babel.units import format_unit
|
|
|
|
|
from flask import send_from_directory, make_response, redirect, abort
|
|
|
|
|
from flask_babel import gettext as _
|
|
|
|
|
from flask_login import current_user
|
|
|
|
|
from sqlalchemy.sql.expression import true, false, and_, or_, text, func
|
|
|
|
|
from sqlalchemy.sql.expression import true, false, and_, text, func
|
|
|
|
|
from werkzeug.datastructures import Headers
|
|
|
|
|
from werkzeug.security import generate_password_hash
|
|
|
|
|
from . import calibre_db
|
|
|
|
@ -59,10 +58,9 @@ try:
|
|
|
|
|
except ImportError:
|
|
|
|
|
use_PIL = False
|
|
|
|
|
|
|
|
|
|
from . import logger, config, get_locale, db, ub, isoLanguages, worker
|
|
|
|
|
from . import logger, config, get_locale, db, ub, worker
|
|
|
|
|
from . import gdriveutils as gd
|
|
|
|
|
from .constants import STATIC_DIR as _STATIC_DIR
|
|
|
|
|
from .pagination import Pagination
|
|
|
|
|
from .subproc_wrapper import process_wait
|
|
|
|
|
from .worker import STAT_WAITING, STAT_FAIL, STAT_STARTED, STAT_FINISH_SUCCESS
|
|
|
|
|
from .worker import TASK_EMAIL, TASK_CONVERT, TASK_UPLOAD, TASK_CONVERT_ANY
|
|
|
|
@ -100,10 +98,10 @@ def convert_book_format(book_id, calibrepath, old_book_format, new_book_format,
|
|
|
|
|
# text = _(u"%(format)s: %(book)s", format=new_book_format, book=book.title)
|
|
|
|
|
else:
|
|
|
|
|
settings = dict()
|
|
|
|
|
text = (u"%s -> %s: %s" % (old_book_format, new_book_format, book.title))
|
|
|
|
|
txt = (u"%s -> %s: %s" % (old_book_format, new_book_format, book.title))
|
|
|
|
|
settings['old_book_format'] = old_book_format
|
|
|
|
|
settings['new_book_format'] = new_book_format
|
|
|
|
|
worker.add_convert(file_path, book.id, user_id, text, settings, kindle_mail)
|
|
|
|
|
worker.add_convert(file_path, book.id, user_id, txt, settings, kindle_mail)
|
|
|
|
|
return None
|
|
|
|
|
else:
|
|
|
|
|
error_message = _(u"%(format)s not found: %(fn)s",
|
|
|
|
@ -263,6 +261,22 @@ def get_valid_filename(value, replace_whitespace=True):
|
|
|
|
|
return value.decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def split_authors(values):
|
|
|
|
|
authors_list = []
|
|
|
|
|
for value in values:
|
|
|
|
|
authors = re.split('[&;]', value)
|
|
|
|
|
for author in authors:
|
|
|
|
|
commas = author.count(',')
|
|
|
|
|
if commas == 1:
|
|
|
|
|
author_split = author.split(',')
|
|
|
|
|
authors_list.append(author_split[1] + ' ' + author_split[0])
|
|
|
|
|
elif commas > 1:
|
|
|
|
|
authors_list.append(author.split(','))
|
|
|
|
|
else:
|
|
|
|
|
authors_list.append(author)
|
|
|
|
|
return authors_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_sorted_author(value):
|
|
|
|
|
try:
|
|
|
|
|
if ',' not in value:
|
|
|
|
@ -366,6 +380,7 @@ def update_dir_structure_file(book_id, calibrepath, first_author):
|
|
|
|
|
src=path, dest=new_author_path, error=str(ex))
|
|
|
|
|
# Rename all files from old names to new names
|
|
|
|
|
if authordir != new_authordir or titledir != new_titledir:
|
|
|
|
|
new_name = ""
|
|
|
|
|
try:
|
|
|
|
|
new_name = get_valid_filename(localbook.title) + ' - ' + get_valid_filename(new_authordir)
|
|
|
|
|
path_name = os.path.join(calibrepath, new_authordir, os.path.basename(path))
|
|
|
|
@ -474,14 +489,14 @@ def generate_random_password():
|
|
|
|
|
return "".join(s[c % len(s)] for c in os.urandom(passlen))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def uniq(input):
|
|
|
|
|
def uniq(inpt):
|
|
|
|
|
output = []
|
|
|
|
|
for x in input:
|
|
|
|
|
for x in inpt:
|
|
|
|
|
if x not in output:
|
|
|
|
|
output.append(x)
|
|
|
|
|
return output
|
|
|
|
|
|
|
|
|
|
################################## External interface
|
|
|
|
|
# ################################# External interface #################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_dir_stucture(book_id, calibrepath, first_author=None):
|
|
|
|
@ -558,7 +573,6 @@ def save_cover_from_url(url, book_path):
|
|
|
|
|
return False, _("Cover Format Error")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_cover_from_filestorage(filepath, saved_filename, img):
|
|
|
|
|
if hasattr(img, '_content'):
|
|
|
|
|
f = open(os.path.join(filepath, saved_filename), "wb")
|
|
|
|
@ -617,7 +631,6 @@ def save_cover(img, book_path):
|
|
|
|
|
return save_cover_from_filestorage(os.path.join(config.config_calibre_dir, book_path), "cover.jpg", img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def do_download_file(book, book_format, client, data, headers):
|
|
|
|
|
if config.config_use_google_drive:
|
|
|
|
|
startTime = time.time()
|
|
|
|
@ -787,6 +800,7 @@ def get_cc_columns(filter_config_custom_read=False):
|
|
|
|
|
|
|
|
|
|
return cc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_download_link(book_id, book_format, client):
|
|
|
|
|
book_format = book_format.split(".")[0]
|
|
|
|
|
book = calibre_db.get_filtered_book(book_id)
|
|
|
|
|