Add playlist search support

This commit is contained in:
Jaidyn Ann 2017-01-07 11:07:16 -06:00
parent 628c4be558
commit 277432053d
2 changed files with 43 additions and 32 deletions

View File

@ -61,7 +61,12 @@ function get_input() {
get_input get_input
elif [ $n -gt 0 ] && [ $n -lt 20 ] elif [ $n -gt 0 ] && [ $n -lt 20 ]
then then
if sed -n ${n}p $temp_file | grep "View full playlist" > /dev/null
then
sed -n ${n}p $temp_file | sed 's/.*&list=//' | sed 's/".*//' > $output
else
sed -n ${n}p $temp_file | sed 's/.*<a href="\/watch?v=//' | sed 's/".*//' > $output sed -n ${n}p $temp_file | sed 's/.*<a href="\/watch?v=//' | sed 's/".*//' > $output
fi
else else
echo "Bad input, mate. Type in a valid number or 'exit'." echo "Bad input, mate. Type in a valid number or 'exit'."
get_input get_input
@ -107,6 +112,7 @@ do
type="Playlist" type="Playlist"
title=$(echo "$LINE" | sed 's/.*title="//' | sed 's/".*//') title=$(echo "$LINE" | sed 's/.*title="//' | sed 's/".*//')
items=$(echo "$LINE" | sed 's/.*View full playlist (//' | sed 's/).*//') items=$(echo "$LINE" | sed 's/.*View full playlist (//' | sed 's/).*//')
itemid=$(echo "$LINE" | sed 's/.*&amp;list=//' | sed 's/".*//')
if [ $item_num -ge $((results+1)) ] if [ $item_num -ge $((results+1)) ]
then then
break break
@ -118,8 +124,7 @@ do
fi fi
printf '%s\n' "$title" printf '%s\n' "$title"
printf ' ' printf ' '
printf '%s | %s\n' "$type" "$items" printf '%s | %s | %s\n' "$type" "$items" "$itemid"
printf ' '
else else
type="Video" type="Video"
duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//') duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//')
@ -145,7 +150,6 @@ do
fi fi
printf '%s\n' "$title" printf '%s\n' "$title"
printf ' ' printf ' '
fi
i=0 i=0
while [ $i -lt 16 ] while [ $i -lt 16 ]
do do
@ -172,6 +176,7 @@ do
fi fi
done done
printf ' | %s\n' "$itemid" printf ' | %s\n' "$itemid"
fi
done done
printf '\033[0m' printf '\033[0m'

View File

@ -39,8 +39,13 @@ fi
search() { search() {
output="$(mktemp -u /tmp/yt_XXXXXX)" output="$(mktemp -u /tmp/yt_XXXXXX)"
yt-search -i "$1" "$output" yt-search -i "$1" "$output"
if grep "^PL" "$output" > /dev/null
then
playlist "$(cat "$output")"
else
selected_video="$(cat "$output")" selected_video="$(cat "$output")"
yt-meta "$selected_video" yt-meta "$selected_video"
fi
} }
playlist() { playlist() {
@ -151,7 +156,8 @@ parse() {
;; ;;
'' ) ;; '' ) ;;
* ) * )
printf 'unknown command: "%s"\ntry "help"\n' "$command" echo "Unknown command: \"$command\""
echo "Try \"help\" or \"?\""
;; ;;
esac esac
} }