Last active
October 3, 2021 15:34
-
-
Save squaresmile/7395dec4cbcaec55b939464f9e2d8df2 to your computer and use it in GitHub Desktop.
Revisions
-
squaresmile renamed this gist
Oct 3, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
squaresmile created this gist
Oct 3, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ [Unit] Description=Save Twitch stream After=network.target [Service] WorkingDirectory=/home/squaresmile/twitch_streams ExecStart=/bin/bash /home/squaresmile/twitch_streams/save_stream.sh User=cereal [Install] WantedBy=multi-user.target 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ [Unit] Description=Check and save stream [Timer] OnCalendar=*-*-* *:00/15:00 RandomizedDelaySec=60 AccuracySec=1us [Install] WantedBy=timers.target 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #!/usr/bin/env bash set -e if [[ $(find . -name "*_.mp4" -printf '.' | wc -m) -ne "0" ]]; then exit 1 fi STREAM=$(date +"%Y_%m_%d_%H_%M_%S") echo "Saving stream $STREAM" streamlink https://www.twitch.tv/<twitch_username> -o "$STREAM"_.mp4 --twitch-disable-hosting \ --twitch-disable-ads --twitch-disable-reruns --retry-streams 60 --retry-max 5 || true if [ -f "$STREAM"_.mp4 ]; then # Some players (Chrome) can't play the original mp4 file from streamlink (probably because when the stream ends, strealink doesn't finish writing cleanly) # so we remux the file ffmpeg -i "$STREAM"_.mp4 -c: copy "$STREAM".mp4 rm "$STREAM"_.mp4 # Uncomment if you want to send a pushbullet notification on finish # curl -u <pushbullet_api_token>: https://api.pushbullet.com/v2/pushes -d type=note --data-urlencode title="$STREAM stream finished" fi