Checks for channels_list.txt

This commit is contained in:
Rain Clark 2024-04-02 21:17:14 -04:00
parent 8813f26cbe
commit ccf38e2358

27
main.py
View File

@ -3,7 +3,10 @@
import subprocess import subprocess
import time import time
import requests import requests
import os
import sys
channel_list = []
downloading = [] downloading = []
@ -12,17 +15,27 @@ def download_stream(channel):
subprocess.run(["dl-stream", "-r", channel]) subprocess.run(["dl-stream", "-r", channel])
# Grab all the channels from channel_list.txt and put them in a list # Checks if the channel_list exists and if not makes one
with open("channel_list.txt", "r") as file: if os.path.exists("channel_list.txt"):
# channel_list = file.readlines() # Grab all the channels from channel_list.txt and put them in a list
channel_list = [ with open("channel_list.txt", "r") as file:
line for line in file if line.strip() # channel_list = file.readlines()
] # Removes all white spaces per line 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 # Run untill progam is killed
while True: 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: for channel in channel_list:
channel = channel.strip()
contents = requests.get("https://www.twitch.tv/" + channel).content.decode( contents = requests.get("https://www.twitch.tv/" + channel).content.decode(
"utf-8" "utf-8"
) )