mirror of
https://gitgud.io/Melon__Bread/auto-ttv-grabber.git
synced 2024-11-25 00:38:35 -05:00
Compare commits
5 Commits
4218dc827f
...
1ce273bc61
Author | SHA1 | Date | |
---|---|---|---|
1ce273bc61 | |||
65efcbb171 | |||
e07dd0c5cd | |||
33d7ae24fb | |||
aaf2173894 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -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
|
||||
|
47
README.md
47
README.md
@ -2,12 +2,49 @@
|
||||
|
||||
<!--toc:start-->
|
||||
- [Auto TTV Grabber](#auto-ttv-grabber)
|
||||
- [Getting started](#getting-started)
|
||||
- [tl;dr](#tldr)
|
||||
- [Configuration](#configuration)
|
||||
- [Settings](#settings)
|
||||
- [Adding streams](#adding-streams)
|
||||
<!--toc:end-->
|
||||
|
||||
## 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/<channel_name>`)
|
||||
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/<channel_name>`)
|
||||
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/<channel_name>`
|
||||
- `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
|
||||
|
7
config.ini.example
Normal file
7
config.ini.example
Normal file
@ -0,0 +1,7 @@
|
||||
[settings]
|
||||
streamlink_location = ""
|
||||
download_location = ""
|
||||
skip_ads =
|
||||
|
||||
[streams]
|
||||
|
51
main.py
51
main.py
@ -7,9 +7,11 @@ import sys
|
||||
import time
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
import requests
|
||||
|
||||
channel_list = []
|
||||
channel_list: List[str] = []
|
||||
downloading = {}
|
||||
|
||||
# Default Config Settings
|
||||
@ -18,7 +20,7 @@ download_location: str = f"{Path.home()}/Downloads/Streams"
|
||||
skip_ads: bool = False
|
||||
|
||||
|
||||
def load_config():
|
||||
def load_config() -> None:
|
||||
print("Reading config file...")
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
@ -38,10 +40,17 @@ def load_config():
|
||||
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")
|
||||
|
||||
|
||||
def write_log(channel):
|
||||
# TODO: Log better and properly
|
||||
def write_log(channel: str) -> None:
|
||||
"""Writes the latest stdout of a process to log.txt"""
|
||||
with open("log.txt", "a") as log:
|
||||
line = downloading[channel].stdout.readline()
|
||||
@ -49,15 +58,16 @@ def write_log(channel):
|
||||
log.write(line.decode())
|
||||
|
||||
|
||||
def download_stream(channel):
|
||||
def download_stream(channel: str) -> None:
|
||||
"""Downloads a given channel name in its own subprocess"""
|
||||
# TODO: Just clean this up at somepoint
|
||||
addtional_parms = ""
|
||||
print(str(skip_ads))
|
||||
addtional_parms: str = ""
|
||||
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"
|
||||
cmd = f"{streamlink_location} --loglevel none --retry-max 10 {addtional_parms} -o {download_location}/{channel}/{file_name} twitch.tv/{channel} best"
|
||||
file_name: str = f"{channel}_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.ts"
|
||||
cmd: str = (
|
||||
f"{streamlink_location} --loglevel none --retry-max 10 {addtional_parms} -o {download_location}/{channel}/{file_name} twitch.tv/{channel} best"
|
||||
)
|
||||
downloading[channel] = subprocess.Popen(
|
||||
[cmd],
|
||||
shell=True,
|
||||
@ -65,10 +75,9 @@ def download_stream(channel):
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
write_log(channel)
|
||||
|
||||
|
||||
def check_system():
|
||||
def check_system() -> None:
|
||||
"""Makes sure everything is place for the script to run"""
|
||||
|
||||
# Checks for config file
|
||||
@ -79,14 +88,6 @@ def check_system():
|
||||
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(
|
||||
@ -95,7 +96,7 @@ def check_system():
|
||||
os.makedirs(download_location)
|
||||
|
||||
|
||||
def stop_downloads():
|
||||
def stop_downloads() -> None:
|
||||
"""Goes through every process and stops it if running"""
|
||||
print("\nCleaning up...")
|
||||
for name, proc in downloading.items():
|
||||
@ -103,20 +104,12 @@ def stop_downloads():
|
||||
print(f"Stopping download of {name}")
|
||||
|
||||
|
||||
def main():
|
||||
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:
|
||||
# Exits the program if there is no channels to grab
|
||||
if not channel_list:
|
||||
sys.exit("Please populate the channel_list.txt with one channel per line!")
|
||||
print("\n------------------------------------")
|
||||
for channel in channel_list:
|
||||
channel = channel.strip()
|
||||
@ -130,7 +123,7 @@ def main():
|
||||
download_stream(channel)
|
||||
else:
|
||||
print(f"{channel} is already downloading")
|
||||
write_log(channel)
|
||||
# write_log(channel)
|
||||
else:
|
||||
print("\033[1m" + channel + "\033[0m is \033[31mnot live\033[0m.")
|
||||
if channel in downloading:
|
||||
|
Loading…
Reference in New Issue
Block a user