Return the local path to the downloaded copy of a given URL.
        Don't download the file again if it's already present,
        unless `force` is True.
328437
def fetch(
            self,
            url,
            filename=None,
            decompress=False,
            force=False,
            timeout=None,
            use_wget_if_available=True):
        
        key = (url, decompress)
        if not force and key in self._local_paths:
            path = self._local_paths[key]
            if exists(path):
                return path
            else:
                del self._local_paths[key]
        path = download.fetch_file(
            url,
            filename=filename,
            decompress=decompress,
            subdir=self.subdir,
            force=force,
            timeout=timeout,
            use_wget_if_available=use_wget_if_available)

        self._local_paths[key] = path
        return path
1191288
def download(self, url, dir_path, filename=None):
        
        if not filename:
            filename = url.rsplit('/', 1)[1]
        path = os.path.join(dir_path, filename)

        content = self.fetch(url)
        with open(path, "wb") as f:
            f.write(content)

        return path
542270
def local_filename(
            self,
            url=None,
            filename=None,
            decompress=False):
        
        return common.build_local_filename(url, filename, decompress)
961803
def download_url(self, local_file):
        

        downloader = urllib.request.URLopener()
        downloader.retrieve(self.url, local_file)
448907
def get_download_link(self):
        
        url = None
        if not self.get("downloadable"):
            try:
                url = self.client.get_location(
                    self.client.STREAM_URL % self.get("id"))
            except serror as e:
                print(e)

        if not url:
            try:
                url = self.client.get_location(
                    self.client.DOWNLOAD_URL % self.get("id"))
            except serror as e:
                print(e)

        return url
1188379
def download(self, local, remote):
        
        self.sync(RemoteFile(remote, self.api), LocalFile(local))
158472
def download(self, localdir, max_retry):
        
        local_file = self.gen_localdir(localdir) + self.gen_filename()

        if self.track_exists(localdir):
            print("Track {0} already downloaded, skipping!".format(
                self.get("id")))
            return False

        if local_file in self.get_ignored_tracks(localdir):
            print("\033[93mTrack {0} ignored, skipping!!\033[0m".format(
                self.get("id")))
            return False

        dlurl = self.get_download_link()

        if not dlurl:
            raise serror("Can't download track_id:%d|%s" % (
                self.get("id"),
                self.get("title")))

        retry = max_retry
        print("\nDownloading %s (%d).." % (self.get("title"), self.get("id")))

        while True:
            try:
                urllib.request.urlretrieve(dlurl, local_file,
                                           self._progress_hook)
                break
            except Exception as e:
                if os.path.isfile(local_file):
                    os.unlink(local_file)
                retry -= 1

                if retry < 0:
                    raise serror("Can't download track-id %s, max retry "
                                 "reached (%d). Error occured: %s" % (
                                     self.get("id"), max_retry, type(e)))
                else:
                    print("\033[93mError occured for track-id %s (%s). "
                          "Retrying.. (%d/%d) \033[0m" % (
                              self.get("id"),
                              type(e),
                              max_retry - retry,
                              max_retry))
            except KeyboardInterrupt:
                if os.path.isfile(local_file):
                    os.unlink(local_file)
                raise serror("KeyBoard Interrupt: Incomplete file removed.")

        self.filepath = local_file + self.get_file_extension(local_file)
        os.rename(local_file, self.filepath)
        print("Downloaded => %s" % self.filepath)

        self.downloaded = True
        return True
380196
def file_url_to_local_path(file_url):
    
    parts = urlparse(file_url)
    path = unquote(parts.path)
    if path.startswith('/') and not path.startswith('//'):
        if ON_DARWIN:
            return path
        if len(parts.netloc) == 2 and parts.netloc[1] == ':':  # Drive letter and colon.
            return parts.netloc + path
        return 'C:' + path  # Assume C drive if it's just a path starting with /.
    if len(path) > 2 and path[1] == ':':
        return path
1276014
def get_path(src):  # pragma: no cover
    
    res = None
    while not res:
        if res is False:
            print(colored('You must provide a path to an existing directory!', 'red'))
        print('You need a local clone or release of (a fork of) '
              'https://github.com/{0}'.format(src))
        res = input(colored('Local path to {0}: '.format(src), 'green', attrs=['blink']))
        if res and Path(res).exists():
            return Path(res).resolve()
        res = False
1257587
def download_file(save_path, file_url):
    

    r = requests.get(file_url)  # create HTTP response object

    with open(save_path, 'wb') as f:
        f.write(r.content)

    return save_path
1284507
def download_if_not_exists(url: str, filename: str,
                           skip_cert_verify: bool = True,
                           mkdir: bool = True) -> None:
    
    if os.path.isfile(filename):
        log.info("No need to download, already have: {}", filename)
        return
    if mkdir:
        directory, basename = os.path.split(os.path.abspath(filename))
        mkdir_p(directory)
    download(url=url,
             filename=filename,
             skip_cert_verify=skip_cert_verify)
843883
def download(cls, url, filename=None):
        
        return utility.download(url, cls.directory(), filename)
4815
def get_path_url(path, relative=False):
    
    if relative:
        return os.path.relpath(path)
    else:
        return 'file://%s' % os.path.abspath(path)
724436
def do_get(self, from_path, to_path):
        
        to_file = open(os.path.expanduser(to_path), "wb")

        self.n.downloadFile(self.current_path + "/" + from_path, to_path)
768398
def download_file(url, local_filename):
    
    local_filename = os.path.abspath(local_filename)
    path = os.path.dirname(local_filename)
    if not os.path.isdir(path):
        os.makedirs(path)

    with tqdm(unit='B', unit_scale=True) as progress:
        def report(chunk, chunksize, total):
            progress.total = total
            progress.update(chunksize)
        return urlretrieve(url, local_filename, reporthook=report)
1299750
def download(self, overwrite=True):
        
        if overwrite or not os.path.exists(self.file_path):
            _, f = tempfile.mkstemp()
            try:
                urlretrieve(self.DOWNLOAD_URL, f)
                extract_csv(f, self.file_path)
            finally:
                os.remove(f)
1365227
def path(self, which=None):
        
        if which in ('download_html',):
            return '{0}/{1}'.format(
                super(ArfReport, self).path(which='self'),
                which
            )
        return super(ArfReport, self).path(which)