// DownloadImages download all images from URL and save to directory.
DownloadImages download all images from URL and save to directory.
// DownloadImages download all images from URL and save to directory .
func DownloadImages(baseURL string, dir string, feedback chan DownloadEntry) {
	var (
		maxWorkers = runtime.GOMAXPROCS(0)
		sem        = semaphore.NewWeighted(int64(maxWorkers))
	)
	defer close(feedback)
	root, err := parseHTML(baseURL)
	if err != nil {
		feedback <- DownloadEntry{Error: err}
		return
	}
	getImage := func(content *elementConent) {
		defer sem.Release(1)
		filename, err := downloadImage(content, dir)
		feedback <- DownloadEntry{filename, err}
	}
	ctx := context.TODO()
	for _, content := range iterateDOM(root, baseURL, domHandlers) {
		if err := sem.Acquire(ctx, 1); err != nil {
			feedback <- DownloadEntry{Error: err}
			return
		}
		go getImage(content)
	}
	if err := sem.Acquire(ctx, int64(maxWorkers)); err != nil {
		feedback <- DownloadEntry{Error: err} 
	}
}
func DownloadImages ( baseURL string , dir string , feedback chan DownloadEntry ) { var ( maxWorkers = runtime . GOMAXPROCS ( 0 ) sem = semaphore . NewWeighted ( int64 ( maxWorkers ) ) ) defer close ( feedback ) root , err := parseHTML ( baseURL ) if err != nil { feedback <- DownloadEntry { Error : err } return } getImage := func ( content * elementConent ) { defer sem . Release ( 1 ) filename , err := downloadImage ( content , dir ) feedback <- DownloadEntry { filename , err } } ctx := context . TODO ( ) for _ , content := range iterateDOM ( root , baseURL , domHandlers ) { if err := sem . Acquire ( ctx , 1 ) ; err != nil { feedback <- DownloadEntry { Error : err } return } go getImage ( content ) } if err := sem . Acquire ( ctx , int64 ( maxWorkers ) ) ; err != nil { feedback <- DownloadEntry { Error : err } } }
DownloadImages download all images from URL and save to directory.
DownloadImages download all images from URL and save to directory .