from datetime import date, datetime
import getpass
import json
import logging
from os.path import join
import re
import shutil
import subprocess
import tempfile
import uuid
from urllib.parse import urljoin
from xml.etree import ElementTree

import argh
from argh.interaction import safe_input
import arghlog
import requests
from requests.auth import HTTPBasicAuth


__version__ = '1.0'


SRC_ATTR_RE = re.compile(r"""
    (?P<src> src \s*=\s* )
    (?P<quote> ["'] )
    (?P<url>.*?)
    (?=(?P=quote))
    """, re.IGNORECASE | re.VERBOSE | re.MULTILINE | re.DOTALL)


CONTENTS_NCX_XML = """
    <ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="en">
        <head>
            <meta name="dtb:uid"/>
            <meta content="3" name="dtb:depth"/>