Generic function that downloads either files or thumbnails.
483952
private /*@Nullable*/Downloader startGetSomething(final String apiPath,
                                                      final /*@Nullable*/String[] params)
        throws DbxException
    {
        final String host = this.host.getContent();

        // we don't use doGet() here because doGet() will close our input stream before we can
        // download the contents.
        return DbxRequestUtil.runAndRetry(requestConfig.getMaxRetries(),
                                          new DbxRequestUtil.RequestMaker<Downloader, DbxException>() {
            @Override
            public Downloader run() throws DbxException {
                HttpRequestor.Response response = DbxRequestUtil.startGet(requestConfig, accessToken, USER_AGENT_ID, host, apiPath, params, null);

                boolean passedOwnershipOfStream = false;
                try {
                    if (response.getStatusCode() == 404) return null;
                    if (response.getStatusCode() != 200) throw DbxRequestUtil.unexpectedStatus(response);

                    String metadataString = DbxRequestUtil.getFirstHeader(response, "x-dropbox-metadata");
                    DbxEntry.File metadata;
                    try {
                        metadata = DbxEntry.File.Reader.readFully(metadataString);
                    }
                    catch (JsonReadException ex) {
                        String requestId = DbxRequestUtil.getRequestId(response);
                        throw new BadResponseException(requestId, "Bad JSON in X-Dropbox-Metadata header: " + ex.getMessage(), ex);
                    }

                    // Package up the metadata with the response body's InputStream.
                    Downloader result = new Downloader(metadata, response.getBody());

                    passedOwnershipOfStream = true;
                    return result;
                }
                finally {
                    // If we haven't passed ownership the stream to the caller, then close it.
                    if (!passedOwnershipOfStream) {
                        try {
                            response.getBody().close();
                        }
                        catch (IOException ex) {
                            // Ignore, since we don't actually care about the data in this method.
                            // We only care about IOExceptions when actually reading from the stream.
                        }
                    }
                }
            }
        });
    }
481679
def download(self, path=None, show_progress=True, resume=True,
                 auto_retry=True, proapi=False):
        """"""
        self.api.download(self, path, show_progress, resume, auto_retry,
                          proapi)
843883
def download(cls, url, filename=None):
        
        return utility.download(url, cls.directory(), filename)
1345148
def download_file(client, bucket, remote_path, local_path, overwrite=False):
    """"""
    bucket = client.get_bucket(bucket)
    if (not overwrite) and os.path.isfile(local_path):
        raise OSError('File already exists!')
    with open(local_path, 'wb') as ofh:
        bucket.get_blob(remote_path).download_to_file(ofh)
947500
function(dataUri, fileName) {

            var blob = joint.util.dataUriToBlob(dataUri);
            joint.util.downloadBlob(blob, fileName);
        }
152813
def _thumbnail_local(self, original_filename, thumb_filename,
                         thumb_size, thumb_url, crop=None, bg=None,
                         quality=85):
        """"""

        # create folders
        self._get_path(thumb_filename)

        thumb_url_full = url_for('static', filename=thumb_url)

        # Return the thumbnail URL now if it already exists locally
        if os.path.exists(thumb_filename):
            return thumb_url_full

        try:
            image = Image.open(original_filename)
        except IOError:
            return ''

        img = self._thumbnail_resize(image, thumb_size, crop=crop, bg=bg)

        img.save(thumb_filename, image.format, quality=quality)

        return thumb_url_full
538801
def download_preview(self, image, url_field='url'):
        
        return self.download(image, url_field=url_field, suffix='preview')
575133
def download(self, force=False, silent=False):
        """"""
        def _download():
            if self.url.startswith("http"):
                self._download_http(silent=silent)
            elif self.url.startswith("ftp"):
                self._download_ftp(silent=silent)
            else:
                raise ValueError("Invalid URL %s" % self.url)
            logger.debug("Moving %s to %s" % (
                self._temp_file_name,
                self.destination))
            shutil.move(self._temp_file_name, self.destination)
            logger.debug("Successfully downloaded %s" % self.url)

        try:
            is_already_downloaded = os.path.isfile(self.destination)
            if is_already_downloaded:
                if force:
                    try:
                        os.remove(self.destination)
                    except Exception:
                        logger.error("Cannot delete %s" % self.destination)
                    logger.info(
                        "Downloading %s to %s" % (self.url, self.destination))
                    logger.debug(
                        "Downloading %s to %s" % (self.url,
                                                  self._temp_file_name))
                    _download()
                else:
                    logger.info(("File %s already exist. Use force=True if you"
                                 " would like to overwrite it.") %
                                self.destination)
            else:
                _download()
        finally:
            try:
                os.remove(self._temp_file_name)
            except OSError:
                pass
197872
def download_file(url, dst_path):
    """"""
    request = requests.get(url, stream=True)
    with open(dst_path, 'wb') as downloaded_file:
        request.raw.decode_content = True
        shutil.copyfileobj(request.raw, downloaded_file)
1354346
def _download_wrapper(self, url, *args, **kwargs):
        
        try:
            return url, self._file_downloader.download(url, *args, **kwargs)
        except Exception as e:
            logging.error("AbstractDownloader: %s", traceback.format_exc())
            return url, e
252255
def download_file(url, path=None, clobber=False):
    
    if path is None:
        local_filename = os.path.join(directory, url.split('/')[-1])
    else:
        local_filename = path

    if os.path.exists(local_filename) and not clobber:
        logging.info('{} exists; not downloading.'.format(local_filename))
        return local_filename
        
    # NOTE the stream=True parameter
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                #f.flush() commented by recommendation from J.F.Sebastian
    return local_filename
