mirror of
https://gitgud.io/Melon__Bread/auto-ttv-grabber.git
synced 2024-11-24 16:28:30 -05:00
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
import time
|
|
import requests
|
|
import os
|
|
import sys
|
|
|
|
channel_list = []
|
|
downloading = []
|
|
|
|
|
|
def download_stream(channel):
|
|
downloading.append(channel)
|
|
subprocess.run(["dl-stream", "-r", channel])
|
|
|
|
|
|
# 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"
|
|
)
|
|
if "isLiveBroadcast" in contents:
|
|
print(channel + " is live!")
|
|
if channel not in downloading:
|
|
download_stream(channel)
|
|
else:
|
|
print(channel + " is already downloading")
|
|
else:
|
|
print(channel + " is not live.")
|
|
if channel in downloading:
|
|
downloading.remove(channel)
|
|
print(channel + " is no longer downloading")
|
|
time.sleep(60) # Wait 60 Seconds before trying again
|