Compare commits
2
Commits
07712d1ad4
...
1ae30d54b1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ae30d54b1 | ||
|
|
62e3d3f5e5 |
@@ -99,37 +99,6 @@ shuffle() {
|
|||||||
echo "$1" | fold -w 1 | shuf | tr -d '\n'
|
echo "$1" | fold -w 1 | shuf | tr -d '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
stream() {
|
|
||||||
channel="$1"
|
|
||||||
quality="$2"
|
|
||||||
lowLatency="$3"
|
|
||||||
|
|
||||||
if [ -z "$quality" ]; then
|
|
||||||
streamlink --quiet --config "/dev/null" "https://twitch.tv/$1"
|
|
||||||
[ "$?" -ne 0 ] && return 1
|
|
||||||
|
|
||||||
printf "Select stream quality: "
|
|
||||||
read -r quality
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$lowLatency" ]; then
|
|
||||||
arguments="\
|
|
||||||
--twitch-low-latency \
|
|
||||||
--player-args '--cache=yes --demuxer-max-bytes=750k' \
|
|
||||||
"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Starting stream https://twitch.tv/$channel @ $quality"
|
|
||||||
command="setsid -f streamlink \
|
|
||||||
--twitch-disable-hosting \
|
|
||||||
--twitch-disable-reruns \
|
|
||||||
--player mpv \
|
|
||||||
--stream-sorting-excludes '<480p,>=1080p' \
|
|
||||||
$arguments \
|
|
||||||
https://twitch.tv/$channel $quality > /dev/null 2>&1"
|
|
||||||
eval "$command"
|
|
||||||
}
|
|
||||||
|
|
||||||
update_mirrorlist() {
|
update_mirrorlist() {
|
||||||
sudo rm /etc/pacman.d/mirrorlist.pacnew
|
sudo rm /etc/pacman.d/mirrorlist.pacnew
|
||||||
sudo reflector --latest 100 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
|
sudo reflector --latest 100 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
|
||||||
|
|||||||
+188
-55
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
PIPE="$XDG_CACHE_HOME/mpv/umpv_fifo"
|
# Depends: GNU getopt, mpv, socat, streamlink
|
||||||
|
|
||||||
|
SOCK="/tmp/umpv-fifo"
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
B=$(tput bold)
|
B=$(tput bold)
|
||||||
@@ -16,99 +18,230 @@ ${B}SYNOPSIS${N}
|
|||||||
|
|
||||||
${B}DESCRIPTION${N}
|
${B}DESCRIPTION${N}
|
||||||
play is a script to manage different mpv viewing bahavior.
|
play is a script to manage different mpv viewing bahavior.
|
||||||
If no ${U}URLS${N} argument is provided, it is read from clipboard instead.
|
If no ${U}URLS${N} argument is provided, it is read from the clipboard instead.
|
||||||
The queue option starts a mpv window with a playlist, which all videos of
|
The queue option starts a mpv window with a playlist, which all videos of
|
||||||
subsequent queue calls get added to.
|
subsequent queue calls get added to.
|
||||||
|
|
||||||
${B}OPTIONS${N}
|
${B}OPTIONS${N}
|
||||||
${B}help${N}
|
${B}-h${N}, ${B}--help${N}
|
||||||
Display usage message and exit.
|
Display usage message and exit.
|
||||||
|
|
||||||
[${B}play${N}] [${U}URLS${N}...] (default)
|
${B}-q${N}, ${B}--quality${N} ${U}QUALITY${N}
|
||||||
Plays videos in a new mpv window.
|
Set the video quality, example: ${U}720p60${N}.
|
||||||
|
|
||||||
${B}shuffle${N} [${U}URLS${N}...]
|
${B}-f${N}, ${B}--shuffle${N} [${U}URLS${N}...]
|
||||||
Shuffle audio playlist (disables video playback).
|
Shuffle audio playlist (disables video playback).
|
||||||
|
|
||||||
${B}queue${N} [${U}URLS${N}...]
|
${B}-q${N}, ${B}--queue${N} [${U}URLS${N}...]
|
||||||
Add multiple videos to the unique mpv's queue.
|
Add multiple videos to the unique mpv's queue.
|
||||||
|
|
||||||
|
${B}-s${N}, ${B}--stream${N} [${U}URLS${N}...]
|
||||||
|
Play video(s) using streamlink.
|
||||||
|
|
||||||
|
${B}-l${N}, ${B}--low-latency${N}
|
||||||
|
Enable twitch low-latency mode in streamlink.
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
CLIP="$(xclip -se c -o)"
|
# --------------------------------------
|
||||||
|
|
||||||
|
qualityFormat() {
|
||||||
|
# , separator = download several formats
|
||||||
|
# + separator = merge several formats into a single file
|
||||||
|
# / separator = or
|
||||||
|
if [ -z "$quality" ]; then
|
||||||
|
echo "bestvideo[height<=?1080]+bestaudio/best"
|
||||||
|
else
|
||||||
|
height="$(echo "$quality" | awk -F 'p' '{ print $1 }')"
|
||||||
|
fps="$(echo "$quality" | awk -F 'p' '{ print $2 }')"
|
||||||
|
|
||||||
|
format="bestvideo[height<=?$height]"
|
||||||
|
if [ -n "$fps" ]; then
|
||||||
|
format="${format}[fps<=?$fps]"
|
||||||
|
fi
|
||||||
|
format="$format+bestaudio/best"
|
||||||
|
|
||||||
|
echo "$format"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
play() {
|
play() {
|
||||||
MPV="mpv --ytdl-raw-options=external-downloader=aria2c"
|
url="$1"
|
||||||
if [ -z "$1" ]; then
|
|
||||||
MPV="$MPV $CLIP"
|
|
||||||
# Cut off everything after space
|
|
||||||
LINK="$(echo "$CLIP" | sed -nE 's/^(\S+).*/\1/p')"
|
|
||||||
else
|
|
||||||
MPV="$MPV $*"
|
|
||||||
# Determain which argument holds the urls
|
|
||||||
[ "$1" = "${1#-}" ] && DISPLAY="$1" || DISPLAY="$2"
|
|
||||||
# Cut off everything after space
|
|
||||||
LINK="$(echo "$DISPLAY" | sed -nE 's/^(\S+).*/\1/p')"
|
|
||||||
fi
|
|
||||||
|
|
||||||
notify-send -t 2500 "Loading video: $LINK"
|
notify-send -t 2500 "Loading video: $url"
|
||||||
# Attempt to load video
|
setsid -f mpv --no-terminal \
|
||||||
[ "$($MPV)" ] && notify-send -u critical -t 4000 "Loading video failed.."
|
--ytdl-format="$(qualityFormat)" \
|
||||||
|
--ytdl-raw-options=add-metadata=,external-downloader=aria2c \
|
||||||
|
"$url"
|
||||||
}
|
}
|
||||||
|
|
||||||
shuffle() {
|
shuffle() {
|
||||||
# Skip first argument
|
urls="$*"
|
||||||
shift 1
|
|
||||||
mpv --no-video --shuffle \
|
mpv --no-video --shuffle \
|
||||||
--ytdl-format='bestaudio[ext=m4a]' \
|
--ytdl-format='bestaudio[ext=m4a]' \
|
||||||
--ytdl-raw-options='external-downloader=aria2c' \
|
--ytdl-raw-options=add-metadata=,external-downloader=aria2c \
|
||||||
"${@:-$CLIP}"
|
"$urls"
|
||||||
}
|
}
|
||||||
|
|
||||||
queue() {
|
queue() {
|
||||||
OPTIONS="--no-terminal --force-window --input-file=$PIPE --ytdl-raw-options=external-downloader=aria2c"
|
urls="$*"
|
||||||
|
|
||||||
|
options="--no-terminal --force-window --input-ipc-server=$SOCK"
|
||||||
|
|
||||||
# Create mpv cache directory
|
# Create mpv cache directory
|
||||||
DIR="$(dirname "$PIPE")"
|
dir="$(dirname "$SOCK")"
|
||||||
[ ! -d "$DIR" ] && mkdir -p "$DIR"
|
[ ! -d "$dir" ] && mkdir -p "$dir"
|
||||||
|
|
||||||
# Delete named pipe if no umpv is running
|
# Delete socket if no umpv is running
|
||||||
if ! pgrep -f "mpv $OPTIONS" > /dev/null; then
|
if ! pgrep -f "mpv $options" > /dev/null; then
|
||||||
rm -f "$PIPE"
|
rm -f "$SOCK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Skip first argument
|
if [ -S "$SOCK" ]; then
|
||||||
shift 1
|
|
||||||
# Set url to argument if provided, clipboard otherwise
|
|
||||||
URLS="${*:-$CLIP}"
|
|
||||||
|
|
||||||
if [ -p "$PIPE" ]; then
|
|
||||||
notify-send -t 2500 "Added video to queue.."
|
notify-send -t 2500 "Added video to queue.."
|
||||||
# Add video to named pipe
|
# Add video to named pipe
|
||||||
echo "$URLS" \
|
echo "$urls" | awk -v RS=' ' '{ print "raw loadfile "$1" append" }' \
|
||||||
| awk -v RS=' ' '{ print "raw loadfile "$1" append" }' > "$PIPE"
|
| socat UNIX-CONNECT:"$SOCK" -
|
||||||
else
|
else
|
||||||
# Create named pipe
|
|
||||||
mkfifo "$PIPE"
|
|
||||||
|
|
||||||
# Play video
|
# Play video
|
||||||
play "$OPTIONS" "$URLS"
|
notify-send -t 2500 "Loading video: $urls"
|
||||||
|
# shellcheck disable=2086
|
||||||
rm -f "$PIPE"
|
setsid -f mpv $options \
|
||||||
|
--ytdl-format="$(qualityFormat)" \
|
||||||
|
--ytdl-raw-options=add-metadata=,external-downloader=aria2c \
|
||||||
|
$urls
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
stream() {
|
||||||
help)
|
channel="$1"
|
||||||
|
quality="$2"
|
||||||
|
lowLatency="$3"
|
||||||
|
|
||||||
|
if [ -z "$quality" ]; then
|
||||||
|
if ! streamlink --quiet --config /dev/null "$channel"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Select stream quality: "
|
||||||
|
read -r quality
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$lowLatency" ]; then
|
||||||
|
arguments="\
|
||||||
|
--twitch-low-latency \
|
||||||
|
--player-args '--cache=yes --demuxer-max-bytes=750k'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting stream $channel @ $quality"
|
||||||
|
command="setsid -f streamlink \
|
||||||
|
--twitch-disable-hosting \
|
||||||
|
--twitch-disable-reruns \
|
||||||
|
--player mpv \
|
||||||
|
--stream-sorting-excludes '<480p,>=1080p' \
|
||||||
|
$arguments \
|
||||||
|
$channel $quality > /dev/null 2>&1"
|
||||||
|
eval "$command"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Option parsing
|
||||||
|
# --------------------------------------
|
||||||
|
|
||||||
|
script="$(basename "$0")"
|
||||||
|
parsed="$(getopt --options "hslquf" \
|
||||||
|
--longoptions "help,stream,quality,queue,shuffle" \
|
||||||
|
-n "$script" -- "$@" 2>&1)"
|
||||||
|
result="$?"
|
||||||
|
|
||||||
|
# Exit if invalid option is provided
|
||||||
|
if [ "$result" -ne 0 ]; then
|
||||||
|
echo "$parsed" | head -n 1 >&2
|
||||||
|
echo "Try './$script --help' for more information." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
eval set -- "$parsed"
|
||||||
|
|
||||||
|
streamOption=0
|
||||||
|
qualityOption=0
|
||||||
|
lowLatencyOption=0
|
||||||
|
queueOption=0
|
||||||
|
shuffleOption=0
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h | --help)
|
||||||
help
|
help
|
||||||
|
exit
|
||||||
;;
|
;;
|
||||||
shuffle)
|
-s | --stream)
|
||||||
shuffle "$@"
|
streamOption=1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
queue)
|
-l | --low-latency)
|
||||||
queue "$@"
|
lowLatencyOption=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-q | --quality)
|
||||||
|
qualityOption=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-u | --queue)
|
||||||
|
queueOption=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-f | --shuffle)
|
||||||
|
shuffleOption=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
play "$@"
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Target parsing
|
||||||
|
# --------------------------------------
|
||||||
|
|
||||||
|
# Incompatible flags
|
||||||
|
result=$((streamOption + queueOption + shuffleOption))
|
||||||
|
if [ $result -gt 1 ]; then
|
||||||
|
echo "Incompatible flags." >&2
|
||||||
|
echo "Try './$script --help' for more information." >&2
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get quality
|
||||||
|
if [ $qualityOption -eq 1 ]; then
|
||||||
|
quality="$1"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set url to clipboard if none provided
|
||||||
|
clip="$(xclip -selection clipboard -out)"
|
||||||
|
if [ "$#" -eq 0 ]; then
|
||||||
|
eval set -- "$clip"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ $lowLatencyOption -eq 1 ] && lowLatency="1"
|
||||||
|
|
||||||
|
# Execute
|
||||||
|
# --------------------------------------
|
||||||
|
|
||||||
|
if [ $streamOption -eq 1 ]; then
|
||||||
|
for url in "$@"; do
|
||||||
|
stream "$url" "$quality" "$lowLatency"
|
||||||
|
done
|
||||||
|
elif [ $shuffleOption -eq 1 ]; then
|
||||||
|
shuffle "$*"
|
||||||
|
elif [ $queueOption -eq 1 ]; then
|
||||||
|
queue "$*"
|
||||||
|
else
|
||||||
|
for url in "$@"; do
|
||||||
|
play "$url"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user