title: python script to record online live streaming videos
body: <p>i am developing a script to download online live streaming videos.</p>
  
  <h2>My Script:</h2>
  
  <pre><code>print "Recording video..."
  response = urllib2.urlopen("streaming online video url")
  filename = time.strftime("%Y%m%d%H%M%S",time.localtime())+".avi"
  f = open(filename, 'wb')
  
  video_file_size_start = 0  
  video_file_size_end = 1048576 * 7  # end in 7 mb 
  block_size = 1024
  
  while True:
      try:
          buffer = response.read(block_size)
          if not buffer:
              break
          video_file_size_start += len(buffer)
          if video_file_size_start &gt; video_file_size_end:
              break
          f.write(buffer)
  
      except Exception, e:
          logger.exception(e)
  f.close()
  </code></pre>
  
  <p>above script is working fine to download 7Mb of video from live streaming contents and storing it in to *.avi files. </p>
  
  <p>However, I would like to download just 10 secs of video regardless of the file size and store it in avi file. </p>
  
  <p>I tried different possibilities but to no success. </p>
  
  <p>Could any one please share your knowledge here to fix my issue.</p>
  
  <p>Thanks in advance.</p>