mirror of
https://gitgud.io/Melon__Bread/auto-ttv-grabber.git
synced 2024-11-24 16:28:30 -05:00
Formatting & Refactoring
This commit is contained in:
parent
0d53c8c292
commit
5dd3e92a5b
43
main.py
43
main.py
@ -58,6 +58,25 @@ def write_log(channel: str) -> None:
|
||||
log.write(line.decode())
|
||||
|
||||
|
||||
# TODO: Have steamlink itself check if the channel is live
|
||||
def is_live(channel: str) -> bool:
|
||||
"""Checks if a channel is live on Twitch"""
|
||||
try:
|
||||
contents = requests.get("https://www.twitch.tv/" + channel).content.decode(
|
||||
"utf-8"
|
||||
)
|
||||
if "isLiveBroadcast" in contents:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except Exception:
|
||||
print(f"There was an issue checking if {channel} was life. Will try next time!")
|
||||
if channel in downloading:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def download_stream(channel: str) -> None:
|
||||
"""Downloads a given channel name in its own subprocess"""
|
||||
# TODO: Just clean this up at somepoint
|
||||
@ -113,29 +132,29 @@ def main() -> None:
|
||||
print("\n------------------------------------")
|
||||
for channel in channel_list:
|
||||
channel = channel.strip()
|
||||
# TODO: Have steamlink itself check if the channel is live
|
||||
# TODO: Have checking if channel is live in its own function
|
||||
# TODO: If the request erros out just move on and not break the program
|
||||
contents = requests.get("https://www.twitch.tv/" + channel).content.decode(
|
||||
"utf-8"
|
||||
)
|
||||
if "isLiveBroadcast" in contents:
|
||||
print(f"\033[1m{channel}\033[0m is \033[32mlive\033[0m!")
|
||||
|
||||
if is_live(channel):
|
||||
print(f"\n\033[1m{channel}\033[0m is \033[32mlive\033[0m!", end=" ")
|
||||
if channel not in downloading:
|
||||
download_stream(channel)
|
||||
else:
|
||||
# TODO: Format this and dont make its own line
|
||||
print(f"{channel} is already downloading")
|
||||
print("\033[33m(Already Downloading)\033[0m")
|
||||
# write_log(channel)
|
||||
else:
|
||||
print("\033[1m" + channel + "\033[0m is \033[31mnot live\033[0m.")
|
||||
print(
|
||||
"\n\033[1m" + channel + "\033[0m is \033[31mnot live\033[0m.",
|
||||
end=" ",
|
||||
)
|
||||
if channel in downloading:
|
||||
del downloading[channel]
|
||||
# TODO: Format this and dont make its own line
|
||||
print(f"{channel} is no longer downloading")
|
||||
print("\033[35m(Stopping)\033[0m")
|
||||
time.sleep(1) # Wait one second before going to next channel
|
||||
print(
|
||||
"\n\033[3mLast checked: " + datetime.now().strftime("%H:%M:%S") + "\033[0m"
|
||||
"\n\n\033[3mLast checked: "
|
||||
+ datetime.now().strftime("%H:%M:%S")
|
||||
+ "\033[0m"
|
||||
)
|
||||
print("------------------------------------")
|
||||
time.sleep(60) # Wait 60 Seconds before trying again
|
||||
|
Loading…
Reference in New Issue
Block a user