public function download($itag=null, $resume=false, $caption=false)
	{
		if ($itag === null && $this->defaultItag !== null) $itag = $this->defaultItag;
		if (!$this->isPlaylist) {
			try {
				$this->getVideoInfo(true);
				$this->downloadVideo($itag, $resume, $caption);
			} catch (YoutubeException $e) {
				throw $e;
			}
		} else {
			$i = 1;
			foreach ($this->playlistInfo->video as $video)
			{
				$this->currentDownloadingVideoIndex = $i++;
				$this->videoId = $video->encrypted_id;
				try {
					$this->getVideoInfo(true);
				} catch (YoutubeException $e) {
					throw $e;
				}

				try {
					$this->downloadVideo($itag, $resume, $caption);
				} catch (YoutubeException $e) {
					throw $e;
				}
			}
		}
	}
public function download($itag=null, $resume=false, $caption=false)
	{
		if ($itag === null && $this->defaultItag !== null) $itag = $this->defaultItag;
		if (!$this->isPlaylist) {
			try {
				$this->getVideoInfo(true);
				$this->downloadVideo($itag, $resume, $caption);
			} catch (YoutubeException $e) {
				throw $e;
			}
		} else {
			$i = 1;
			foreach ($this->playlistInfo->video as $video)
			{
				$this->currentDownloadingVideoIndex = $i++;
				$this->videoId = $video->encrypted_id;
				try {
					$this->getVideoInfo(true);
				} catch (YoutubeException $e) {
					throw $e;
				}

				try {
					$this->downloadVideo($itag, $resume, $caption);
				} catch (YoutubeException $e) {
					throw $e;
				}
			}
		}
	}
public function download ( $ itag = null , $ resume = false , $ caption = false ) { if ( $ itag === null && $ this -> defaultItag !== null ) $ itag = $ this -> defaultItag ; if ( ! $ this -> isPlaylist ) { try { $ this -> getVideoInfo ( true ) ; $ this -> downloadVideo ( $ itag , $ resume , $ caption ) ; } catch ( YoutubeException $ e ) { throw $ e ; } } else { $ i = 1 ; foreach ( $ this -> playlistInfo -> video as $ video ) { $ this -> currentDownloadingVideoIndex = $ i ++ ; $ this -> videoId = $ video -> encrypted_id ; try { $ this -> getVideoInfo ( true ) ; } catch ( YoutubeException $ e ) { throw $ e ; } try { $ this -> downloadVideo ( $ itag , $ resume , $ caption ) ; } catch ( YoutubeException $ e ) { throw $ e ; } } } }
Downloads video or playlist videos by given itag

@throws YoutubeException If Video ID is wrong or video not exists anymore or it's not viewable anyhow

@param  int  $itag   After calling {@see getVideoInfo()}, it returns various formats, each format has it's own itag. if no itag is passed or passed itag is not valid for the video, it will download the best quality of video
@param  boolean $resume If it should resume download if an uncompleted file exists or should download from beginning
@param  mixed $caption Caption language to download or null to download caption of default language. false to prevent download
@throws YoutubeException
Downloads video or playlist videos by given itag