You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
1.7 KiB
88 lines
1.7 KiB
#!/usr/bin/env sh |
|
|
|
# include common definitions |
|
# shellcheck source=scripts/core/sxmo_common.sh |
|
. "$(dirname "$0")/sxmo_common.sh" |
|
|
|
HISTORY_FILE="$XDG_CACHE_HOME"/sxmo/youtubehistory.tsv |
|
AUDIOONLY=0 |
|
|
|
youtubesearch() { |
|
QUERY="$1" |
|
youtube-cli "$QUERY" | |
|
grep -Ev '^(Channelid|Atom feed|Channel title|Published|Viewcount|Userid):' | |
|
sed -E 's/^(URL|Duration):\s+/\t/g' | |
|
tr -d '\n' | |
|
sed 's/===/\n/g' | |
|
gawk -F'\t' '{ print $3 " " $1 " " $2}' |
|
} |
|
|
|
searchmenu() { |
|
HISTORY="$( |
|
tac "$HISTORY_FILE" | nl | sort -uk 2 | sort -k 1 | cut -f 2 | grep . | |
|
sed "s#^#History: #g" |
|
)" |
|
|
|
while true; do |
|
ENTRY="$( |
|
printf %b " |
|
Close Menu |
|
$HISTORY |
|
" | |
|
xargs -0 echo | |
|
sed '/^[[:space:]]*$/d' | |
|
awk '{$1=$1};1' | |
|
sxmo_dmenu_with_kb.sh -p "Yt Search" -c -l 10 |
|
)" |
|
|
|
if [ "Close Menu" = "$ENTRY" ]; then |
|
exit 0 |
|
else |
|
ENTRY="$(echo "$ENTRY" | sed 's#^History: ##')" |
|
printf %b "$ENTRY\n" >> "$HISTORY_FILE" |
|
youtubesearch "$ENTRY" | resultsmenu |
|
fi |
|
done |
|
} |
|
|
|
resultsmenu() { |
|
RESULTS="$(cat)" |
|
|
|
while true; do |
|
PICKED="$( |
|
printf %b " |
|
Close Menu\n |
|
Change Search\n |
|
$RESULTS |
|
" | |
|
xargs -0 echo | |
|
sed '/^[[:space:]]*$/d' | |
|
awk '{$1=$1};1' | |
|
dmenu -c -l 10 -p "Results" |
|
)" |
|
|
|
if [ "Change Search" = "$PICKED" ]; then |
|
return |
|
elif [ "Close Menu" = "$PICKED" ]; then |
|
exit 0 |
|
elif [ "$AUDIOONLY" = 1 ]; then |
|
URL="$(echo "$PICKED" | awk -F " " '{print $NF}')" |
|
sxmo_terminal.sh mpv -ao=alsa -v --no-video "$URL" & |
|
else |
|
URL="$(echo "$PICKED" | awk -F " " '{print $NF}')" |
|
sxmo_terminal.sh mpv -ao=alsa -v --ytdl-format='[height<420]' "$URL" & |
|
fi |
|
done |
|
} |
|
|
|
video() { |
|
AUDIOONLY=0 |
|
searchmenu |
|
} |
|
|
|
audio() { |
|
AUDIOONLY=1 |
|
searchmenu |
|
} |
|
|
|
"$@"
|
|
|