Move tagtype detection to separate script for further use. - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit 9c2d6a5313bd098963f1e8350ad2037d6dca5e37 DIR parent 05a5677d0d72f707f08e15317c6c9073a723ea0a HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Tue, 19 May 2020 12:59:59 +0200 Move tagtype detection to separate script for further use. Thanks parazyd for the hint! Diffstat: M annna-add-hashtag | 18 +----------------- A get-tagtype | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 17 deletions(-) --- DIR diff --git a/annna-add-hashtag b/annna-add-hashtag @@ -83,23 +83,7 @@ inserttag() { stag="$(printf "${tag}\n" | cut -c 2-)" cd "${memecachedir}" tagfile="$(basename "$(find . -name "${stag}.*" | grep -v .orig)")" - case "${tagfile}" in - *.jpg|*.JPG|*.jpeg|*.JPEG|*.png|*.PNG|*.svg|*.SVG) - tagtype="I" - ;; - *.gif|*.GIF) - tagtype="g" - ;; - *.txt|*.TXT|*.vt|*.VT|*.vtv|*.VTV|*.vtt|*.VTT) - tagtype="0" - ;; - *.wav|*.WAV|*.mp3|*.MP3) - tagtype="A" - ;; - *) - tagtype="9" - ;; - esac + tagtype="$(get-tagtype "${tagfile}")" memecacheuri="gopher://bitreich.org/${tagtype}/memecache/${tagfile}" printf "%s %s\n" "${tag}" "${memecacheuri}" >> "${hashtagdb}" DIR diff --git a/get-tagtype b/get-tagtype @@ -0,0 +1,30 @@ +#!/bin/sh + +if [ $# -lt 1 ]; +then + printf "usage: %s filename.ext\n" "$(basename "$0")" >&2 + exit 1 +fi + +tagfile="$1" +case "${tagfile}" in +*.jpg|*.JPG|*.jpeg|*.JPEG|*.png|*.PNG|*.svg|*.SVG) + tagtype="I" + ;; +*.gif|*.GIF) + tagtype="g" + ;; +*.txt|*.TXT|*.vt|*.VT|*.vtv|*.VTV|*.vtt|*.VTT) + tagtype="0" + ;; +*.wav|*.WAV|*.mp3|*.MP3) + tagtype="A" + ;; +*) + tagtype="9" + ;; +esac + +printf "%s\n" "${tagtype}" +return 0 +