bash/fedilives/peertube.sh
cheesus_crust 9581bcc174 lets
2023-02-14 21:22:28 +03:00

60 lines
1.2 KiB
Bash

#!/usr/bin/env bash
: "${1?How to use: $0 PT_VIDEO_LINK}"
link="$1"
### Get HTML
wget "$link" -O /tmp/videohtml
### Variables
videolink=$( grep "meta property" /tmp/videohtml | grep "og:video:url" \
| sed 's/.*href="//' | sed 's#" />##')
chatver=$( grep 'peertube-plugin-livechat' /tmp/videohtml | grep 'version'\
| sed 's#.*npmName..:..peertube-plugin-livechat.....name..:..livechat.....version..:..##' \
| sed 's#.....description.....PeerTube plugin livechat: offers a way.*##' )
instance=$(echo "$videolink" | sed 's#https://##' | sed 's#/videos/watch/.*##')
videoid=$(echo $videolink | sed 's#.*videos/watch/##')
### Delete html
rm /tmp/videohtml
### Functions
function live()
{
xdg-open https://"$instance"/plugins/livechat/"$chatver"/router/webchat/room/"$videoid" &
mpv https://"$instance"/static/streaming-playlists/hls/"$videoid"/0.m3u8 &
exit 0
}
function nolive()
{
mpv --ytdl-format=best "$videolink"
exit 0
}
### Choose
echo
echo "Is it live? (Y/n)"
read -r is_live
echo
case "$is_live" in
"" | "y")
live
;;
"n")
nolive
;;
* )
echo "Ты, блять, дурак что ли? Белым по чёрному написано y или n"
;;
esac
exit 0