From 1aadacde298cb33af304462e75f88d2d6feccd17 Mon Sep 17 00:00:00 2001 From: Bo Ørsted Andresen Date: Wed, 16 Dec 2009 18:18:42 +0000 Subject: Fix tinyurl handling so it uses the api. Make it require exactly one argument as --help suggests. The API is described at: http://www.scripting.com/stories/2007/06/27/tinyurlHasAnApi.html --- wgetpaste | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/wgetpaste b/wgetpaste index eb8eddc..7c049fb 100755 --- a/wgetpaste +++ b/wgetpaste @@ -29,7 +29,7 @@ ENGINE_osl=osl URL_osl="http://pastebin.osuosl.org/ pastebin.php" # tinyurl ENGINE_tinyurl=tinyurl -URL_tinyurl="http://tinyurl.com/ create.php" +URL_tinyurl="http://tinyurl.com/ api-create.php" ### engines # ca @@ -66,9 +66,6 @@ EXPIRATIONS_osl="Never 1%day 1%month" EXPIRATION_VALUES_osl="f d m" POST_osl="paste=Send poster % format expiry % code2" REGEX_RAW_osl='s|^\(http://[^/]*/\)\([0-9]*\)$|\1pastebin.php?dl=\2|' -# tinyurl -POST_tinyurl="submit=Make+TinyURL! % % % % % url" -REGEX_URL_tinyurl='s|^$|\1|p' ### errors die() { @@ -525,7 +522,10 @@ while [[ -n $1 ]]; do TEE=0 ;; -u | --tinyurl ) + requiredarg "$@" SERVICE=tinyurl + SOURCE="url" + INPUTURL="$1" ;; -v | --verbose ) VERBOSE=0 @@ -656,6 +656,9 @@ fi # read input case "$SOURCE" in + url ) + INPUT="${INPUTURL}" + ;; command ) for c in "${COMMANDS[@]}"; do if [[ $TEE ]]; then @@ -731,6 +734,9 @@ warnings >&2 # set recipient RECIPIENT=$(getrecipient RAW) +if [[ $SERVICE == tinyurl ]]; then + URL=$(LC_ALL=C wget -qO - "$RECIPIENT?url=$INPUT") +else # create temp file (wget is much more reliable reading # large input via --post-file rather than --post-data) [[ -f $TMPF ]] || TMPF=$(mktemp /tmp/wgetpaste.XXXXXX) @@ -762,6 +768,7 @@ RECIPIENT=$(getrecipient RAW) # get the url URL=$(geturl "$OUTPUT") +fi # verify that the pastebin service did not return a known error url such as toofast.html from rafb verifyurl -- cgit v1.2.3