Last active
August 30, 2025 20:34
-
-
Save alsolovyev/3ee1c8a62b224abe9874ef23865b169d to your computer and use it in GitHub Desktop.
This Fish shell script simplifies the process of recording Twitch streams by using Streamlink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rt --description "Record a Twitch/VKVideo live-stream to a file" | |
| set -l app "streamlink" | |
| # Ensure the app is installed | |
| if not command -v $app > /dev/null | |
| echo (set_color red)"Error: '$app' is not installed."(set_color normal) | |
| switch $app | |
| case "streamlink" | |
| if command -v brew > /dev/null | |
| echo "You can install 'streamlink' using Homebrew by running:" | |
| echo "brew install streamlink" | |
| else | |
| echo "Please install 'streamlink' manually. Visit the official website for installation instructions:" | |
| echo "https://streamlink.github.io/install.html" | |
| end | |
| case "*" | |
| echo (set_color yellow)"Please install '$app' manually"(set_color normal) | |
| end | |
| return 1 | |
| end | |
| # Parse command-line arguments | |
| argparse --name=rt "D/debug" "d/delay=" "h/help" "o/output=" "q/quality=" "r/retry=" -- $argv | |
| or return | |
| # Display usage message if help flag is passed | |
| if set -q _flag_help | |
| echo "Usage: rt [options] <streamer_name>" | |
| echo "" | |
| echo "Options:" | |
| echo " -D, --debug Show the streamlink command that would be executed, but don't run it" | |
| echo " -h, --help Show this help message and exit" | |
| echo " -o, --output FILE Specify the output file or directory" | |
| echo " -q, --quality QUAL Specify the stream quality (default: best)" | |
| echo " -r, --retry DELAY Retry fetching the list of available streams until streams are found while waiting DELAY second(s)" | |
| return 0 | |
| end | |
| # Set default options and variable | |
| # set -l retry_delay 10 | |
| set -l streamlink_options "--twitch-disable-ads" | |
| set -l streamer_name $argv[1] | |
| set -l quality "best" | |
| # ATTEMPTS time(s) to open the stream | |
| # https://streamlink.github.io/cli.html#cmdoption-retry-open | |
| set -a streamlink_options "--retry-open=24" | |
| # Validate streamer name | |
| if test -z "$streamer_name" | |
| echo (set_color red)"Error: Streamer name is required."(set_color normal) | |
| return 1 | |
| end | |
| # Set default quality or use specified one | |
| if set -q _flag_quality | |
| set quality $_flag_quality | |
| end | |
| # Set retry-streams delay if specified | |
| # https://streamlink.github.io/cli.html#cmdoption-default-stream | |
| if set -q _flag_retry | |
| set -a streamlink_options "--retry-streams=$_flag_retry" | |
| end | |
| # Handle output flag if specified, else use default naming convention | |
| if set -q _flag_output | |
| set -a streamlink_options "--output=$_flag_output" | |
| else | |
| set -a streamlink_options "--output=~/Movies/Streams/{author}-{time:%d%m%y}.ts" | |
| end | |
| # Add any additional arguments to streamlink options | |
| if test (count $argv) -gt 1 | |
| set -a streamlink_options $argv[2..-1] | |
| end | |
| # Find correct host | |
| set -l url | |
| if curl -sL --max-time 5 -w '%{http_code}' -o /dev/null "https://live.vkvideo.ru/$streamer_name" | string match -q '200' | |
| set url "https://live.vkvideo.ru/$streamer_name" | |
| else | |
| set url "https://twitch.tv/$streamer_name" | |
| end | |
| if set -q _flag_debug # Is debug mode | |
| echo "Executing: $app $streamlink_options $url $quality" | |
| else | |
| caffeinate & # Run caffeinate in the background | |
| set -l caffeinate_pid $last_pid # Capture the PID of caffeinate | |
| $app $streamlink_options $url $quality | |
| kill $caffeinate_pid # Kill caffeinate once the main task is done | |
| end | |
| end | |
| # Add completions | |
| complete -c rt --no-files -a ' | |
| cymanneth | |
| dreadztv | |
| vikared | |
| f1ashko | |
| kseniyasergeevna | |
| kati | |
| juliafareast | |
| swetik_ | |
| ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment