Update play-lofi
This commit is contained in:
parent
9bb3049dd8
commit
66b4328a30
25
play-lofi
25
play-lofi
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# Copyright (C) 2020 Ortega Froysa, Nicolás <nicolas@ortegas.org> All rights reserved.
|
# Copyright (C) 2020 Ortega Froysa, Nicolás <nicolas@ortegas.org> All rights reserved.
|
||||||
# Author: Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
# Author: Ortega Froysa, Nicolás <nicolas@ortegas.org>
|
||||||
#
|
#
|
||||||
@ -37,16 +37,17 @@ Commands:
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_link() {
|
new_link() {
|
||||||
local results=$(curl -s "https://invidio.us/search?q=lofi+radio" |
|
local results
|
||||||
|
results=$(curl -s "https://invidious.tube/search?q=lofi+radio" |
|
||||||
grep "<p>.*watch" | tr -d "\n" | tr -s " ")
|
grep "<p>.*watch" | tr -d "\n" | tr -s " ")
|
||||||
results=${results//\<p\>\<a href\=\"/\"https:\/\/invidio.us}
|
results=${results//\<p\>\<a href\=\"/\"https:\/\/invidious.tube}
|
||||||
results=${results//\"\>/\" \"}
|
results=${results//\"\>/\" \"}
|
||||||
results=${results//\<\/a\>\<\/p\>/\" þ }
|
results=${results//\<\/a\>\<\/p\>/\" þ }
|
||||||
results=${results::-2} # remove that last separator
|
results=${results::-2} # remove that last separator
|
||||||
|
|
||||||
# NOTE: I chose þ because never in a million years will that
|
# NOTE: I chose þ because never in a million years will that
|
||||||
# character be in the title of a lofi video stream.
|
# character be in the title of a lofi video stream.
|
||||||
IFS="þ" read -r -a streams <<< $results
|
IFS="þ" read -r -a streams <<< "$results"
|
||||||
|
|
||||||
echo "Streams:"
|
echo "Streams:"
|
||||||
local id=1
|
local id=1
|
||||||
@ -60,12 +61,12 @@ new_link() {
|
|||||||
while [ "$opt" -gt "${#streams[@]}" ] || [ "$opt" -lt "1" ]
|
while [ "$opt" -gt "${#streams[@]}" ] || [ "$opt" -lt "1" ]
|
||||||
do
|
do
|
||||||
printf "Selection: "
|
printf "Selection: "
|
||||||
read opt
|
read -r opt
|
||||||
done
|
done
|
||||||
link=${streams[$opt]}
|
link=${streams[$opt]}
|
||||||
link=${link//\" \"*/}
|
link=${link//\" \"*/}
|
||||||
link=${link//*\"/}
|
link=${link//*\"/}
|
||||||
echo $link > $link_file
|
echo "$link" > "$link_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
# argument parsing
|
# argument parsing
|
||||||
@ -85,7 +86,7 @@ elif [ "$#" -eq "2" ]
|
|||||||
then
|
then
|
||||||
if [ "$1" = "set" ]
|
if [ "$1" = "set" ]
|
||||||
then
|
then
|
||||||
echo "$2" > $link_file
|
echo "$2" > "$link_file"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo "Unknown command '$1 $2'. Run 'play-lofi help' for a list of commands."
|
echo "Unknown command '$1 $2'. Run 'play-lofi help' for a list of commands."
|
||||||
@ -104,28 +105,28 @@ then
|
|||||||
while [ "$option" != "y" ] && [ "$option" != "n" ]
|
while [ "$option" != "y" ] && [ "$option" != "n" ]
|
||||||
do
|
do
|
||||||
printf "Would you like to create one? [y/n] "
|
printf "Would you like to create one? [y/n] "
|
||||||
read option
|
read -r option
|
||||||
done
|
done
|
||||||
[ "$option" = "n" ] && exit 1
|
[ "$option" = "n" ] && exit 1
|
||||||
new_link
|
new_link
|
||||||
echo "New link file created."
|
echo "New link file created."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
link=$(cat $link_file)
|
link=$(cat "$link_file")
|
||||||
|
|
||||||
# check if video is available
|
# check if video is available
|
||||||
output=$(curl -s $link | grep "This video is unavailable.")
|
output=$(curl -s "$link" | grep "This video is unavailable.")
|
||||||
if [ -n "$output" ]
|
if [ -n "$output" ]
|
||||||
then
|
then
|
||||||
echo "The stream link '$link' is unavailable."
|
echo "The stream link '$link' is unavailable."
|
||||||
while [ "$option" != "y" ] && [ "$option" != "n" ]
|
while [ "$option" != "y" ] && [ "$option" != "n" ]
|
||||||
do
|
do
|
||||||
printf "Would you like to find a new one? [y/n] "
|
printf "Would you like to find a new one? [y/n] "
|
||||||
read option
|
read -r option
|
||||||
done
|
done
|
||||||
[ "$option" = "n" ] && exit 1
|
[ "$option" = "n" ] && exit 1
|
||||||
new_link
|
new_link
|
||||||
echo "New link saved."
|
echo "New link saved."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mpv --no-video --msg-level=ffmpeg=no $link
|
mpv --no-video --msg-level=ffmpeg=no "$link"
|
||||||
|
Loading…
Reference in New Issue
Block a user