Various updates
Show_Submission/copy_shownotes: Changed the location of the function library Show_Submission/do_brave: Updates to the way local stand-alone HTML is generated for review purposes. Show_Submission/do_index: Changed the location of the function library Show_Submission/do_pandoc: Changed the location of the function library; now uses 'author_title.pl' to generate YAML for Pandoc Show_Submission/do_parse: Trivial change Show_Submission/do_pictures: Changed the location of the function library; better handling of the show specification Show_Submission/do_report: Changed the location of the function library Show_Submission/do_update_reservations: Changed the location of the function library Show_Submission/fix_relative_links: Added features 'say' and 'state' Show_Submission/parse_JSON: New checks: notes too short, trailing spaces on title, summary and tags (needing JSON changes). Check for Markdown in the assets (see 'do_pandoc_assets'). New 'trim' function.
This commit is contained in:
parent
7e925621f4
commit
b7cae1cb90
@ -18,7 +18,7 @@
|
|||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.10
|
# VERSION: 0.0.10
|
||||||
# CREATED: 2015-09-16 21:51:15
|
# CREATED: 2015-09-16 21:51:15
|
||||||
# REVISION: 2023-07-01 22:48:53
|
# REVISION: 2024-06-18 20:42:17
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -29,9 +29,9 @@ SCRIPT=${0##*/}
|
|||||||
#
|
#
|
||||||
# Load library functions
|
# Load library functions
|
||||||
#
|
#
|
||||||
LIB="$HOME/bin/function_lib.sh"
|
LIB="$HOME/HPR/function_lib.sh"
|
||||||
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
||||||
# shellcheck source=/home/cendjm/bin/function_lib.sh
|
# shellcheck source=/home/cendjm/HPR/function_lib.sh
|
||||||
source "$LIB"
|
source "$LIB"
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -19,10 +19,17 @@
|
|||||||
# 2022-12-22: We now write state changes to the file .status in
|
# 2022-12-22: We now write state changes to the file .status in
|
||||||
# the show directory, so we need to do that here too. Also
|
# the show directory, so we need to do that here too. Also
|
||||||
# changed to using the function library for cleanup_temp.
|
# changed to using the function library for cleanup_temp.
|
||||||
|
# 2024-10-17: Changed the logic around 'hpr????_full.html' by
|
||||||
|
# using a TT² template to enclose the usual HTML fragment in
|
||||||
|
# enough HTML to make it standalone. We have to get values from
|
||||||
|
# 'shownotes.json' and paass them into 'tpage' to do this, and
|
||||||
|
# the end result is not the same as the one generated by
|
||||||
|
# 'do_pandoc'. The result looks better than using the HTML
|
||||||
|
# fragment.
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.5
|
# VERSION: 0.0.6
|
||||||
# CREATED: 2016-03-20 15:22:29
|
# CREATED: 2016-03-20 15:22:29
|
||||||
# REVISION: 2022-12-22 17:28:12
|
# REVISION: 2024-10-17 19:33:42
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -47,18 +54,29 @@ if [[ $# -ne 1 ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
epno="${1}"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Directories and files
|
# Directories and files
|
||||||
#
|
#
|
||||||
BASENAME="$HOME/HPR/Show_Submission"
|
BASENAME="$HOME/HPR/Show_Submission"
|
||||||
SHOWDIR="$BASENAME/shownotes/hpr${1}"
|
SHOWDIR="$BASENAME/shownotes/hpr${epno}"
|
||||||
RAWNOTES="$SHOWDIR/hpr${1}.out"
|
RAWNOTES="$SHOWDIR/hpr${epno}.out"
|
||||||
HTML="$SHOWDIR/hpr${1}.html"
|
HTML="$SHOWDIR/hpr${epno}.html"
|
||||||
FULLHTML="$SHOWDIR/hpr${1}_full.html"
|
FULLHTML="$SHOWDIR/hpr${epno}_full.html"
|
||||||
|
SHOWNOTES="$SHOWDIR/shownotes.json"
|
||||||
STATUSFILE="$SHOWDIR/.status"
|
STATUSFILE="$SHOWDIR/.status"
|
||||||
|
FORMATFILE="$SHOWDIR/.format"
|
||||||
|
FORMAT="$(cat "$FORMATFILE")"
|
||||||
|
|
||||||
HTMLFILE="$FULLHTML"
|
HTMLFILE="$FULLHTML"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Check we have this template
|
||||||
|
#
|
||||||
|
FULLTPL="$BASENAME/make_fullnotes.tpl"
|
||||||
|
[[ -e $FULLTPL ]] || { echo "Unable to find template $FULLTPL"; exit 1; }
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check we have this browser
|
# Check we have this browser
|
||||||
#
|
#
|
||||||
@ -66,28 +84,57 @@ BRAVE=$(command -v brave-browser)
|
|||||||
[[ -v BRAVE ]] || { echo "Problem finding the Brave browser"; exit 1; }
|
[[ -v BRAVE ]] || { echo "Problem finding the Brave browser"; exit 1; }
|
||||||
|
|
||||||
#
|
#
|
||||||
# We prefer to view the 'full' html which we do by default. If not found
|
# Taking a different approach with the 'full' html. If the format is known to
|
||||||
# (because the host sent in HTML themselves) we look for hpr????.html, which
|
# be 'html5' there will not be one the first time we run this script. We will
|
||||||
# is a link to the notes from the form (hpr????.out), and view that. If the
|
# make 'hpr????_full.html' by enclosing the HTML "fragment" in 'hpr????.html'
|
||||||
# link didn't get created (not sure why) we copy the "raw" notes to
|
# in a TT² template with HTML header and footer.
|
||||||
# a temporary file with an '.html' extension (TODO: we could just make a link
|
|
||||||
# here). Otherwise we found nothing viewable.
|
|
||||||
#
|
#
|
||||||
if [[ ! -e $FULLHTML ]]; then
|
if [[ $FORMAT = 'html5' ]]; then
|
||||||
if [[ -e $HTML ]]; then
|
#
|
||||||
echo "No full HTML found, viewing $HTML instead"
|
# Extract the fields we want from the JSON and make them Bash variables
|
||||||
HTMLFILE="$HTML"
|
#
|
||||||
elif [[ -e $RAWNOTES ]]; then
|
declare _author _title _summary # Declare them for shellcheck
|
||||||
echo "No files with ''.HTML' suffix, viewing raw notes"
|
jqprog='@sh "_author=\(.host.Host_Name) '
|
||||||
|
jqprog+='_title=\(.episode.Title) '
|
||||||
|
jqprog+='_summary=\(.episode.Summary)"'
|
||||||
|
eval "$(jq -r "$jqprog" "$SHOWNOTES")"
|
||||||
|
|
||||||
TMP1=$(mktemp '/tmp/notes_XXXXXX.html') || { echo "$SCRIPT: creation of temporary file failed!"; exit 1; }
|
#
|
||||||
trap 'cleanup_temp $TMP1' SIGHUP SIGINT SIGPIPE SIGTERM EXIT
|
# Feed the variables to the template to make the full HTML
|
||||||
|
#
|
||||||
|
tpage --define author="$_author" \
|
||||||
|
--define title="$_title" \
|
||||||
|
--define summary="$_summary" \
|
||||||
|
--define body="$HTML" \
|
||||||
|
"$FULLTPL" > "$FULLHTML"
|
||||||
|
else
|
||||||
|
#
|
||||||
|
# See above for how we make the 'full' notes if the host sent in HTML
|
||||||
|
# notes. Here we have received notes that use one of the excepted markup
|
||||||
|
# formats or are plain text (≡ Pandoc Markdown).
|
||||||
|
#
|
||||||
|
# If the 'full' HTML is not found (for unknown reasons) we look for
|
||||||
|
# hpr????.html, which is a link to the notes from the form (hpr????.out),
|
||||||
|
# and view that. If the link didn't get created (not sure why) we copy the
|
||||||
|
# "raw" notes to a temporary file with an '.html' extension (TODO: we
|
||||||
|
# could just make a link here). Otherwise we found nothing viewable.
|
||||||
|
#
|
||||||
|
if [[ ! -e $FULLHTML ]]; then
|
||||||
|
if [[ -e $HTML ]]; then
|
||||||
|
echo "No full HTML found, viewing $HTML instead"
|
||||||
|
HTMLFILE="$HTML"
|
||||||
|
elif [[ -e $RAWNOTES ]]; then
|
||||||
|
echo "No files with ''.HTML' suffix, viewing raw notes"
|
||||||
|
|
||||||
cp "$RAWNOTES" "$TMP1"
|
TMP1=$(mktemp '/tmp/notes_XXXXXX.html') || { echo "$SCRIPT: creation of temporary file failed!"; exit 1; }
|
||||||
HTMLFILE="$TMP1"
|
trap 'cleanup_temp $TMP1' SIGHUP SIGINT SIGPIPE SIGTERM EXIT
|
||||||
else
|
|
||||||
echo "Nothing to view, giving up"
|
cp "$RAWNOTES" "$TMP1"
|
||||||
exit
|
HTMLFILE="$TMP1"
|
||||||
|
else
|
||||||
|
echo "Nothing to view, giving up"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash -
|
#!/bin/bash -
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
#
|
#
|
||||||
# FILE: do_index
|
# FILE: do_index
|
||||||
@ -11,11 +11,11 @@
|
|||||||
# OPTIONS: ---
|
# OPTIONS: ---
|
||||||
# REQUIREMENTS: ---
|
# REQUIREMENTS: ---
|
||||||
# BUGS: ---
|
# BUGS: ---
|
||||||
# NOTES: ---
|
# NOTES: [[ Probably obsolete! ]]
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.5
|
# VERSION: 0.0.5
|
||||||
# CREATED: 2022-10-30 15:39:28
|
# CREATED: 2022-10-30 15:39:28
|
||||||
# REVISION: 2022-12-17 17:38:00
|
# REVISION: 2024-06-18 20:28:55
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -31,9 +31,9 @@ STDOUT="/dev/fd/2"
|
|||||||
#
|
#
|
||||||
# Load library functions (make_file_list, range_parse, cleanup_temp)
|
# Load library functions (make_file_list, range_parse, cleanup_temp)
|
||||||
#
|
#
|
||||||
LIB="$HOME/bin/function_lib.sh"
|
LIB="$HOME/HPR/function_lib.sh"
|
||||||
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
||||||
# shellcheck source=/home/cendjm/bin/function_lib.sh
|
# shellcheck source=/home/cendjm/HPR/function_lib.sh
|
||||||
source "$LIB"
|
source "$LIB"
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -37,9 +37,9 @@
|
|||||||
# careful about collisions.
|
# careful about collisions.
|
||||||
#
|
#
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.2.10
|
# VERSION: 0.2.11
|
||||||
# CREATED: 2016-08-16 15:34:30
|
# CREATED: 2016-08-16 15:34:30
|
||||||
# REVISION: 2024-02-18 13:27:40
|
# REVISION: 2024-10-18 23:03:25
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -48,16 +48,16 @@ set -o nounset # Treat unset variables as an error
|
|||||||
SCRIPT=${0##*/}
|
SCRIPT=${0##*/}
|
||||||
#DIR=${0%/*}
|
#DIR=${0%/*}
|
||||||
|
|
||||||
VERSION='0.2.10'
|
VERSION='0.2.11'
|
||||||
|
|
||||||
STDOUT="/dev/fd/2"
|
STDOUT="/dev/fd/2"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Load library functions
|
# Load library functions
|
||||||
#
|
#
|
||||||
LIB="$HOME/bin/function_lib.sh"
|
LIB="$HOME/HPR/function_lib.sh"
|
||||||
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
||||||
# shellcheck source=/home/cendjm/bin/function_lib.sh
|
# shellcheck source=/home/cendjm/HPR/function_lib.sh
|
||||||
source "$LIB"
|
source "$LIB"
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -65,7 +65,7 @@ source "$LIB"
|
|||||||
#
|
#
|
||||||
define_colours
|
define_colours
|
||||||
|
|
||||||
# {{{ Functions: -- _usage -- _DEBUG --
|
# {{{ Functions: -- _usage --
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _usage
|
# NAME: _usage
|
||||||
# DESCRIPTION: Report usage
|
# DESCRIPTION: Report usage
|
||||||
@ -102,19 +102,6 @@ Examples
|
|||||||
endusage
|
endusage
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
|
||||||
# NAME: _DEBUG
|
|
||||||
# DESCRIPTION: Writes one or more message lines if in DEBUG mode
|
|
||||||
# PARAMETERS: List of messages
|
|
||||||
# RETURNS: Nothing
|
|
||||||
#===============================================================================
|
|
||||||
_DEBUG () {
|
|
||||||
[ "$DEBUG" == 0 ] && return
|
|
||||||
for msg in "$@"; do
|
|
||||||
printf 'D> %s\n' "$msg"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -168,8 +155,8 @@ options[txt2tags]=''
|
|||||||
#
|
#
|
||||||
# Sanity checks
|
# Sanity checks
|
||||||
#
|
#
|
||||||
JQ=$(command -v jq)
|
# JQ=$(command -v jq)
|
||||||
[ -n "$JQ" ] || { echo "Program 'jq' was not found"; exit 1; }
|
# [ -n "$JQ" ] || { echo "Program 'jq' was not found"; exit 1; }
|
||||||
# YQ=$(command -v yq)
|
# YQ=$(command -v yq)
|
||||||
# [ -n "$YQ" ] || { echo "Program 'yq' was not found"; exit 1; }
|
# [ -n "$YQ" ] || { echo "Program 'yq' was not found"; exit 1; }
|
||||||
|
|
||||||
@ -235,7 +222,7 @@ trap 'cleanup_temp $TMP1 $TMP2 $TMP3' SIGHUP SIGINT SIGPIPE SIGTERM EXIT
|
|||||||
# Main directory
|
# Main directory
|
||||||
BASENAME="$HOME/HPR/Show_Submission"
|
BASENAME="$HOME/HPR/Show_Submission"
|
||||||
|
|
||||||
# JSON to YAML Perl script
|
# JSON to YAML Perl script - sanity check
|
||||||
J2Y="$BASENAME/author_title.pl"
|
J2Y="$BASENAME/author_title.pl"
|
||||||
[ -e "$J2Y" ] || { echo "Program '$J2Y' was not found"; exit 1; }
|
[ -e "$J2Y" ] || { echo "Program '$J2Y' was not found"; exit 1; }
|
||||||
|
|
||||||
@ -303,19 +290,23 @@ BASEURL='https://hackerpublicradio.org/eps/'
|
|||||||
# needed for Pandoc
|
# needed for Pandoc
|
||||||
#
|
#
|
||||||
# Non-YAML alternative - not chosen
|
# Non-YAML alternative - not chosen
|
||||||
#jqprog="@text \"author: \(.host.Host_Name)\ntitle: \(.episode.Title)\""
|
# jqprog="@text \"author: \(.host.Host_Name)\ntitle: \(.episode.Title)\""
|
||||||
#
|
#
|
||||||
# Testing another formatter (Journal 2023-03-03)
|
# Testing another formatter (Journal 2023-03-03)
|
||||||
#jqprog="@sh \"---\nauthor: \(.host.Host_Name)\ntitle: \(.episode.Title)\n---\""
|
# jqprog="@sh \"---\nauthor: \(.host.Host_Name)\ntitle: \(.episode.Title)\n---\""
|
||||||
# Added quotes around the generated strings (2023-03-31)
|
# Added quotes around the generated strings (2023-03-31)
|
||||||
# jqprog="@text \"---\nauthor: \(.host.Host_Name)\ntitle: \(.episode.Title)\n---\""
|
# jqprog="@text \"---\nauthor: \(.host.Host_Name)\ntitle: \(.episode.Title)\n---\""
|
||||||
|
#
|
||||||
# Moved to 'yq' 2023-04-01
|
# Moved to 'yq' 2023-04-01
|
||||||
# jqprog="@text \"---\nauthor: '\(.host.Host_Name)'\ntitle: '\(.episode.Title)'\n---\""
|
# jqprog="@text \"---\nauthor: '\(.host.Host_Name)'\ntitle: '\(.episode.Title)'\n---\""
|
||||||
# jq -r "$jqprog" "$JSONFILE" > "$TMP1"
|
# jq -r "$jqprog" "$JSONFILE" > "$TMP1"
|
||||||
|
#
|
||||||
# On 2023-10-01 wrote a Perl JSON to YAML generator just for these two
|
# On 2023-10-01 wrote a Perl JSON to YAML generator just for these two
|
||||||
# elements. It's called 'author_title.pl'
|
# elements. It's called 'author_title.pl'
|
||||||
|
#
|
||||||
# yqprog='{author:.host.Host_Name,title:.episode.Title}'
|
# yqprog='{author:.host.Host_Name,title:.episode.Title}'
|
||||||
# ( echo "---"; $YQ -y "$yqprog" "$JSONFILE"; echo "---"; ) > "$TMP1"
|
# ( echo "---"; $YQ -y "$yqprog" "$JSONFILE"; echo "---"; ) > "$TMP1"
|
||||||
|
#
|
||||||
$J2Y "$JSONFILE" "$TMP1"
|
$J2Y "$JSONFILE" "$TMP1"
|
||||||
_DEBUG "YAML:" "$(cat "$TMP1")"
|
_DEBUG "YAML:" "$(cat "$TMP1")"
|
||||||
|
|
||||||
@ -497,7 +488,7 @@ if [[ $DRYRUN -eq 0 ]]; then
|
|||||||
#
|
#
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
pandoc -f ${FROM}${POPTIONS} -t html5 --ascii \
|
pandoc -f ${FROM}${POPTIONS} -t html5 --ascii \
|
||||||
--standalone --template=hpr.html5 --no-highlight \
|
--standalone --template=hpr_dev.html5 --no-highlight \
|
||||||
-c https://hackerpublicradio.org/css/hpr.css \
|
-c https://hackerpublicradio.org/css/hpr.css \
|
||||||
--metadata-file="$TMP1" -o "$FULLHTML" "$TMP3"
|
--metadata-file="$TMP1" -o "$FULLHTML" "$TMP3"
|
||||||
RES=$?
|
RES=$?
|
||||||
|
@ -124,6 +124,7 @@ fi
|
|||||||
#
|
#
|
||||||
# $PARSER -novalid -ep "${show}" -in "$FROM" -show "$TOTPL" \
|
# $PARSER -novalid -ep "${show}" -in "$FROM" -show "$TOTPL" \
|
||||||
# -json "$JSONTPL" -format="$FMT"
|
# -json "$JSONTPL" -format="$FMT"
|
||||||
|
#
|
||||||
$PARSER -ep "${show}" -in "$FROM" -show "$TOTPL" \
|
$PARSER -ep "${show}" -in "$FROM" -show "$TOTPL" \
|
||||||
-format="$FMT" -release="$REL" -pictures="$PICTURES" -assets="$ASSETS" \
|
-format="$FMT" -release="$REL" -pictures="$PICTURES" -assets="$ASSETS" \
|
||||||
-zip="$ZIP"
|
-zip="$ZIP"
|
||||||
|
@ -60,9 +60,9 @@
|
|||||||
# BUGS: ---
|
# BUGS: ---
|
||||||
# NOTES: ---
|
# NOTES: ---
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.2.3
|
# VERSION: 0.2.4
|
||||||
# CREATED: 2020-05-25 13:20:18
|
# CREATED: 2020-05-25 13:20:18
|
||||||
# REVISION: 2024-02-22 14:32:03
|
# REVISION: 2024-07-25 21:39:16
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -71,16 +71,16 @@ set -o nounset # Treat unset variables as an error
|
|||||||
SCRIPT=${0##*/}
|
SCRIPT=${0##*/}
|
||||||
# DIR=${0%/*}
|
# DIR=${0%/*}
|
||||||
|
|
||||||
VERSION="0.2.3"
|
VERSION="0.2.4"
|
||||||
|
|
||||||
STDOUT="/dev/fd/2"
|
STDOUT="/dev/fd/2"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Load library functions (make_file_list, range_parse, cleanup_temp)
|
# Load library functions (make_file_list, range_parse, cleanup_temp)
|
||||||
#
|
#
|
||||||
LIB="$HOME/bin/function_lib.sh"
|
LIB="$HOME/HPR/function_lib.sh"
|
||||||
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
||||||
# shellcheck source=/home/cendjm/bin/function_lib.sh
|
# shellcheck source=/home/cendjm/HPR/function_lib.sh
|
||||||
source "$LIB"
|
source "$LIB"
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -88,7 +88,7 @@ source "$LIB"
|
|||||||
#
|
#
|
||||||
define_colours
|
define_colours
|
||||||
|
|
||||||
# {{{ -- _usage --
|
# {{{ -- _usage - _silent -- _dryrun --
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _usage
|
# NAME: _usage
|
||||||
# DESCRIPTION: Report usage
|
# DESCRIPTION: Report usage
|
||||||
@ -150,9 +150,7 @@ Examples
|
|||||||
endusage
|
endusage
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
# }}}
|
|
||||||
|
|
||||||
# {{{ -- _silent -- _dryrun -- _DEBUG --
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _silent
|
# NAME: _silent
|
||||||
# DESCRIPTION: Output a message unless we're being silent
|
# DESCRIPTION: Output a message unless we're being silent
|
||||||
@ -179,19 +177,6 @@ _dryrun () {
|
|||||||
prefix=
|
prefix=
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
|
||||||
# NAME: _DEBUG
|
|
||||||
# DESCRIPTION: Writes one or more message lines if in DEBUG mode
|
|
||||||
# PARAMETERS: List of messages
|
|
||||||
# RETURNS: Nothing
|
|
||||||
#===============================================================================
|
|
||||||
_DEBUG () {
|
|
||||||
[ "$DEBUG" == 0 ] && return
|
|
||||||
for msg in "$@"; do
|
|
||||||
printf 'D> %s\n' "$msg"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@ -229,12 +214,25 @@ if [[ $# -ne 1 ]]; then
|
|||||||
echo "${red}Missing shownumber argument${reset}"
|
echo "${red}Missing shownumber argument${reset}"
|
||||||
_usage
|
_usage
|
||||||
fi
|
fi
|
||||||
|
epno="${1}"
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ensure item spec is correctly formatted. Have to cater for leading zeroes
|
||||||
|
# being interpreted as octal.
|
||||||
|
#
|
||||||
|
if [[ $epno =~ ^(hpr)?([0-9]+)$ ]]; then
|
||||||
|
epno="$((10#${BASH_REMATCH[-1]}))"
|
||||||
|
else
|
||||||
|
coloured 'red' "Incorrect show specification: $epno"
|
||||||
|
coloured 'yellow' "Use 'hpr9999' or '9999' formats"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Paths to files
|
# Paths to files
|
||||||
#
|
#
|
||||||
BASEDIR="$HOME/HPR/Show_Submission"
|
BASEDIR="$HOME/HPR/Show_Submission"
|
||||||
SHOWDIR="$BASEDIR/shownotes/hpr${1}"
|
SHOWDIR="$BASEDIR/shownotes/hpr${epno}"
|
||||||
# RAWFILE="$SHOWDIR/shownotes.txt"
|
# RAWFILE="$SHOWDIR/shownotes.txt"
|
||||||
JSONFILE="$SHOWDIR/shownotes.json"
|
JSONFILE="$SHOWDIR/shownotes.json"
|
||||||
PICDIR="$SHOWDIR/uploads"
|
PICDIR="$SHOWDIR/uploads"
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.8
|
# VERSION: 0.0.8
|
||||||
# CREATED: 2022-09-07 15:27:29
|
# CREATED: 2022-09-07 15:27:29
|
||||||
# REVISION: 2023-06-01 17:58:09
|
# REVISION: 2024-06-18 20:13:46
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -32,9 +32,9 @@ STDOUT="/dev/fd/2"
|
|||||||
#
|
#
|
||||||
# Load library functions
|
# Load library functions
|
||||||
#
|
#
|
||||||
LIB="$HOME/bin/function_lib.sh"
|
LIB="$HOME/HPR/function_lib.sh"
|
||||||
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
||||||
# shellcheck source=/home/cendjm/bin/function_lib.sh
|
# shellcheck source=/home/cendjm/HPR/function_lib.sh
|
||||||
source "$LIB"
|
source "$LIB"
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -42,7 +42,7 @@ source "$LIB"
|
|||||||
#
|
#
|
||||||
define_colours
|
define_colours
|
||||||
|
|
||||||
#{{{ Functions: --- _usage --- _DEBUG --- _verbose --- _silent ---
|
#{{{ Functions: --- _usage --- _verbose --- _silent ---
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _usage
|
# NAME: _usage
|
||||||
# DESCRIPTION: Report usage
|
# DESCRIPTION: Report usage
|
||||||
@ -77,22 +77,6 @@ endusage
|
|||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
|
||||||
# NAME: _DEBUG
|
|
||||||
# DESCRIPTION: Writes one or more messages if in DEBUG mode. Each argument is
|
|
||||||
# seen as a message and is written on a separate line.
|
|
||||||
# References the global variable 'DEBUG' which is expected to be
|
|
||||||
# True if debug output is wanted.
|
|
||||||
# PARAMETERS: List of messages
|
|
||||||
# RETURNS: Nothing
|
|
||||||
#===============================================================================
|
|
||||||
_DEBUG () {
|
|
||||||
[ "$DEBUG" == 0 ] && return
|
|
||||||
for msg in "$@"; do
|
|
||||||
printf 'D> %s\n' "$msg"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: _verbose
|
# NAME: _verbose
|
||||||
# DESCRIPTION: Writes a message in verbose mode
|
# DESCRIPTION: Writes a message in verbose mode
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.6
|
# VERSION: 0.0.6
|
||||||
# CREATED: 2022-04-11 09:36:21
|
# CREATED: 2022-04-11 09:36:21
|
||||||
# REVISION: 2023-06-14 23:24:42
|
# REVISION: 2024-06-18 20:16:19
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
@ -32,9 +32,9 @@ STDOUT="/dev/fd/2"
|
|||||||
#
|
#
|
||||||
# Load library functions
|
# Load library functions
|
||||||
#
|
#
|
||||||
LIB="$HOME/bin/function_lib.sh"
|
LIB="$HOME/HPR/function_lib.sh"
|
||||||
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
[ -e "$LIB" ] || { echo "$SCRIPT: Unable to source functions"; exit 1; }
|
||||||
# shellcheck source=/home/cendjm/bin/function_lib.sh
|
# shellcheck source=/home/cendjm/HPR/function_lib.sh
|
||||||
source "$LIB"
|
source "$LIB"
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -25,8 +25,7 @@ use v5.16;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
use feature qw{ postderef say signatures state };
|
use feature qw{ say state };
|
||||||
no warnings qw{ experimental::postderef experimental::signatures };
|
|
||||||
|
|
||||||
use Carp;
|
use Carp;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
@ -605,7 +604,7 @@ base URL described below.
|
|||||||
|
|
||||||
=item B<-baseURL=URL>
|
=item B<-baseURL=URL>
|
||||||
|
|
||||||
This option will default to the foillowing URL if not provided:
|
This option will default to the following URL if not provided:
|
||||||
|
|
||||||
https://hackerpublicradio.org/eps/hpr${show}/
|
https://hackerpublicradio.org/eps/hpr${show}/
|
||||||
|
|
||||||
|
@ -21,14 +21,17 @@
|
|||||||
# BUGS: ---
|
# BUGS: ---
|
||||||
# NOTES: ---
|
# NOTES: ---
|
||||||
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
|
||||||
# VERSION: 0.0.14
|
# VERSION: 0.0.17
|
||||||
# CREATED: 2020-11-28 10:52:02
|
# CREATED: 2020-11-28 10:52:02
|
||||||
# REVISION: 2024-03-09 20:34:54
|
# REVISION: 2024-10-04 18:37:29
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
use 5.30.0;
|
use v5.36;
|
||||||
use utf8;
|
use utf8;
|
||||||
|
use feature qw{ postderef say signatures state try };
|
||||||
|
no warnings
|
||||||
|
qw{ experimental::postderef experimental::signatures experimental::try };
|
||||||
|
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use Pod::Usage;
|
use Pod::Usage;
|
||||||
@ -57,7 +60,7 @@ use Data::Dumper;
|
|||||||
#
|
#
|
||||||
# Version number (manually incremented)
|
# Version number (manually incremented)
|
||||||
#
|
#
|
||||||
our $VERSION = '0.0.14';
|
our $VERSION = '0.0.17';
|
||||||
|
|
||||||
#
|
#
|
||||||
# Script and directory names
|
# Script and directory names
|
||||||
@ -79,7 +82,12 @@ my $logfile = "$logdir/${PROG}.log";
|
|||||||
my ( $snlevel, $showno, $summarylength, $notelength );
|
my ( $snlevel, $showno, $summarylength, $notelength );
|
||||||
|
|
||||||
our $MARKUP_DETECTED = 0;
|
our $MARKUP_DETECTED = 0;
|
||||||
|
|
||||||
|
#
|
||||||
|
# Maximum and minimum number of characters (bytes)
|
||||||
|
#
|
||||||
my $MAXNOTELEN = 4000;
|
my $MAXNOTELEN = 4000;
|
||||||
|
my $MINNOTELEN = 10;
|
||||||
|
|
||||||
#
|
#
|
||||||
# Printing: general output format
|
# Printing: general output format
|
||||||
@ -223,13 +231,14 @@ my @markup_types = (
|
|||||||
my @markup_found;
|
my @markup_found;
|
||||||
my $markup_choice;
|
my $markup_choice;
|
||||||
|
|
||||||
my ( $showdir, $assetdir , $statusfile );
|
my ( $showdir, $assetdir, $statusfile );
|
||||||
my ( %media_files, $media_files );
|
my ( %media_files, $media_files );
|
||||||
my ( %assets, @assets, @audio, $sanitised );
|
my ( %assets, @assets, @audio, $sanitised );
|
||||||
my ( $has_audio, $has_extra, $has_archives );
|
my ( $has_audio, $has_extra, $has_archives );
|
||||||
my ( @archives, @extracted );
|
my ( @archives, @extracted );
|
||||||
my ( $astate, $has_pictures, @pictures, $pictures );
|
my ( $astate, $has_pictures, @pictures, $pictures );
|
||||||
my ( %spellchecks );
|
my ( $has_markup, @markup, $markup );
|
||||||
|
my ( $json_change, @json_changes, %spellchecks );
|
||||||
my @pstates = (
|
my @pstates = (
|
||||||
'No pictures found', # 0
|
'No pictures found', # 0
|
||||||
'Pictures that need management', # 1
|
'Pictures that need management', # 1
|
||||||
@ -347,8 +356,13 @@ open( my $fh, '<:encoding(UTF-8)', $infile );
|
|||||||
my $json_text = <$fh>;
|
my $json_text = <$fh>;
|
||||||
close($fh);
|
close($fh);
|
||||||
|
|
||||||
# TODO: bad JSON can crash the script here!
|
my $content;
|
||||||
my $content = decode_json($json_text);
|
try {
|
||||||
|
$content = decode_json($json_text);
|
||||||
|
}
|
||||||
|
catch ($e) {
|
||||||
|
die colored( "Failed to decode the JSON in $infile", 'red' ) . "\n"
|
||||||
|
}
|
||||||
|
|
||||||
$log->info( $showno, "[$VERSION] Processing $infile" );
|
$log->info( $showno, "[$VERSION] Processing $infile" );
|
||||||
|
|
||||||
@ -372,6 +386,19 @@ print STDERR '-' x 80, "\n";
|
|||||||
printf STDERR $ofmt, "Show:", $content->{metadata}{Episode_Number};
|
printf STDERR $ofmt, "Show:", $content->{metadata}{Episode_Number};
|
||||||
printf STDERR $ofmt, "Date:", $content->{metadata}{Episode_Date};
|
printf STDERR $ofmt, "Date:", $content->{metadata}{Episode_Date};
|
||||||
|
|
||||||
|
#
|
||||||
|
# Trim off leading and trailing spaces in these fields
|
||||||
|
#
|
||||||
|
$json_change = 0;
|
||||||
|
for my $key ( 'Title', 'Summary', 'Tags' ) {
|
||||||
|
my $str = trim($content->{episode}{$key});
|
||||||
|
if ($str ne $content->{episode}{$key}) {
|
||||||
|
$content->{episode}{$key} = $str;
|
||||||
|
$json_change = 1;
|
||||||
|
push(@json_changes,$key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Detect Unicode in the Title, Summary or Tags and flag their presence.
|
# Detect Unicode in the Title, Summary or Tags and flag their presence.
|
||||||
#
|
#
|
||||||
@ -386,6 +413,9 @@ for my $key ( 'Title', 'Summary', 'Tags' ) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alert( $ofmt, "JSON to be updated; changes to: " .
|
||||||
|
join(',',@json_changes) ) if $json_change;
|
||||||
|
|
||||||
#
|
#
|
||||||
# Check summary length. The field might be filled and something might have
|
# Check summary length. The field might be filled and something might have
|
||||||
# been lost.
|
# been lost.
|
||||||
@ -429,7 +459,12 @@ printf STDERR $ofmt, "Notes:", $snlevel . " HTML start/end tags found";
|
|||||||
$notelength = length( $content->{episode}{Show_Notes} );
|
$notelength = length( $content->{episode}{Show_Notes} );
|
||||||
if ( $notelength > $MAXNOTELEN ) {
|
if ( $notelength > $MAXNOTELEN ) {
|
||||||
printf STDERR $ofmt, "Notes:",
|
printf STDERR $ofmt, "Notes:",
|
||||||
colored( "Notes are longer than $MAXNOTELEN ($notelength)",
|
colored( "Notes are longer than $MAXNOTELEN bytes ($notelength)",
|
||||||
|
'bold yellow on_magenta' );
|
||||||
|
}
|
||||||
|
elsif ( $notelength <= $MINNOTELEN ) {
|
||||||
|
printf STDERR $ofmt, "Notes:",
|
||||||
|
colored( "Notes are shorter than $MINNOTELEN bytes ($notelength)",
|
||||||
'bold yellow on_magenta' );
|
'bold yellow on_magenta' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,6 +686,17 @@ if (%media_files) {
|
|||||||
_debug( $DEBUG > 2, '@assets: ' . Dumper( \@assets ) );
|
_debug( $DEBUG > 2, '@assets: ' . Dumper( \@assets ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Look for un-processed markup in the assets hash. For the moment we
|
||||||
|
# only look for Markdown.
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
$has_markup = @markup
|
||||||
|
= grep { $assets{$_}->{type} =~ m{^text/markdown$} } keys(%assets);
|
||||||
|
$markup = join( ', ', @markup );
|
||||||
|
if (@markup) {
|
||||||
|
_debug( $DEBUG > 2, '@markup ' . Dumper( \@markup ) );
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Look for archive files in the assets
|
# Look for archive files in the assets
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
@ -690,6 +736,11 @@ if (%media_files) {
|
|||||||
@assets = array_difference(\@assets,\@archives);
|
@assets = array_difference(\@assets,\@archives);
|
||||||
push(@assets, @extracted);
|
push(@assets, @extracted);
|
||||||
|
|
||||||
|
#
|
||||||
|
# Remove markup files from the assets so we don't upload them
|
||||||
|
#
|
||||||
|
@assets = array_difference(\@assets,\@markup);
|
||||||
|
|
||||||
#
|
#
|
||||||
# Remove directory stuff from @assets elements and %assets keys
|
# Remove directory stuff from @assets elements and %assets keys
|
||||||
#
|
#
|
||||||
@ -745,6 +796,8 @@ if (%media_files) {
|
|||||||
$log->info( $showno, "Media files: $media_files" ) if ($media_files);
|
$log->info( $showno, "Media files: $media_files" ) if ($media_files);
|
||||||
$log->info( $showno, "Pictures: " . join( ', ', @pictures ) )
|
$log->info( $showno, "Pictures: " . join( ', ', @pictures ) )
|
||||||
if (@pictures);
|
if (@pictures);
|
||||||
|
$log->info( $showno, "Markup " . join( ', ', @markup ) )
|
||||||
|
if (@markup);
|
||||||
$log->info( $showno, "Assets: " . join( ', ', @assets ) )
|
$log->info( $showno, "Assets: " . join( ', ', @assets ) )
|
||||||
if (@assets);
|
if (@assets);
|
||||||
|
|
||||||
@ -849,7 +902,6 @@ if ( $snlevel > 0 && $content->{metadata}{Shownotes_Format} =~ /html5/i ) {
|
|||||||
"Apparently incorrect URLs detected in the notes", 'red'
|
"Apparently incorrect URLs detected in the notes", 'red'
|
||||||
), "\n";
|
), "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -866,6 +918,15 @@ if ( $markup_choice eq 'html5'
|
|||||||
"Declared format 'plain_text' but notes seem to be HTML5!" );
|
"Declared format 'plain_text' but notes seem to be HTML5!" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# 7. The host has sent in markup version(s) of their external notes, so we
|
||||||
|
# need to take special action.
|
||||||
|
#
|
||||||
|
if ($markup) {
|
||||||
|
printf STDERR "%s\n",
|
||||||
|
textFormat( $markup, 'Markup files:', 'L', 18, 80 );
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Determine the picture asset state
|
# Determine the picture asset state
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
@ -1709,6 +1770,23 @@ sub find_Unicode {
|
|||||||
return ( $string =~ /[^\x{00}-\x{7F}]/ );
|
return ( $string =~ /[^\x{00}-\x{7F}]/ );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#=== FUNCTION ================================================================
|
||||||
|
# NAME: trim
|
||||||
|
# PURPOSE: Trims leading and trailing spaces from a string
|
||||||
|
# PARAMETERS: string string to trim
|
||||||
|
# RETURNS: Trimmed string
|
||||||
|
# DESCRIPTION:
|
||||||
|
# THROWS: No exceptions
|
||||||
|
# COMMENTS: None
|
||||||
|
# SEE ALSO: N/A
|
||||||
|
#===============================================================================
|
||||||
|
sub trim {
|
||||||
|
my ($str) = @_;
|
||||||
|
|
||||||
|
$str =~ s/^\s+|\s+$//g;
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
#=== FUNCTION ================================================================
|
#=== FUNCTION ================================================================
|
||||||
# NAME: output_file_name
|
# NAME: output_file_name
|
||||||
# PURPOSE: Generate an output file name with three choices
|
# PURPOSE: Generate an output file name with three choices
|
||||||
@ -1969,7 +2047,6 @@ sub alert {
|
|||||||
my ( $fmt, $message ) = @_;
|
my ( $fmt, $message ) = @_;
|
||||||
|
|
||||||
$fmt = "%-16s %s\n" unless $fmt;
|
$fmt = "%-16s %s\n" unless $fmt;
|
||||||
# print STDERR "$bold$red", sprintf( $fmt, "** ALERT **:", $message ), "$reset";
|
|
||||||
print STDERR colored( sprintf( $fmt, "** ALERT **:", $message ),
|
print STDERR colored( sprintf( $fmt, "** ALERT **:", $message ),
|
||||||
'bold red' );
|
'bold red' );
|
||||||
}
|
}
|
||||||
@ -2082,7 +2159,7 @@ parse_JSON - parse the JSON output file from the HPR show submission form
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
This documentation refers to parse_JSON version 0.0.14
|
This documentation refers to parse_JSON version 0.0.17
|
||||||
|
|
||||||
|
|
||||||
=head1 USAGE
|
=head1 USAGE
|
||||||
|
Loading…
Reference in New Issue
Block a user