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
sed -n ${n}p $temp_file | sed 's/.*<a href="\/watch?v=//' | sed 's/".*//' > $output if sed -n ${n}p $temp_file | grep "View full playlist" > /dev/null
then
sed -n ${n}p $temp_file | sed 's/.*&amp;list=//' | sed 's/".*//' > $output
else
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,33 +150,33 @@ do
fi fi
printf '%s\n' "$title" printf '%s\n' "$title"
printf ' ' printf ' '
i=0
while [ $i -lt 16 ]
do
i=$((i+1))
char=$(echo $author | cut -c$i)
if [ -z $char ]
then
printf ' '
else
printf '%s' "$char"
fi fi
i=0 done
while [ $i -lt 16 ] printf ' | '
do i=0
i=$((i+1)) while [ $i -lt 5 ]
char=$(echo $author | cut -c$i) do
if [ -z $char ] i=$((i+1))
then char=$(echo $duration | cut -c$i)
printf ' ' if [ -z $char ]
else then
printf '%s' "$char" printf ' '
fi else
done printf '%s' "$char"
printf ' | ' fi
i=0 done
while [ $i -lt 5 ] printf ' | %s\n' "$itemid"
do fi
i=$((i+1))
char=$(echo $duration | cut -c$i)
if [ -z $char ]
then
printf ' '
else
printf '%s' "$char"
fi
done
printf ' | %s\n' "$itemid"
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"
selected_video="$(cat "$output")" if grep "^PL" "$output" > /dev/null
yt-meta "$selected_video" then
playlist "$(cat "$output")"
else
selected_video="$(cat "$output")"
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
} }