# Path: dbcollection/core/exceptions.py
# class GoogleDriveFileIdDoesNotExist(Exception):
#     """Google drive's file id does not exist."""
#     pass
# 
# class InvalidURLDownloadSource(Exception):
#     """The url source is invalid/undefined."""
#     pass
# 
# class MD5HashNotEqual(Exception):
#     """The MD5 hashes are not equal."""
#     pass
# 
# class URLDoesNotExist(Exception):
#     """URL path does not exist."""
#     pass


import os
import hashlib
import shutil
import tempfile
import requests
import patoolib
import progressbar
from dbcollection.core.exceptions import (
    GoogleDriveFileIdDoesNotExist,
    InvalidURLDownloadSource,
    MD5HashNotEqual,
    URLDoesNotExist,
)

    def download_url_to_file(self, url_metadata, filename, verbose=True):
        """Downloads a single url to a file.

        Parameters
        ----------
        url_metadata : dict
            URL metadata.
        filename : str
            File name + path to save the url's data to disk.
        verbose : bool, optional
            Display messages + progress bar on screen when downloading the file.

        Raises
        ------
        InvalidURLDownloadSource
            If the input download method is invalid.

        """
        # Create temporary file to store the downloaded data
        tmpfile = self.create_temp_file(filename)

        # download the file
        method = url_metadata['method']
        url = url_metadata['url']
        if method == 'requests':
            URLDownload().download(url, filename=tmpfile, verbose=verbose)
        elif method == 'googledrive':
            URLDownloadGoogleDrive().download(url, filename=tmpfile)
        else:

# Path: dbcollection/core/exceptions.py
# class GoogleDriveFileIdDoesNotExist(Exception):
#     """Google drive's file id does not exist."""
#     pass
# 
# class InvalidURLDownloadSource(Exception):
#     """The url source is invalid/undefined."""
#     pass
# 
# class MD5HashNotEqual(Exception):
#     """The MD5 hashes are not equal."""
#     pass
# 
# class URLDoesNotExist(Exception):
#     """URL path does not exist."""
#     pass


# Path: dbcollection/utils/url.py
import os
import hashlib
import shutil
import tempfile
import requests
import patoolib
import progressbar
from dbcollection.core.exceptions import (
    GoogleDriveFileIdDoesNotExist,
    InvalidURLDownloadSource,
    MD5HashNotEqual,
    URLDoesNotExist,
)


    def download_url_to_file(self, url_metadata, filename, verbose=True):
        """Downloads a single url to a file.

        Parameters
        ----------
        url_metadata : dict
            URL metadata.
        filename : str
            File name + path to save the url's data to disk.
        verbose : bool, optional
            Display messages + progress bar on screen when downloading the file.

        Raises
        ------
        InvalidURLDownloadSource
            If the input download method is invalid.

        """
        # Create temporary file to store the downloaded data
        tmpfile = self.create_temp_file(filename)

        # download the file
        method = url_metadata['method']
        url = url_metadata['url']
        if method == 'requests':
            URLDownload().download(url, filename=tmpfile, verbose=verbose)
        elif method == 'googledrive':
            URLDownloadGoogleDrive().download(url, filename=tmpfile)
        else:

            raise InvalidURLDownloadSource('Invalid url source: {}'.format(method))