From e07dd0c5cd7e7bd20140d62ecb8aae28809b588c Mon Sep 17 00:00:00 2001 From: Melon Bread Date: Mon, 8 Apr 2024 16:34:28 -0400 Subject: [PATCH] Now read the channel list from the config.ini --- .gitignore | 4 ++-- README.md | 47 +++++++++++++++++++++++++++++++++++++++++----- config.ini.example | 7 +++++++ main.py | 20 ++++++-------------- 4 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 config.ini.example diff --git a/.gitignore b/.gitignore index a1a1b6d..7772b6a 100644 --- a/.gitignore +++ b/.gitignore @@ -159,8 +159,8 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ -# Channel List -channel_list.txt +# Configuration +config.ini # dl-stream log log.txt diff --git a/README.md b/README.md index 1ba0d8a..0be5bdc 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,49 @@ - [Auto TTV Grabber](#auto-ttv-grabber) - - [Getting started](#getting-started) + - [tl;dr](#tldr) + - [Configuration](#configuration) + - [Settings](#settings) + - [Adding streams](#adding-streams) -## Getting started +## tl;dr -This script relies on [streamlink](https://streamlink.github.io) being in your systems path. +This script relies on [streamlink](https://streamlink.github.io) being installed. You can find all of its requirements on the their project page. -This script loops through all of the channels in `channel_list.txt` once per minute checking to see if the channel is live via a HTTP request. -Once a channel is live a [streamlink](https://streamlink.github.io) subprocess spawns in the background downloading the stream to it's default location (`$HOME/Downloads/Stream/`) +This script loops through all of the channels in `config.ini`, +once per minute checking to see if the channel is live via a HTTP request. +Once a channel is live a `streamlink` subprocess spawns in the background, +downloading the stream to it's default location (`$HOME/Downloads/Stream/`) +If you wish to change this location, you can find out how to below + +## Configuration + +You can copy `config.ini.example` from the repo to `config.ini` to begin. +Leaving a setting blank will render it being ignored and using the default value. + +### Settings + +- `streamlink_location`: If `streamlink` is not in your path you can specify +its absolute location here. Otherwise it looks for it in your path. +- `download_location`: You can specify the absolute path to where you would like +to save the steams. A subdirectory will be created for each channel as it goes live. +If left blank the default location is: `$HOME/Downloads/Streams/` +- `skip_ads` : Takes a `True` or `False` value. If `True` you will need to have +installed the [ttvlol](https://github.com/2bc4/streamlink-ttvlol) `streamlink` +plugin. Setting this to `True` without doing so will cause the +`streamlink` subprocess to fail. Default value is `False` + +### Adding streams + +You will need to add the channels Twitch username to `config.ini`: + +```ini +[streams] +1 = coney +2 = dougdoug +3 = parkzer +``` + +As for as I know there is no limit to how many streams you can add this way, +just make sure when you add a new stream it is incremented by one diff --git a/config.ini.example b/config.ini.example new file mode 100644 index 0000000..bc7e43a --- /dev/null +++ b/config.ini.example @@ -0,0 +1,7 @@ +[settings] +streamlink_location = "" +download_location = "" +skip_ads = + +[streams] + diff --git a/main.py b/main.py index dc5a464..d9ff388 100755 --- a/main.py +++ b/main.py @@ -40,6 +40,12 @@ def load_config() -> None: skip_ads = bool(config["settings"]["skip_ads"]) print(f"Skip ads: {skip_ads}") + if len(config["streams"]) < 1: + sys.exit("ERROR: No streams found in config.ini! See README.md for more info.") + else: + for index in range(1, len(config["streams"]) + 1): + channel_list.append(config["streams"][str(index)]) + print("Config file loaded") @@ -82,14 +88,6 @@ def check_system() -> None: if not shutil.which("streamlink"): sys.exit("ERROR: streamlink is not found in the systems path!") - # TODO: Combine the channel_list into the config - # Checks if the channel_list exists and if not makes one - if not os.path.exists("channel_list.txt"): - print("ERROR:'channel_list.txt' does not exist, creating now!") - with open("channel_list.txt", "w"): - 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( @@ -108,12 +106,6 @@ def stop_downloads() -> None: def main() -> None: """Main entry point of the app""" - # 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 # Run untill progam is killed while True: