############################## # name: yt-search # lisc: gnu gplv3 # main: jadedctrl # desc: search youtube simply. ############################## # Usage: yt-search [-csmb] "$search_string" # -------------------------------------- # a bit of math... # NUMBER NUMBER --> NUMBER # Well, subtraction. Y'know... function subtract { local operated=$1 local operatee=$2 echo "${1}-${2}" | bc } # -------------------------------------- # ... now some string manip... # NIL --> STRING # Print an ANSI "unbold" escape string. function unbold { printf "$(tput sgr0)" } # STRING --> STRING # Print an ANSI "bold" escape string. function bold { printf "$(tput bold)" } # STRING --> NUMBER # Return the length of a string function char_length { subtract $(echo $1 | wc -c) 1 } # STRING NUMBER [STRING] --> STRING # pad string $1 out to the minimum length $2 with padding $3 (default: "0") function min_string_length { local string="$1" local length=$2 if test -z "$3"; then local padding="0" else local padding="$3" fi local new="$string" if test $(char_length $1) -eq $2; then echo $1 else while test $(char_length $new) -lt $2; do new="${new}${padding}" done echo $new fi } # STRING NUMBER --> STRING # get the first $2 characters in string $1 function char_get { local number=$2 local string="$1" string="$(min_string_length "$string" $number " ")" echo "$string" \ | grep -o "^$(min_string_length "." $number ".")" } # -------------------------------------- # ... now for the real deal~! # STRING --> STRING # Pass the raw search HTML, get raw video result-lines function result_lines { local search_html="$1" echo "$search_html" \ | grep " STRING # Return the video ID of a result_line. function result_id { local result_line="$1" echo "$result_line" \ | sed 's%.* STRING # Return the title of a result-line. function result_title { local result_line="$1" echo "$result_line" \ | sed 's%.*" title="%%' \ | sed 's%".*%%' } function result_name { local result_line="$1" local title="$(result_title "$result_line")" echo "$(bold)${title}$(unbold)" } function result_title_backup { local result_line="$1" echo "$result_line" \ | sed 's%.*title="%%' \ | sed 's%".*%%' } # STRING --> STRING # Return the duration of a result-line. function result_duration { local result_line="$1" echo "$result_line" \ | sed 's%.*> - Duration: %%' \ | sed 's%\..*%%' } # STRING --> STRING # Return the .yt-lockup-meta-info