mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-10 15:13:35 +02:00
Sorted out mime initialization.
Every mime related function in main __init__.py has a flag check for the check if initialization has already done. This is nonsense, since it should be done implicitly early on the converter is starting. This commit straight the things out, and initialization is done in cli module. Also, function guess_type was removed, since it's just a proxy for mimetypes.guess_type function.
This commit is contained in:
@@ -2,22 +2,18 @@
|
||||
Provides abstraction for metadata reading.writing from a variety of ebook
|
||||
formats.
|
||||
"""
|
||||
import mimetypes
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.parse
|
||||
|
||||
from ebook_converter import relpath, guess_type, prints, force_unicode
|
||||
from ebook_converter import relpath, prints, force_unicode
|
||||
from ebook_converter.utils.config_base import tweaks
|
||||
from ebook_converter.polyglot.builtins import as_unicode
|
||||
from ebook_converter.polyglot.urllib import unquote
|
||||
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
try:
|
||||
_author_pat = re.compile(tweaks['authors_split_regex'])
|
||||
except Exception:
|
||||
@@ -231,7 +227,7 @@ class Resource(object):
|
||||
self.path = None
|
||||
self.fragment = ''
|
||||
try:
|
||||
self.mime_type = guess_type(href_or_path)[0]
|
||||
self.mime_type = mimetypes.guess_type(href_or_path)[0]
|
||||
except:
|
||||
self.mime_type = None
|
||||
if self.mime_type is None:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Read meta information from fb2 files
|
||||
"""
|
||||
import mimetypes
|
||||
import functools
|
||||
import os
|
||||
import random
|
||||
@@ -225,7 +226,7 @@ def _parse_cover_data(root, imgid, mi, ctx):
|
||||
mime_extensions = guess_all_extensions(mimetype)
|
||||
|
||||
if not mime_extensions and mimetype.startswith('image/'):
|
||||
mimetype_fromid = guess_type(imgid)[0]
|
||||
mimetype_fromid = mimetypes.guess_type(imgid)[0]
|
||||
if mimetype_fromid and mimetype_fromid.startswith('image/'):
|
||||
mime_extensions = guess_all_extensions(mimetype_fromid)
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import functools
|
||||
import glob
|
||||
import io
|
||||
import json
|
||||
import mimetypes
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@@ -74,7 +75,7 @@ class Resource(object): # {{{
|
||||
self.path = None
|
||||
self.fragment = ''
|
||||
try:
|
||||
self.mime_type = guess_type(href_or_path)[0]
|
||||
self.mime_type = mimetypes.guess_type(href_or_path)[0]
|
||||
except Exception:
|
||||
self.mime_type = None
|
||||
if self.mime_type is None:
|
||||
@@ -1304,8 +1305,8 @@ class OPF(object): # {{{
|
||||
'other.ms-coverimage'):
|
||||
for item in self.guide:
|
||||
if item.type.lower() == t:
|
||||
self.create_manifest_item(item.href(),
|
||||
guess_type(path)[0])
|
||||
self.create_manifest_item(
|
||||
item.href(), mimetypes.guess_type(path)[0])
|
||||
|
||||
def get_metadata_element(self, name):
|
||||
matches = self.metadata_elem_path(self.metadata, name=name)
|
||||
|
||||
Reference in New Issue
Block a user