From 79201f0975cb481aecf7efafdfa40399cd21b506 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Fri, 27 Nov 2020 19:47:48 -0600 Subject: [PATCH] Replace gendl with curl --- gendl | 155 --------------------------------------------------------- mp | 124 --------------------------------------------- wyrics | 4 +- 3 files changed, 2 insertions(+), 281 deletions(-) delete mode 100755 gendl delete mode 100755 mp diff --git a/gendl b/gendl deleted file mode 100755 index 0013f4a..0000000 --- a/gendl +++ /dev/null @@ -1,155 +0,0 @@ -#!/bin/sh -############################## -# name: gendl -# lisc: gnu gplv3 -# desc: download to stdout or -# file, independent of -# a specific downloader. -# ftp/wget/curl support. -# main: jadedctrl -############################## - -# usage: gendl [-o output] url - - - -#--------------------------------------- -# backend bits - -# NIL --> STRING -# return the download program you're using -function download_program -{ - programs="ftp curl wget" - current="" - - for program in $programs - do - if whereis $program > /dev/null - then - current=$program - fi - done - - if uname -s | grep -e "LibertyBSD" -e "OpenBSD" > /dev/null - then - current="ftp" - fi - - echo "$current" -} - -# STRING PATH --> NIL -# download URL $1 to stdout -function download_stdout -{ - program=$(download_program) - url=$1 - - case "$program" in - "ftp") - output="$(ftp -VMo- $url)" - ;; - "curl") - output="$(curl $url)" - ;; - "wget") - output="$(wget --quiet -O- $url)" - ;; - esac - - return_code=$? - - echo "$output" - return $return_code -} - -# STRING PATH --> NIL -# download URL $1 to path $2 -function download_file -{ - program=$(download_program) - url=$1 - path=$2 - - case "$program" in - "ftp") - ftp -VMU "." -o $path $url - ;; - "curl") - curl -o $path $url - ;; - "wget") - wget --quiet -O $path $url - ;; - esac - - return_code=$? - - if test $return_code -ne 0 2>/dev/null - then - rm $path 2> /dev/null - # for consistency in behavior; wget saves 404s anyway, whereas - # ftp doesn't save anything from 404s, etc. - fi - - return $return_code -} - - - -# -------------------------------------- -# front-end string-manip - -# STRING --> STRING -# return the last word in a string -function last_word -{ - string="$1" - - echo "$string" \ - | rev \ - | sed 's% .*%%' \ - | rev -} - -function usage -{ - echo "usage: gendl [-o output] URL" -} - - - -# -------------------------------------- -# invocation - -args="$(getopt o: $*)" -if test -z "$@" 2>/dev/null -then - usage - exit 2 -fi - - -set -- $args -while test $# -ne 0 -do - case "$1" - in - -o) - download_path="$2"; shift; shift;; - --) - shift; break;; - esac -done - - -url="$(last_word "$@")" - - -if test -n "$download_path" 2> /dev/null -then - download_file $url $download_path -else - download_stdout "$url" -fi diff --git a/mp b/mp deleted file mode 100755 index 40c4ebb..0000000 --- a/mp +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh -######################################## -# name: mp -# desc: front-end to MPV that displays -# lyrics text-files before playing -# a song. -# main: Jenga Phoenix -# -# lisc: CC 0 -######################################## - -ARGUMENTS='--vo null --term-osd-bar' -trap "" 2 - - -#--------------------------------------- -# generic - -# STRING --> STRING -# Return the first 'word' (space-delimiter) of a string. -function car { - local string="$1" - - echo "$string" \ - | awk '{ print $1 }' -} - -# STRING --> STRING -# Return all words after the first word of a string. -function cdr { - local string="$1" - - local car="$(car "$string")" - - if test $(length "$string") -eq 1; then - echo "" - else - echo "$string" \ - | sed 's/^'"$car"' //' - fi -} - -# STRING --> NUMBER -# Return the length of a string. -function length { - local string="$1" - - echo "$string" \ - | wc -w \ - | tr -d ' ' -} - -# NUMBER NUMBER --> NUMBER -# Add two numbers together. -function add { - operator="$1" - operatee="$2" - - echo "$1 + $2" \ - | bc -} - - - -# -------------------------------------- - -# NIL --> NUMBER -# Return the amount of total items. -function total_items { - add "$(length "$DISCARD")" "$(length "$ITEMS")" -} - -# NIL --> NUMBER -# Return the amount of discarded items. -function discarded_items { - echo "$(length "$DISCARD")" -} - - - -# -------------------------------------- - -# NUMBER --> NIL -# Handle the return code of `mpv` properly, according -# to the cause. -function handle_return { - local return=$1 - - case $return in - 4) # ^C - # rewind one file << - ITEMS="$(car "$DISCARD") $ITEMS" - DISCARD="$(cdr "$DISCARD")" - ;; - 0) # normal - # put current file to discard - DISCARD="$(car "$ITEMS") $DISCARD" - ITEMS="$(cdr "$ITEMS")" - ;; - 2) # no file - # don't even discard it-- BURN IT - ITEMS="$(cdr "$ITEMS")" - ;; - esac -} - - - -# -------------------------------------- -# invocation - -DISCARD="" -ITEMS="$@" - -while test -n "$ITEMS"; do - local item="$(car "$ITEMS")" - - cat "${item}.txt" 2> /dev/null - echo "===$(add $(discarded_items) 1)/$(total_items)===" - eval "mpv ${ARGUMENTS} ${item}" - - return=$? - handle_return "$return" -done diff --git a/wyrics b/wyrics index 2ca47d4..39bb0cf 100755 --- a/wyrics +++ b/wyrics @@ -71,7 +71,7 @@ function search { local query="$1" local query="$(echo "$query" | sed 's/ /+/g')" - gendl "https://songlyrics.com/index.php?section=search&searchW=${query}" \ + curl -Ls "https://songlyrics.com/index.php?section=search&searchW=${query}" \ | sed '1,/serpresult/d' \ | grep "title=" \ | grep -v "/d' \ | sed '/<\/div>/,$d' \ | blank_lines \