From 7f7d900fef30de732ef11200f98039926e27b4ab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Jun 2011 12:23:34 -0600 Subject: [PATCH] Comic Input: Replace the # character in filenames as it can cause problem with conversion/vieweing. Fixes #792723 (ebook viewer cannot open cbr with # in image name) --- src/calibre/ebooks/comic/input.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/comic/input.py b/src/calibre/ebooks/comic/input.py index 56f7683c57..5203e3698d 100755 --- a/src/calibre/ebooks/comic/input.py +++ b/src/calibre/ebooks/comic/input.py @@ -11,7 +11,7 @@ import os, shutil, traceback, textwrap, time, codecs from Queue import Empty from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation -from calibre import extract, CurrentDir, prints +from calibre import extract, CurrentDir, prints, walk from calibre.constants import filesystem_encoding from calibre.ptempfile import PersistentTemporaryDirectory from calibre.utils.ipc.server import Server @@ -27,6 +27,11 @@ def extract_comic(path_to_comic_file): # names tdir = tdir.decode(filesystem_encoding) extract(path_to_comic_file, tdir) + for x in walk(tdir): + bn = os.path.basename(x) + nbn = bn.replace('#', '_') + if nbn != bn: + os.rename(x, os.path.join(os.path.dirname(x), nbn)) return tdir def find_pages(dir, sort_on_mtime=False, verbose=False): @@ -362,6 +367,7 @@ class ComicInput(InputFormatPlugin): if not line: continue fname, title = line.partition(':')[0], line.partition(':')[-1] + fname = fname.replace('#', '_') fname = os.path.join(tdir, *fname.split('/')) if not title: title = os.path.basename(fname).rpartition('.')[0]