From 660b7f1e822ee8651ac8b41e8930f8fb828b19ae Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Sun, 7 Apr 2024 15:47:37 -0400 Subject: [PATCH] Clean up --- main.py | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index 5ad906a..cda285f 100755 --- a/main.py +++ b/main.py @@ -13,34 +13,32 @@ channel_list = [] downloading = {} # Default Config Settings -config = configparser.ConfigParser() -streamlink_location = "streamlink" -download_location = f"{Path.home()}/Downloads/Streams" -skip_ads = False +streamlink_location: str = "streamlink" +download_location: str = f"{Path.home()}/Downloads/Streams" +skip_ads: bool = False def load_config(): 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!") + config = configparser.ConfigParser() + config.read("config.ini") + if ( + config.has_option("settings", "streamlink_location") + and not config["settings"]["streamlink_location"].strip() + ): + streamlink_location = config["settings"]["streamlink_location"] + print(f"Streamlink location: {streamlink_location}") + if ( + config.has_option("settings", "download_location") + and not config["settings"]["download_location"].strip() + ): + download_location = config["settings"]["download_location"] + print(f"Download location: {download_location}") + if config.has_option("settings", "skip_ads") and not config["settings"]["skip_ads"]: + skip_ads = bool(config["settings"]["skip_ads"]) + print(f"Skip ads: {skip_ads}") + + print("Config file loaded") def write_log(channel): @@ -55,6 +53,7 @@ def download_stream(channel): """Downloads a given channel name in its own subprocess""" # TODO: Just clean this up at somepoint addtional_parms = "" + print(str(skip_ads)) if skip_ads: addtional_parms = "--twitch-proxy-playlist=https://lb-eu.cdn-perfprod.com,https://lb-eu2.cdn-perfprod.com,https://lb-na.cdn-perfprod.com,https://lb-as.cdn-perfprod.com,https://as.luminous.dev --twitch-disable-ads" file_name = f"{channel}_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.ts" @@ -71,6 +70,11 @@ def download_stream(channel): def check_system(): """Makes sure everything is place for the script to run""" + + # Checks for config file + if not os.path.exists("config.ini"): + sys.exit("ERROR: config.ini is not found! See README.md for more info.") + # Checks if streamlink is in the systems path if not shutil.which("streamlink"): sys.exit("ERROR: streamlink is not found in the systems path!") @@ -141,10 +145,10 @@ def main(): if __name__ == "__main__": - """ This is executed when run from the command line """ + """This is executed when run from the command line""" try: - load_config() check_system() + load_config() main() finally: stop_downloads()