import os, time, requests


def check_folder_for_new_videos(folder_path, interval_seconds=200):
    """
    Checks a folder for new TS video files at regular intervals.

    Args:
        folder_path (str): Path to the folder to be monitored.
        interval_seconds (int, optional): Time interval between checks in seconds. Default is 10 seconds.
    """
    # Create a set to store the filenames in the folder during the last check.
    previous_files = set()

    while True:
        # List all the files in the folder.
        current_files = set(os.listdir(folder_path))

        # Get the difference between the current files and the previous files.
        new_files = current_files - previous_files

        if new_files:
            print("New TS videos received:")

        else:
            message="*************** HLS live goes down !!!!!!!!!!!!!!!!!!!"
            base_url = 'https://api.telegram.org/bot6372395639:AAHaP8xxO-6kLxwLTrGJl1xuRNX2BIgJ5eQ/sendMessage?chat_id=-989588949&text="{}"'.format(message)
            requests.get(base_url)

        # Update the previous_files set for the next iteration.
        previous_files = current_files

        # Wait for the specified interval before the next check.
        time.sleep(interval_seconds)

if __name__ == "__main__":
    folder_path = "2m/2m_hls/"
    check_folder_for_new_videos(folder_path)
