mirror of
https://gitgud.io/Melon__Bread/auto-ttv-grabber.git
synced 2024-11-28 10:18:21 -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())
|
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:
|
def download_stream(channel: str) -> None:
|
||||||
"""Downloads a given channel name in its own subprocess"""
|
"""Downloads a given channel name in its own subprocess"""
|
||||||
# TODO: Just clean this up at somepoint
|
# TODO: Just clean this up at somepoint
|
||||||
@ -113,29 +132,29 @@ def main() -> None:
|
|||||||
print("\n------------------------------------")
|
print("\n------------------------------------")
|
||||||
for channel in channel_list:
|
for channel in channel_list:
|
||||||
channel = channel.strip()
|
channel = channel.strip()
|
||||||
# TODO: Have steamlink itself check if the channel is live
|
|
||||||
# TODO: Have checking if channel is live in its own function
|
if is_live(channel):
|
||||||
# TODO: If the request erros out just move on and not break the program
|
print(f"\n\033[1m{channel}\033[0m is \033[32mlive\033[0m!", end=" ")
|
||||||
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 channel not in downloading:
|
if channel not in downloading:
|
||||||
download_stream(channel)
|
download_stream(channel)
|
||||||
else:
|
else:
|
||||||
# TODO: Format this and dont make its own line
|
# 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)
|
# write_log(channel)
|
||||||
else:
|
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:
|
if channel in downloading:
|
||||||
del downloading[channel]
|
del downloading[channel]
|
||||||
# TODO: Format this and dont make its own line
|
# 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
|
time.sleep(1) # Wait one second before going to next channel
|
||||||
print(
|
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("------------------------------------")
|
print("------------------------------------")
|
||||||
time.sleep(60) # Wait 60 Seconds before trying again
|
time.sleep(60) # Wait 60 Seconds before trying again
|
||||||
|
Loading…
Reference in New Issue
Block a user