// Download downloads media item (video or image) with the best quality.
//
// Input parameters are folder and filename. If filename is "" will be saved with
// the default value name.
//
// If file exists it will be saved
// This function makes folder automatically
//
// This function returns an slice of location of downloaded items
// The returned values are the output path of images and videos.
//
// This function does not download CarouselMedia.
//
// See example: examples/media/itemDownload.go
Download downloads media item (video or image) with the best quality.

Input parameters are folder and filename. If filename is "" will be saved with
the default value name.

If file exists it will be saved
This function makes folder automatically

This function returns an slice of location of downloaded items
The returned values are the output path of images and videos.

This function does not download CarouselMedia.

See example: examples/media/itemDownload.go
// Download downloads media item ( video or image ) with the best quality . // // Input parameters are folder and filename . If filename is " " will be saved with // the default value name . // // If file exists it will be saved // This function makes folder automatically // // This function returns an slice of location of downloaded items // The returned values are the output path of images and videos . // // This function does not download CarouselMedia . // // See example : examples / media / itemDownload . go
func (item *Item) Download(folder, name string) (imgs, vds string, err error) {
	var u *neturl.URL
	var nname string
	imgFolder := path.Join(folder, "images")
	vidFolder := path.Join(folder, "videos")
	inst := item.media.instagram()
	os.MkdirAll(folder, 0777)
	os.MkdirAll(imgFolder, 0777)
	os.MkdirAll(vidFolder, 0777)
	vds = GetBest(item.Videos)
	if vds != "" {
		if name == "" {
			u, err = neturl.Parse(vds)
			if err != nil {
				return
			}
			nname = path.Join(vidFolder, path.Base(u.Path))
		} else {
			nname = path.Join(vidFolder, nname)
		}
		nname = getname(nname)
		vds, err = download(inst, vds, nname)
		return "", vds, err
	}
	imgs = GetBest(item.Images.Versions)
	if imgs != "" {
		if name == "" {
			u, err = neturl.Parse(imgs)
			if err != nil {
				return
			}
			nname = path.Join(imgFolder, path.Base(u.Path))
		} else {
			nname = path.Join(imgFolder, nname)
		}
		nname = getname(nname)
		imgs, err = download(inst, imgs, nname)
		return imgs, "", err
	}
	return imgs, vds, fmt.Errorf("cannot find any image or video")
}
func ( item * Item ) Download ( folder , name string ) ( imgs , vds string , err error ) { var u * neturl . URL var nname string imgFolder := path . Join ( folder , " " ) vidFolder := path . Join ( folder , " " ) inst := item . media . instagram ( ) os . MkdirAll ( folder , 0777 ) os . MkdirAll ( imgFolder , 0777 ) os . MkdirAll ( vidFolder , 0777 ) vds = GetBest ( item . Videos ) if vds != " " { if name == " " { u , err = neturl . Parse ( vds ) if err != nil { return } nname = path . Join ( vidFolder , path . Base ( u . Path ) ) } else { nname = path . Join ( vidFolder , nname ) } nname = getname ( nname ) vds , err = download ( inst , vds , nname ) return " " , vds , err } imgs = GetBest ( item . Images . Versions ) if imgs != " " { if name == " " { u , err = neturl . Parse ( imgs ) if err != nil { return } nname = path . Join ( imgFolder , path . Base ( u . Path ) ) } else { nname = path . Join ( imgFolder , nname ) } nname = getname ( nname ) imgs , err = download ( inst , imgs , nname ) return imgs , " " , err } return imgs , vds , fmt . Errorf ( " " ) }
Download downloads media item (video or image) with the best quality.
Download downloads media item ( video or image ) with the best quality .