2024-04-02 20:51:44 -04:00
|
|
|
#!/usr/bin/env python3
|
2024-04-02 21:17:14 -04:00
|
|
|
import os
|
2024-04-03 13:27:00 -04:00
|
|
|
import shutil
|
2024-04-03 15:13:14 -04:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
2024-04-03 14:17:51 -04:00
|
|
|
from datetime import datetime
|
2024-04-02 20:51:44 -04:00
|
|
|
|
2024-04-03 15:13:14 -04:00
|
|
|
import requests
|
|
|
|
|
2024-04-02 21:17:14 -04:00
|
|
|
channel_list = []
|
2024-04-02 20:51:44 -04:00
|
|
|
downloading = []
|
|
|
|
|
|
|
|
|
|
|
|
def download_stream(channel):
|
|
|
|
downloading.append(channel)
|
2024-04-03 15:13:14 -04:00
|
|
|
with open("log.txt", "w") as log:
|
|
|
|
subprocess.Popen(
|
|
|
|
["dl-stream", "-r", channel], start_new_session=True, stdout=log
|
|
|
|
)
|
2024-04-02 20:51:44 -04:00
|
|
|
|
|
|
|
|
2024-04-03 13:27:00 -04:00
|
|
|
# Checks if dl-stream is in the systems path
|
|
|
|
if not shutil.which("dl-stream"):
|
|
|
|
sys.exit("ERROR: dl-stream is not found in the systems path!")
|
|
|
|
|
|
|
|
|
2024-04-02 21:17:14 -04:00
|
|
|
# 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!")
|
2024-04-02 20:51:44 -04:00
|
|
|
|
|
|
|
# Run untill progam is killed
|
|
|
|
while True:
|
2024-04-02 21:17:14 -04:00
|
|
|
# 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!")
|
2024-04-03 14:17:51 -04:00
|
|
|
print("\n------------------------------------")
|
2024-04-02 20:51:44 -04:00
|
|
|
for channel in channel_list:
|
2024-04-02 21:17:14 -04:00
|
|
|
channel = channel.strip()
|
2024-04-02 20:51:44 -04:00
|
|
|
contents = requests.get("https://www.twitch.tv/" + channel).content.decode(
|
|
|
|
"utf-8"
|
|
|
|
)
|
|
|
|
if "isLiveBroadcast" in contents:
|
2024-04-03 14:17:51 -04:00
|
|
|
print("\033[1m" + channel + "\033[0m is \033[32mlive\033[0m!")
|
2024-04-02 20:51:44 -04:00
|
|
|
if channel not in downloading:
|
|
|
|
download_stream(channel)
|
|
|
|
else:
|
|
|
|
print(channel + " is already downloading")
|
|
|
|
else:
|
2024-04-03 15:13:14 -04:00
|
|
|
print("\033[1m" + channel + "\033[0m is \033[31mnot live\033[0m.")
|
2024-04-02 20:51:44 -04:00
|
|
|
if channel in downloading:
|
|
|
|
downloading.remove(channel)
|
|
|
|
print(channel + " is no longer downloading")
|
2024-04-03 14:17:51 -04:00
|
|
|
print("\n\033[3mLast checked: " + datetime.now().strftime("%H:%M:%S") + "\033[0m")
|
|
|
|
print("------------------------------------")
|
2024-04-02 20:51:44 -04:00
|
|
|
time.sleep(60) # Wait 60 Seconds before trying again
|