URI: 
       reddit plumb script, support v.redd.it/id URLs - randomcrap - random crap programs of varying quality
  HTML git clone git://git.codemadness.org/randomcrap
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 79a3b9fc6d97a826ef369e6ff72c090a61743f7a
   DIR parent 89eb17624c7dd8ac457ce13f5f8d6722b2236a16
  HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sun, 31 May 2026 13:14:13 +0200
       
       reddit plumb script, support v.redd.it/id URLs
       
       Diffstat:
         M config/scripts/plumb/reddit.sh      |      24 +++++++++++++++++-------
       
       1 file changed, 17 insertions(+), 7 deletions(-)
       ---
   DIR diff --git a/config/scripts/plumb/reddit.sh b/config/scripts/plumb/reddit.sh
       @@ -5,7 +5,17 @@
        ua="Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0"
        
        arg="$1"
       -arg=$(printf '%s' "$arg" | sed -E 's@www.reddit.com@old.reddit.com@')
       +
       +url="$arg"
       +# v.redd.it/id -> old.reddit.com/video/id
       +if printf '%s' "$url" | grep -F -q '/v.redd.it/'; then
       +        url=$(printf '%s' "$url" | sed -E 's@/v\.redd\.it/@old.reddit.com/video/@')
       +fi
       +
       +url=$(printf '%s' "$url" | sed -E 's@www.reddit.com@old.reddit.com@')
       +
       +# DEBUG
       +#printf 'arg=%s, new url=%s\n' "$arg" "$url"
        
        cookiejar="/tmp/reddit_plumb_cookies.txt"
        
       @@ -17,7 +27,7 @@ getcookie() {
        
        # getjson(url)
        getjson() {
       -        curl -s -f -H "User-Agent: $ua" -b "$cookiejar" -c "$cookiejar" "$1"
       +        curl -L -s -f -H "User-Agent: $ua" -b "$cookiejar" -c "$cookiejar" "$1"
        }
        
        # parse JSON from stdin.
       @@ -38,16 +48,16 @@ END {
        
        # get cookie (by HTML page) if cookie do not exist.
        if ! test -s "$cookiejar"; then
       -        getcookie "$arg"
       +        getcookie "$url"
        fi
        
        tmp=$(mktemp)
       -url="${arg}.json"
       -if ! getjson "$url" > "$tmp"; then
       +jsonurl="${url}.json"
       +if ! getjson "$jsonurl" > "$tmp"; then
                # on failure, retry, cookie might be expired.
       -        getcookie "$arg"
       +        getcookie "$url"
                # try once
       -        if ! getjson "$url" > "$tmp"; then
       +        if ! getjson "$jsonurl" > "$tmp"; then
                        exit 1
                fi
        fi