diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..e4bceac --- /dev/null +++ b/config.ini @@ -0,0 +1,5 @@ +[settings] +streamlink_location = "" +download_location = "" +skip_ads = + diff --git a/main.py b/main.py index 049cc11..274d623 100755 --- a/main.py +++ b/main.py @@ -1,25 +1,47 @@ #!/usr/bin/env python3 +import configparser import os import shutil import subprocess import sys import time from datetime import datetime -import configparser from pathlib import Path + import requests channel_list = [] downloading = {} -# Config Settings +# Default Config Settings +config = configparser.ConfigParser() streamlink_location = "streamlink" download_location = str(f"{Path.home()}/Downloads/Streams/") skip_ads = False def load_config(): - pass + print("Reading config file...") + if os.path.exists("config.ini"): + config.read("config.ini") + if ( + config.has_option("settings", "streamlink_location") + and not config["settings"]["streamlink_location"].strip() + ): + streamlink_location = config["settings"]["streamlink_location"] + if ( + config.has_option("settings", "download_location") + and not config["settings"]["download_location"].strip() + ): + download_location = config["settings"]["download_location"] + if ( + config.has_option("settings", "skip_ads") + and not config["settings"]["skip_ads"] + ): + skip_ads = bool(config["settings"]["skip_ads"]) + print("Config file loaded") + else: + print("No config file found using default values!") def write_log(channel): @@ -55,13 +77,20 @@ def check_system(): pass # Creates empty file sys.exit("Please populate the channel_list.txt with one channel per line!") + # Make sure the download location exists + if not os.path.exists(download_location): + print( + f"Download destination does not exist.\n Creating now at {download_location}" + ) + os.makedirs(download_location) + def stop_downloads(): """Goes through every process and stops it if running""" print("\nCleaning up...") for name, proc in downloading.items(): proc.terminate() - print("Stopping download of " + name) + print(f"Stopping download of {name}") def main(): @@ -85,17 +114,17 @@ def main(): "utf-8" ) if "isLiveBroadcast" in contents: - print("\033[1m" + channel + "\033[0m is \033[32mlive\033[0m!") + print(f"\033[1m{channel}\033[0m is \033[32mlive\033[0m!") if channel not in downloading: download_stream(channel) else: - print(channel + " is already downloading") + print("f{channel} is already downloading") write_log(channel) else: print("\033[1m" + channel + "\033[0m is \033[31mnot live\033[0m.") if channel in downloading: del downloading[channel] - print(channel + " is no longer downloading") + print(f"{channel} is no longer downloading") time.sleep(1) # Wait one second before going to next channel print( "\n\033[3mLast checked: " + datetime.now().strftime("%H:%M:%S") + "\033[0m"