(self)
Get the next chunk of the download.

    Returns:
      (status, done): (MediaDownloadStatus, boolean)
         The value of 'done' will be True when the media has been fully
         downloaded.

    Raises:
      apiclient.errors.HttpError if the response was not a 2xx.
      httplib2.Error if a transport error has occured.
Get the next chunk of the download.
Get the next chunk of the download .
def next_chunk(self):
    """Get the next chunk of the download.

    Returns:
      (status, done): (MediaDownloadStatus, boolean)
         The value of 'done' will be True when the media has been fully
         downloaded.

    Raises:
      apiclient.errors.HttpError if the response was not a 2xx.
      httplib2.Error if a transport error has occured.
    """
    headers = {
        'range': 'bytes=%d-%d' % (
            self.progress_, self.progress_ + self.chunksize_)
        }
    http = self.request_.http
    http.follow_redirects = False

    resp, content = http.request(self.uri_, headers=headers)
    if resp.status in [301, 302, 303, 307, 308] and 'location' in resp:
        self.uri_ = resp['location']
        resp, content = http.request(self.uri_, headers=headers)
    if resp.status in [200, 206]:
      self.progress_ += len(content)
      self.fh_.write(content)

      if 'content-range' in resp:
        content_range = resp['content-range']
        length = content_range.rsplit('/', 1)[1]
        self.total_size_ = int(length)

      if self.progress_ == self.total_size_:
        self.done_ = True
      return MediaDownloadProgress(self.progress_, self.total_size_), self.done_
    else:
      raise HttpError(resp, content, self.uri_)
def next_chunk ( self ) : headers = { 'range' : 'bytes=%d-%d' % ( self . progress_ , self . progress_ + self . chunksize_ ) } http = self . request_ . http http . follow_redirects = False resp , content = http . request ( self . uri_ , headers = headers ) if resp . status in [ 301 , 302 , 303 , 307 , 308 ] and 'location' in resp : self . uri_ = resp [ 'location' ] resp , content = http . request ( self . uri_ , headers = headers ) if resp . status in [ 200 , 206 ] : self . progress_ += len ( content ) self . fh_ . write ( content ) if 'content-range' in resp : content_range = resp [ 'content-range' ] length = content_range . rsplit ( '/' , 1 ) [ 1 ] self . total_size_ = int ( length ) if self . progress_ == self . total_size_ : self . done_ = True return MediaDownloadProgress ( self . progress_ , self . total_size_ ) , self . done_ else : raise HttpError ( resp , content , self . uri_ )