Skip to content

Instantly share code, notes, and snippets.

@missuo
Created February 1, 2025 07:57
Show Gist options
  • Select an option

  • Save missuo/fb5b70bb993c7c26392e1e9c96c41dbf to your computer and use it in GitHub Desktop.

Select an option

Save missuo/fb5b70bb993c7c26392e1e9c96c41dbf to your computer and use it in GitHub Desktop.
download fansone
import requests
import os
from tqdm import tqdm
def download_and_merge_segments(base_url, start_segment, end_segment, output_file):
# Set headers
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Connection': 'keep-alive',
}
# Create temp directory for segments
if not os.path.exists('temp_segments'):
os.makedirs('temp_segments')
# Download all segments
print("Downloading segments...")
for i in tqdm(range(start_segment, end_segment + 1)):
segment_url = f"{base_url}/segment-{i}.ts"
segment_path = f"temp_segments/segment-{i}.ts"
if not os.path.exists(segment_path):
try:
response = requests.get(segment_url, headers=headers) # 添加 headers
response.raise_for_status()
with open(segment_path, 'wb') as f:
f.write(response.content)
except Exception as e:
print(f"Error downloading segment {i}: {str(e)}")
continue
# Merge segments
print("\nMerging segments...")
with open(output_file, 'wb') as outfile:
for i in range(start_segment, end_segment + 1):
segment_path = f"temp_segments/segment-{i}.ts"
if os.path.exists(segment_path):
with open(segment_path, 'rb') as infile:
outfile.write(infile.read())
# Clean up temp directory
print("Cleaning up temporary files...")
for file in os.listdir('temp_segments'):
os.remove(os.path.join('temp_segments', file))
os.rmdir('temp_segments')
print(f"Complete! Merged video saved as {output_file}")
# Usage
base_url = "https://video7.fansone.co/video7.fansone.co/xxxxxxx-8c3c-41d7-b2f8-d2f4202f1425/video_1"
start_segment = 0
end_segment = 501
output_file = "complete_video.ts"
download_and_merge_segments(base_url, start_segment, end_segment, output_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment