From 277432053d8d4cffbfe0e45cb7a2dfbab77af8a3 Mon Sep 17 00:00:00 2001 From: Jade Levesque Date: Sat, 7 Jan 2017 11:07:16 -0600 Subject: [PATCH] Add playlist search support --- lib/yt-search | 63 +++++++++++++++++++++++++++------------------------ shelltube | 12 +++++++--- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/lib/yt-search b/lib/yt-search index 477cabf..4f16c9e 100755 --- a/lib/yt-search +++ b/lib/yt-search @@ -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/.* $output + 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/.* $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/.*&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' diff --git a/shelltube b/shelltube index 11cc7e9..ca9950c 100755 --- a/shelltube +++ b/shelltube @@ -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 }