nomad

HCL and Docker files for Nomad deployments
git clone https://git.in0rdr.ch/nomad.git
Log | Files | Refs | Pull requests

aload (1175B)


      1 #!/usr/bin/env sh
      2 
      3 set -o errexit
      4 set -o nounset
      5 #set -o xtrace
      6 
      7 echo "Content-type: text/html"
      8 echo
      9 
     10 CONTENT_LENGTH=${CONTENT_LENGTH:-12}
     11 DOCUMENT_ROOT=${DOCUMENT_ROOT:-}
     12 # XDG_CACHE_HOME is /var/www by default for apache user
     13 # which will produce PermissionError because this directory is owned by root
     14 # https://github.com/yt-dlp/yt-dlp#notes-about-environment-variables
     15 export XDG_CACHE_HOME=${DOCUMENT_ROOT}
     16 
     17 if [[ ! $CONTENT_LENGTH -eq 11 ]]; then
     18     echo "Not a valid video string"
     19     exit 1
     20 fi
     21 
     22 if [ "$REQUEST_METHOD" = "POST" ]; then 
     23     case "$CONTENT_TYPE" in
     24     application/x-www-form-urlencoded)
     25             read -n "$CONTENT_LENGTH" QUERY_STRING_POST
     26     ;;
     27     text/plain)
     28             read -n "$CONTENT_LENGTH" QUERY_STRING_POST
     29     ;;
     30     esac
     31 
     32     #if ! [[ "$QUERY_STRING_POST" =~ ^https://www.youtube.com/watch\?v=.{11}$ ]]; then
     33     #    echo "URL invalid"
     34     #    exit 1
     35     #fi
     36     echo "Downloading video "${QUERY_STRING_POST}" ..."
     37     yt-dlp -o "${DOCUMENT_ROOT}/music/%(artist)s - %(title)s.%(ext)s" \
     38       --extract-audio \
     39       --add-metadata \
     40       --audio-format mp3 \
     41       -- $QUERY_STRING_POST
     42 else 
     43     echo "Provide video string"
     44 fi