From ccf38e2358e832dcf7305b127e05e55c16bc926c Mon Sep 17 00:00:00 2001 From: Rain Date: Tue, 2 Apr 2024 21:17:14 -0400 Subject: [PATCH] Checks for channels_list.txt --- main.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index d8812a4..2b913b9 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,10 @@ import subprocess import time import requests +import os +import sys +channel_list = [] downloading = [] @@ -12,17 +15,27 @@ def download_stream(channel): subprocess.run(["dl-stream", "-r", channel]) -# Grab all the channels from channel_list.txt and put them in a list -with open("channel_list.txt", "r") as file: - # channel_list = file.readlines() - channel_list = [ - line for line in file if line.strip() - ] # Removes all white spaces per line - +# Checks if the channel_list exists and if not makes one +if os.path.exists("channel_list.txt"): + # Grab all the channels from channel_list.txt and put them in a list + with open("channel_list.txt", "r") as file: + # channel_list = file.readlines() + channel_list = [ + line for line in file if line.strip() + ] # Removes all white spaces per line +else: + print("ERROR:'channel_list.txt' does not exist, creating now!") + with open("channel_list.txt", "w") as file: + pass # Writes Nothing + sys.exit("Please populate the channel_list.txt with one channel per line!") # Run untill progam is killed while True: + # Exits the program if there is no channels to Grab + if not channel_list: + sys.exit("Please populate the channel_list.txt with one channel per line!") for channel in channel_list: + channel = channel.strip() contents = requests.get("https://www.twitch.tv/" + channel).content.decode( "utf-8" )