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
elif [ $n -gt 0 ] && [ $n -lt 20 ]
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
echo "Bad input, mate. Type in a valid number or 'exit'."
get_input
@ -107,6 +112,7 @@ do
type="Playlist"
title=$(echo "$LINE" | sed 's/.*title="//' | 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)) ]
then
break
@ -118,8 +124,7 @@ do
fi
printf '%s\n' "$title"
printf ' '
printf '%s | %s\n' "$type" "$items"
printf ' '
printf '%s | %s | %s\n' "$type" "$items" "$itemid"
else
type="Video"
duration=$(echo "$LINE" | sed 's/.*Duration: //' | sed 's/\..*//')
@ -145,33 +150,33 @@ do
fi
printf '%s\n' "$title"
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
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
done
printf ' | '
i=0
while [ $i -lt 5 ]
do
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
printf ' | '
i=0
while [ $i -lt 5 ]
do
i=$((i+1))
char=$(echo $duration | cut -c$i)
if [ -z $char ]
then
printf ' '
else
printf '%s' "$char"
fi
done
printf ' | %s\n' "$itemid"
fi
done
printf '\033[0m'

View File

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