Handle the download of an URL, using the proxy currently set in \
            :mod:`socks`.

    :param url: The URL to download.
    :returns: A tuple of the raw content of the downloaded data and its \
            associated content-type. Returns None if it was \
            unable to download the document.

def _download_helper(url):
    """
    Handle the download of an URL, using the proxy currently set in \
            :mod:`socks`.

    :param url: The URL to download.
    :returns: A tuple of the raw content of the downloaded data and its \
            associated content-type. Returns None if it was \
            unable to download the document.
    """
    # Try to fetch the URL using the current proxy
    try:
        request = urllib.request.urlopen(url)
        try:
            size = int(dict(request.info())['content-length'].strip())
        except KeyError:
            try:
                size = int(dict(request.info())['Content-Length'].strip())
            except KeyError:
                size = 0
        # Download the document
        doc = b""
        doc_size = 0
        while True:
            buf = request.read(1024)
            if buf:
                doc += buf
                doc_size += len(buf)
                if size != 0:
                    # Write progress bar on stdout
                    done = int(50 * doc_size / size)
                    sys.stdout.write("\r[%s%s]" %
                                     ('='*done, ' '*(50-done)))
                    sys.stdout.write(" "+str(int(float(done)/52*100))+"%")
                    sys.stdout.flush()
            else:
                break
        # Fetch content type
        contenttype = None
        contenttype_req = None
        try:
            contenttype_req = dict(request.info())['content-type']
        except KeyError:
            try:
                contenttype_req = dict(request.info())['Content-Type']
            except KeyError:
                return None
        if 'pdf' in contenttype_req:
            contenttype = 'pdf'
        elif 'djvu' in contenttype_req:
            contenttype = 'djvu'

        # Check content type and status code are ok
        if request.getcode() != 200 or contenttype is None:
            # Else, try with the next available proxy
            return None

        # Return a tuple of the downloaded content and the content-type
        return (doc, contenttype)
    # If an exception occurred, continue with next available proxy
    except (urllib.error.URLError, socket.error, ValueError):
        return None