diff --git a/yt-desc b/yt-desc index 7d439ed..ff216f6 100755 --- a/yt-desc +++ b/yt-desc @@ -1,3 +1,4 @@ +#!/bin/sh ############################## # name: yt-desc # lisc: gnu gplv3 @@ -7,33 +8,37 @@ # Usage: yt-desc "$url/id" +# STRING --> STRING +# Get the description of a YT video, from HTML. +function video_desc { + local html="$1" + + echo "$html" \ + | grep "action-panel-details" \ + | sed 's/.*

//' \ + | sed 's%

.*%%' \ + | lynx -stdin -dump \ + | sed 's/^ //' +} + # -------------------------------------- # invocation -USAGE="usage: yt-desc url/id" - -if test -z "$1" -then - echo "$USAGE" +function usage { + echo "usage: yt-desc url/id" exit 2 -fi - -if test -n "$1"; then - if echo "$1" | grep "youtube"; then - URL="$1" - else - URL="https://www.youtube.com/watch?v=${1}" - fi -fi - - +} # -------------------------------------- -# invocation <3 -gendl "$URL" \ -| grep "action-panel-details" \ -| sed 's/.*

//' \ -| sed 's%

.*%%' \ -| lynx -stdin -dump \ -| sed 's/^ //' +if test -z "$1"; then + usage +elif echo "$1" | grep "youtube" > /dev/null; then + URL="$1" +else + URL="https://www.youtube.com/watch?v=${1}" +fi + +# -------------------------------------- + +video_desc "$(gendl "$URL")" diff --git a/yt-search b/yt-search index 6f9a31b..2dc1cf8 100755 --- a/yt-search +++ b/yt-search @@ -1,3 +1,4 @@ +#!/bin/sh ############################## # name: yt-search # lisc: gnu gplv3 @@ -12,8 +13,7 @@ # NUMBER NUMBER --> NUMBER # Well, subtraction. Y'know... -function subtract -{ +function subtract { local operated=$1 local operatee=$2 echo "${1}-${2}" | bc @@ -26,29 +26,25 @@ function subtract # NIL --> STRING # Print an ANSI "unbold" escape string. -function unbold -{ +function unbold { printf "$(tput sgr0)" } # STRING --> STRING # Print an ANSI "bold" escape string. -function bold -{ +function bold { printf "$(tput bold)" } # STRING --> NUMBER # Return the length of a string -function char_length -{ +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 -{ +function min_string_length { local string="$1" local length=$2 if test -z "$3"; then @@ -69,8 +65,7 @@ function min_string_length # STRING NUMBER --> STRING # get the first $2 characters in string $1 -function char_get -{ +function char_get { local number=$2 local string="$1" string="$(min_string_length "$string" $number " ")" @@ -85,8 +80,7 @@ function char_get # STRING --> STRING # Pass the raw search HTML, get raw video result-lines -function 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 -{ +function result_id { local result_line="$1" echo "$result_line" \ | sed 's%.* STRING # Return the title of a result-line. -function result_title -{ +function result_title { local result_line="$1" echo "$result_line" \ | sed 's%.*" title="%%' \ | sed 's%".*%%' } -function result_name -{ +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 -{ +function result_duration { local result_line="$1" echo "$result_line" \ | sed 's%.*> - Duration: %%' \ @@ -149,8 +131,7 @@ function result_duration # STRING --> STRING # Return the .yt-lockup-meta-info