def download_video(youtube_id, download_path='../content/', download_url=OUTSIDE_DOWNLOAD_URL, format='mp4', callback=None):
 ensure_dir(download_path)
 (url, thumb_url) = get_outside_video_urls(youtube_id, download_url=download_url, format=format)
 video_filename = ('%(id)s.%(format)s' % {'id': youtube_id, 'format': format})
 filepath = os.path.join(download_path, video_filename)
 thumb_filename = ('%(id)s.png' % {'id': youtube_id})
 thumb_filepath = os.path.join(download_path, thumb_filename)
 try:
  response = download_file(url, filepath, callback_percent_proxy(callback, end_percent=95))
  if ((not os.path.isfile(filepath)) or ('content-length' not in response.headers) or (not (len(open(filepath, 'rb').read()) == int(response.headers['content-length'])))):
   raise URLNotFound('Video was not found, tried: {}'.format(url))
  response = download_file(thumb_url, thumb_filepath, callback_percent_proxy(callback, start_percent=95, end_percent=100))
  if ((not os.path.isfile(thumb_filepath)) or ('content-length' not in response.headers) or (not (len(open(thumb_filepath, 'rb').read()) == int(response.headers['content-length'])))):
   raise URLNotFound('Thumbnail was not found, tried: {}'.format(thumb_url))
 except DownloadCancelled:
  delete_downloaded_files(youtube_id, download_path)
  raise
 except (socket.timeout, IOError) as e:
  logging.exception(e)
  logging.info('Timeout -- Network UnReachable')
  delete_downloaded_files(youtube_id, download_path)
  raise
 except Exception as e:
  logging.exception(e)
  delete_downloaded_files(youtube_id, download_path)
  raise

def download_video ( youtube_id , download_path = '../content/' , download_url = OUTSIDE_DOWNLOAD_URL , format = 'mp4' , callback = None ) : ensure_dir ( download_path ) ( url , thumb_url ) = get_outside_video_urls ( youtube_id , download_url = download_url , format = format ) video_filename = ( '%(id)s.%(format)s' % { 'id' : youtube_id , 'format' : format } ) filepath = os . path . join ( download_path , video_filename ) thumb_filename = ( '%(id)s.png' % { 'id' : youtube_id } ) thumb_filepath = os . path . join ( download_path , thumb_filename ) try : response = download_file ( url , filepath , callback_percent_proxy ( callback , end_percent = 95 ) ) if ( ( not os . path . isfile ( filepath ) ) or ( 'content-length' not in response . headers ) or ( not ( len ( open ( filepath , 'rb' ) . read ( ) ) == int ( response . headers [ 'content-length' ] ) ) ) ) : raise URLNotFound ( 'Video was not found, tried: {}' . format ( url ) ) response = download_file ( thumb_url , thumb_filepath , callback_percent_proxy ( callback , start_percent = 95 , end_percent = 100 ) ) if ( ( not os . path . isfile ( thumb_filepath ) ) or ( 'content-length' not in response . headers ) or ( not ( len ( open ( thumb_filepath , 'rb' ) . read ( ) ) == int ( response . headers [ 'content-length' ] ) ) ) ) : raise URLNotFound ( 'Thumbnail was not found, tried: {}' . format ( thumb_url ) ) except DownloadCancelled : delete_downloaded_files ( youtube_id , download_path ) raise except ( socket . timeout , IOError ) as e : logging . exception ( e ) logging . info ( 'Timeout -- Network UnReachable' ) delete_downloaded_files ( youtube_id , download_path ) raise except Exception as e : logging . exception ( e ) delete_downloaded_files ( youtube_id , download_path ) raise
downloads the video file to disk .