Skip to content

Commit

Permalink
Merge branch 'janeczku:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
holta authored Jul 11, 2024
2 parents 0c3388a + 02d2c2b commit 8b5ebff
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 1,853 deletions.
4 changes: 2 additions & 2 deletions cps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
mimetypes.add_type('image/vnd.djv', '.djvu')
mimetypes.add_type('application/mpeg', '.mpeg')
mimetypes.add_type('audio/mpeg', '.mp3')
mimetypes.add_type('application/mp4', '.m4a')
mimetypes.add_type('application/mp4', '.m4b')
mimetypes.add_type('audio/x-m4a', '.m4a')
mimetypes.add_type('audio/x-m4a', '.m4b')
mimetypes.add_type('audio/ogg', '.ogg')
mimetypes.add_type('application/ogg', '.oga')
mimetypes.add_type('text/css', '.css')
Expand Down
7 changes: 3 additions & 4 deletions cps/file_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def del_temp_dir():

def validate_mime_type(file_buffer, allowed_extensions):
mime = magic.Magic(mime=True)
allowed_mimetypes =list()
allowed_mimetypes = list()
for x in allowed_extensions:
try:
allowed_mimetypes.append(mimetypes.types_map["." + x])
except KeyError as e:
except KeyError:
log.error("Unkown mimetype for Extension: {}".format(x))
tmp_mime_type = mime.from_buffer(file_buffer.read())
file_buffer.seek(0)
Expand All @@ -66,6 +66,5 @@ def validate_mime_type(file_buffer, allowed_extensions):
return True
except:
file_buffer.seek(0)
pass

log.error("Mimetype '{}' not found in allowed types".format(tmp_mime_type))
return False
2 changes: 1 addition & 1 deletion cps/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def move_files_on_change(calibre_path, new_author_dir, new_titledir, localbook,
if not os.path.isdir(new_path):
os.makedirs(new_path)
shutil.move(original_filepath, os.path.join(new_path, db_filename))
log.debug("Moving title: %s to %s/%s", original_filepath, new_path)
log.debug("Moving title: %s to %s", original_filepath, new_path)
else:
# Check new path is not valid path
if not os.path.exists(new_path):
Expand Down
16 changes: 12 additions & 4 deletions cps/tasks/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,18 @@ def _convert_calibre(self, file_path, format_old_ext, format_new_ext, has_cover)
'--with-library', library_path]
p = process_open(opf_command, quotes, my_env)
p.wait()
path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(uuid4()) + ".opf")
with open(path_tmp_opf, 'w') as fd:
copyfileobj(p.stdout, fd)

check = p.returncode
calibre_traceback = p.stderr.readlines()
if check == 0:
path_tmp_opf = os.path.join(tmp_dir, "metadata_" + str(uuid4()) + ".opf")
with open(path_tmp_opf, 'w') as fd:
copyfileobj(p.stdout, fd)
else:
error_message = ""
for ele in calibre_traceback:
if not ele.startswith('Traceback') and not ele.startswith(' File'):
error_message = N_("Calibre failed with error: %(error)s", error=ele)
return check, error_message
quotes = [1, 2, 4, 6]
command = [config.config_converterpath, (file_path + format_old_ext),
(file_path + format_new_ext)]
Expand Down
2 changes: 1 addition & 1 deletion optional-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ natsort>=2.2.0,<8.5.0
comicapi>=2.2.0,<3.3.0

# Kobo integration
jsonschema>=3.2.0,<4.23.0
jsonschema>=3.2.0,<4.24.0

# Hide console Window on Windows
pywin32>=220,<310 ; sys_platform == 'win32'
Loading

0 comments on commit 8b5ebff

Please sign in to comment.