import requests import os import time # 定义下载函数 def download_resource(url, filename): # 设置最大重试次数 max_retries = 3 retries = 0 while retries < max_retries: try: response = requests.get(url) if response.status_code == 200: with open(filename, 'wb') as f: f.write(response.content) print(f'Downloaded {url} as {filename}') return except Exception as e: print(f'Failed to download {url}: {e}') retries += 1 time.sleep(1) # 等待1秒后重试 print(f'Failed to download {url} after {max_retries} retries') # 批量下载资源并命名为带有序号的四位数字文件名 for i in range(238, 1116): # 从0000到0009 fname='{:04d}.ts'.format(i) url = 'https://hey11.cjkypo.com/202312/08/apgz943egj/video/1000k_0X720_64k_25/hls/player'+fname download_resource(url, fname)
ls -1 -v *.ts | xargs cat > mmm.mp4
标签:视频,retries,url,ts,filename,fname,download,文件批量 From: https://www.cnblogs.com/ahuo/p/17892167.html