v9
🧩 Syntax:
#!/bin/bash
# REQUIREMENTS
# curl - sudo apt install curl
# jq - sudo apt install jq
# mpv - sudo apt install mpv
# xbindkeys - sudo apt install xbindkeys
# ffmpeg - sudo apt install ffmpeg
# INSTRUCTIONS
# FILL IN refresh_token (only once)
# How to get it;
# https://files.catbox.moe/e3bg5m.png
refresh_token="APZUo0TVNv21VWf6ogcIIu3S43wXVJl8d-kA3f6ERL0Jf9WbiVKTJPRJnUkw8U5G5wnon-7Xp6fB12Nf4Di8j6r9zx6iROUH88RjtACd__-FL1CmPKY9CxOi70ReUzP-WMCTXDzmz2o9WgZLzhFJuygIgutimc9tmliOvZZ515vqxaN6u51gFQoFvwqFj58mGLcOXgTGO9CDHrIQxFWs-UXQ-tUCTpavVg"
if [ -z "$refresh_token" ]
then
echo "Add refresh_token"
exit
fi
# use the new refresh_token instead of above
if [ -f .refresh_token ]; then
refresh_token=$(cat .refresh_token)
fi
# get your access and refresh tokens
token_response=$(curl -s 'https://securetoken.googleapis.com/v1/token?key=AIzaSyBOOpV21k6o3cJc56-4uRNb0jDMzIxShMY' \
-X POST --data-raw 'grant_type=refresh_token&refresh_token='$refresh_token'' --compressed)
access_token=$(echo "$token_response" | jq -r '.access_token')
refresh_token=$(echo "$token_response" | jq -r '.refresh_token')
echo "$access_token" > .access_token
echo "$refresh_token" > .refresh_token
# function to launch the stream in mpv
launch_mpv() {
feed_token=$1
mpv --really-quiet --no-terminal --mute --profile=norm "https://customer-jwh6wms36w6479b4.cloudflarestream.com/$feed_token/manifest/video.m3u8?parentOrigin=https%3A%2F%2Fwww.fishtank.live" &
}
# function to record the stream with ffmpeg
record_stream() {
feed_token=$1
stream_url="https://customer-jwh6wms36w6479b4.cloudflarestream.com/$feed_token/manifest/video.m3u8?parentOrigin=https%3A%2F%2Fwww.fishtank.live"
filename="$(date +"%Y-%m-%d_%H-%M-%S")_$feed_token.mp4"
ffmpeg -hide_banner -loglevel warning -i "$stream_url" -c copy "$filename"
}
# get the list of live streams
live_streams=$(curl -s 'https://www.fishtank.live/api/live-streams' -H "AuthToken: $access_token" --compressed)
# extract the stream names and tokens
streams=$(echo "$live_streams" | jq -r '.liveStreams | .[] | "\(.name)|\(.url)"')
# array to keep track of running mpv instances
running_streams=()
# launch the streams in mpv
while read -r line; do
feed_token=$(echo "$line" | cut -d '|' -f2)
launch_mpv "$feed_token"
running_streams+=("$feed_token")
done <<< "$streams"
# function to check if a stream is running
is_running() {
feed_token=$1
for stream in "${running_streams[@]}"; do
if [ "$stream" == "$feed_token" ]; then
return 0
fi
done
return 1
}
# bind the hotkey CTRL+r to record the currently focused mpv instance
xbindkeys -f /dev/null - <<EOF
"ffmpeg -f x11grab -y -r 25 -s "$(xdotool getactivewindow getwindowgeometry | awk -F'[ x]+' '/W/ {print $4"x"$5