broadcast-store.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. # https://mro.name/radio-privatkopie
  3. #
  4. # validate and store a single broadcast from stdin and process podcast matches etc.
  5. # ${1} is used just for the error message in case of failure, so e.g. an original
  6. # url.
  7. #
  8. cd "$(dirname "${0}")" || exit 1
  9. readonly tmp="../stations/.bc-$$.xml~"
  10. {
  11. {
  12. echo "<?xml-stylesheet type='text/xsl' href='../../../app/broadcast2html.xslt'?>"
  13. cat -
  14. } \
  15. | xmllint \
  16. --encode "utf-8" \
  17. --format \
  18. --nonet \
  19. --nowarning \
  20. --nsclean \
  21. --output "${tmp}" \
  22. --relaxng "../app/pbmi2003-recmod2012/broadcast.rng" \
  23. - \
  24. || {
  25. echo "failed to scrape ${1}" >&2
  26. exit 1
  27. }
  28. } 2>&1 \
  29. | grep -vE -- \
  30. "^- validates\$" \
  31. >&2
  32. readonly id="$(grep -F ' name="DC.identifier"/>' "${tmp}" | cut -d '"' -f 2)"
  33. readonly mod="$(grep -hoE ' modified="[^"]+"' "${tmp}" | cut -d '"' -f 2)"
  34. readonly dst="../stations/${id}.xml"
  35. touch -d "${mod}" "${tmp}"
  36. mkdir -p "$(dirname "${dst}")"
  37. mv "${tmp}" "${dst}"
  38. sh "../podcasts/app/match.sh" "${id}"
  39. # this may have to be done outside the loop to avoid races?
  40. [ -r "../enclosures/${id}.reserved" ] \
  41. && sh "../enclosures/app/schedule.sh" "${id}"
  42. echo "<${id}> <http://purl.org/dc/terms/modified> \"${mod}\" ." \
  43. >> "../stations/modified.ttl"