1105873
def download_file(url, data_path='.', filename=None, size=None, chunk_size=4096, verbose=True):
    """"""
    if filename is None:
        filename = dropbox_basename(url)
    file_path = os.path.join(data_path, filename)
    if url.endswith('?dl=0'):
        url = url[:-1] + '1'  # noninteractive download
    if verbose:
        tqdm_prog = tqdm
        print('requesting URL: {}'.format(url))
    else:
        tqdm_prog = no_tqdm
    r = requests.get(url, stream=True, allow_redirects=True, timeout=5)
    size = r.headers.get('Content-Length', None) if size is None else size
    print('remote size: {}'.format(size))

    stat = path_status(file_path)
    print('local size: {}'.format(stat.get('size', None)))
    if stat['type'] == 'file' and stat['size'] == size:  # TODO: check md5 or get the right size of remote file
        r.close()
        return file_path

    print('Downloading to {}'.format(file_path))

    with open(file_path, 'wb') as f:
        for chunk in r.iter_content(chunk_size=chunk_size):
            if chunk:  # filter out keep-alive chunks
                f.write(chunk)

    r.close()
    return file_path
1052508
function FlickrImageDownloader () {
	var that = this;
	
	that.url = '';
	that.delay = 500;
	that.downloadFolder = '';

	that.paths = {};
	that.paths.base = 'https://www.flickr.com';
	that.paths.photostream = 'photos/!username';
	that.paths.set = that.paths.photostream + '/sets';
	that.paths.favorites = that.paths.photostream + '/favorites';

	that.image = {};
	that.image.dataAttr = 'deferSrc';
	that.image.selector = 'div#photo-display-container img.pc_img';	
	
	// Events constructor
	events.EventEmitter.call(that);

	// Setup listeners
	that.on('pageCountLoaded', function () {
		console.log('Event::pageCountLoaded');
		that.getImageUrls();
	});

	that.on('imageUrlsLoaded', function () {
		console.log('Event::imageUrlsLoaded');
		that.downloadImages();
	});

	that.on('downloadFinished', function (imageUrl) {
		console.log('Event::downloadFinished(' + imageUrl + ')');
	});

	that.on('allDownloadsFinished', function () {
		console.log('Event::allDownloadsFinished');
	});

	that.on('error', function (functionName, error) {
		console.log('Event::Error (' + functionName + ')', error);
	});
}
887727
def download(self, download_key, raise_exception_on_failure=False):
        """"""
        query = {"output": "json", "user_credentials": self.api_key}
        resp = requests.get(
            "%sdownload/%s" % (self._url, download_key),
            params=query,
            timeout=self._timeout,
        )

        if raise_exception_on_failure and resp.status_code != 200:
            raise DocumentDownloadFailure(resp.content, resp.status_code)
        return resp
118460
def download(self, remote_url, local_path, buffer_size=8 * 1024):
        """"""
        bucket, key = _parse_url(remote_url)

        response_file = self.call("GetObject", bucket=bucket, key=key)['Body']
        with open(local_path, 'wb') as fp:
            buf = response_file.read(buffer_size)
            while buf:
                fp.write(buf)
                buf = response_file.read(buffer_size)
1268326
def main():
    """"""
    from argparse import ArgumentParser
    description = "Download a bunch of thumbnails from Wikimedia Commons"
    parser = ArgumentParser(description=description)
    source_group = parser.add_mutually_exclusive_group()
    source_group.add_argument("-l", "--list", metavar="LIST",
                              dest="file_list",
                              type=argparse.FileType('r'),
                              help='A list of files <filename,width>')
    source_group.add_argument("-c", "--category", metavar="CATEGORY",
                              dest="category_name",
                              type=str,
                              help='A category name (without prefix)')
    parser.add_argument("files", nargs='*',
                        metavar="FILES",
                        help='A list of filenames')
    parser.add_argument("-o", "--output", metavar="FOLDER",
                        dest="output_path",
                        action=Folder,
                        default=os.getcwd(),
                        help='The directory to download the files to')
    parser.add_argument("-w", "--width",
                        dest="width",
                        type=int,
                        default=100,
                        help='The width of the thumbnail (default: 100)')
    verbosity_group = parser.add_mutually_exclusive_group()
    verbosity_group.add_argument("-v",
                                 action="count",
                                 dest="verbose",
                                 default=1,
                                 help="Verbosity level. -v for DEBUG")
    verbosity_group.add_argument("-q", "--quiet",
                                 action="store_const",
                                 dest="verbose",
                                 const=0,
                                 help="To silence the INFO messages")
    args = parser.parse_args()
    logging_map = {0: logging.WARNING,
                   1: logging.INFO,
                   2: logging.DEBUG}
    logging_level = logging_map.get(args.verbose, logging.DEBUG)
    logging.basicConfig(level=logging_level)
    logging.info("Starting")

    if args.file_list:
        download_from_file_list(args.file_list, args.output_path)
    elif args.category_name:
        download_from_category(args.category_name, args.output_path, args.width)
    elif args.files:
        download_from_files(args.files, args.output_path, args.width)
    else:
        parser.print_help()
166141
def download(directory, filename):
  """"""
  filepath = os.path.join(directory, filename)
  if tf.gfile.Exists(filepath):
    return filepath
  if not tf.gfile.Exists(directory):
    tf.gfile.MakeDirs(directory)
  url = 'http://yann.lecun.com/exdb/mnist/' + filename + '.gz'
  _, zipped_filepath = tempfile.mkstemp(suffix='.gz')
  print('Downloading %s to %s' % (url, zipped_filepath))
  urllib.request.urlretrieve(url, zipped_filepath)
  with gzip.open(zipped_filepath, 'rb') as f_in, \
      tf.gfile.Open(filepath, 'wb') as f_out:
    shutil.copyfileobj(f_in, f_out)
  os.remove(zipped_filepath)
  return filepath