我正在开发一个脚本来下载在线直播视频.
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 > video_file_size_end:
break
f.write(buffer)
except Exception, e:
logger.exception(e)
f.close()
Run Code Online (Sandbox Code Playgroud)
上面的脚本工作正常,可以从实时流媒体内容下载7Mb的视频,并将其存储到*.avi文件中.
但是,我想下载10秒的视频而不管文件大小,并将其存储在avi文件中.
我尝试了不同的可能性但没有成功.
任何人都可以在这里分享你的知识来解决我的问题.
提前致谢.
以下是我的清单清单;
db_rows = [('a','b','c',4),
('a','s','f',6),
('a','c','d',6),
('a','b','f',2),
('a','b','c',6),
('a','b','f',8),
('a','s','f',6),
('a','b','f',7),
('a','s','f',5),
('a','b','f',2)]
Run Code Online (Sandbox Code Playgroud)
如果内部列表中前三个值相同,那么我需要添加第四个值来创建新列表
我需要这样的结果列表:
final_list = [('a','b','c',10),
('a','s','f',17),
('a','c','d',6),
('a','b','f',19)]
Run Code Online (Sandbox Code Playgroud)
我试过下面的脚本(不工作):
final_list = []
for row in db_rows:
temp_flag=False
temp_list = []
val = 0
for ref_row in db_rows:
if row != ref_row:
if row[0]==ref_row[0] and row[1]==ref_row[1] and row[2]==ref_row[2]:
val = val + ref_row[3]
temp_flag=True
temp_list=(row[0],row[1],row[2],val)
if temp_flag==False:
temp_list=row
final_list.append(temp_list)
Run Code Online (Sandbox Code Playgroud)
请指教.