# import requests

# base_url = "https://cdn-videos.domestika.org/videos/000/075/208/fc6150916ffe56d52ed6e66c938f1b87/subtitles/fr/"
# for i in range(17):  # 17 files, from 00000.vtt to 00016.vtt
#     file_name = f"{i:05}.vtt"  # Formats the number with leading zeros
#     url = f"{base_url}{file_name}"
#     response = requests.get(url)
#     if response.status_code == 200:
#         with open(file_name, 'w', encoding='utf-8') as file:
#             file.write(response.text)
#     else:
#         print(f"Failed to download {file_name}")


import os

# Directory where your VTT files are located
directory = './'  # Update this to the path where your VTT files are stored

# Name of the file you want to create
merged_filename = 'merged_subtitles.vtt'

# Open the file where you want to merge all VTT files
with open(merged_filename, 'w', encoding='utf-8') as merged_file:
    # Iterate through all files in the directory
    for filename in sorted(os.listdir(directory)):
        if filename.endswith('.vtt'):
            # Construct the full file path
            file_path = os.path.join(directory, filename)
            
            # Open and read the VTT file
            with open(file_path, 'r', encoding='utf-8') as file:
                content = file.read()
                
                # Write the content to the merged file
                merged_file.write(content)
                # Optionally, write a newline after each file's content for better separation
                merged_file.write('\n')

print(f"All files have been merged into {merged_filename}")
