www-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

www/audio-video/workshop av-create


From: Therese Godefroy
Subject: www/audio-video/workshop av-create
Date: Sat, 12 Nov 2022 10:34:07 -0500 (EST)

CVSROOT:        /webcvs/www
Module name:    www
Changes by:     Therese Godefroy <th_g> 22/11/12 10:34:07

Modified files:
        audio-video/workshop: av-create 

Log message:
        Try to catch errors in 'entry' at the very beginning; create fields
        for derived data if they don't exist.

CVSWeb URLs:
http://web.cvs.savannah.gnu.org/viewcvs/www/audio-video/workshop/av-create?cvsroot=www&r1=1.6&r2=1.7

Patches:
Index: av-create
===================================================================
RCS file: /webcvs/www/www/audio-video/workshop/av-create,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- av-create   11 Nov 2022 21:42:34 -0000      1.6
+++ av-create   12 Nov 2022 15:34:06 -0000      1.7
@@ -7,7 +7,7 @@
 # run it without argument.
 
 # Public domain.
-# Last updated 2022-11-11.
+# Last updated 2022-11-12.
 # Please report bugs to thg@gnu.org or ineiev@gnu.org.
 
 
@@ -26,26 +26,25 @@
   exit 1 
 fi
 
-echo "${0##*\/}: Generating a new audio/video entry in rec format..."
-
 # Clean the form.
+
 sed -i 's,[[:space:]]*##.*,,
         s,^[#*],,
-        s,^\([A-Za-z]\+:\)[[:space:]][[:space:]]*\([[:print:]]\+\),\1 \2,
+        s,^\([A-Za-z]\+:\)[[:space:]]*\([[:print:]]\+\),\1 \2,
         /^$/d
        ' entry
 
-# Check that all the required fields have data.
+# Check that the data is correct.
 
 n=1
 missing=""
 for f in Id Type Title Language Duration License; do
-   if ! data[n]=$(grep "^$f: " entry); then
+   if ! data[$n]=$(grep "^$f: " entry); then
      missing="$missing $f"
    fi
    n=$(( $n + 1 ))
 done
-Id=${data[1]}; Language=${data[4]}; Duration=${data[5]};
+Id=${data[1]}; Type=${data[2]}; Language=${data[4]}; Duration=${data[5]};
 
 media=""
 if grep -q '<b>Video</b>' entry; then media="$media video"; fi
@@ -58,15 +57,65 @@
   missing="$missing Media"
 fi
 
+wrong_data=""
+id=${Id#* }
+if ! echo $id | grep -q '^[a-z]\+-[0-9]\{9\}$'; then
+  wrong_data="${wrong_data}\n    ${Id}"
+fi
+
+type=${Type#* }
+if [ ! "${type% *}" = "$type" ] ||
+  [[ ! 'speech interview round-table historical movie extra' =~ "$type" ]]; 
then 
+   wrong_data="${wrong_data}\n    ${Type}"
+fi
+
+language=$(echo $Language | sed 's,^[a-zA-Z]\+: \([a-zA-Z]\+\)\( .*\)\?$,\1,')
+if [[ $language =~ " " ]]; then
+  wrong_data="${wrong_data}\n    ${Language}"
+fi
+
+duration=${Duration#* }
+if ! echo $duration | grep -q '^[0-9]:[0-9]\{1,2\}:[0-9]\{1,2\}$' ||
+  [ "$duration" = '0:00:00' ] ; then
+  wrong_data="${wrong_data}\n    ${Duration}"
+else
+  h=${duration%%:*} 
+  m=${duration%:*} && m=${m#*:} 
+  s=${duration##*:} 
+  duration_errors=""
+  if [ $h -gt 5 ]; then
+    echo "??? Are you sure this recording is $h hours long?"
+  fi
+  if [ $m -gt 59 ]; then
+    duration_errors="${duration_errors}    $m min is more than one hour.\n"
+  fi
+  if [ $s -gt 59 ]; then
+    duration_errors="${duration_errors}\n    $s s is more than one minute.\n"
+  fi
+fi
+
 if [ -n "$missing" ]; then
-  echo 1>&2 "!!! These required field(s) have no data:
-   $missing"
+  printf 1>&2 "!!! These required fields have no data:\n   ${missing}"
+  errors=1
+fi
+if [ -n "$wrong_data" ]; then
+  printf 1>&2 "\n!!! These fields have wrong data:${wrong_data}"
+  errors=1
+fi
+if [ -n "$duration_errors" ]; then
+  printf 1>&2 "\n!!! Error(s) in the Duration field:\n${duration_errors}"
+  errors=1
+fi
+if [ -n "$errors" ]; then
+  printf 1>&2 "\nExit.\n"
   exit 1
 fi
 
+
+echo "${0##*\/}: Generating a new audio/video entry in rec format..."
+
 # Fill the empty fields: by, year, formatted date, lang, length, media.
 
-id=${Id#* }
 if [[ $id =~ "rms" ]]; then by="Richard Stallman"; fi
 
 date=$(echo $id |
@@ -83,68 +132,43 @@
   fdate=$(date "+%B %d, %Y" -d "$date")
 fi
 
-language=$(echo $Language | sed 's,^[a-zA-Z]\+: \([a-zA-Z]\+\)\( .*\)\?$,\1,')
-if [[ $language =~ " " ]]; then
-  echo 1>&2 "!!! The Language field has wrong data: \"$language\"; exit"
-  exit 1
-else
-  case $language in
+case $language in
        English) lang="en";;
        Spanish) lang="es";;
         French) lang="fr";;
      Malayalam) lang="ml";;
              *) lang="other";;
-  esac
-fi
-
-duration=${Duration#* }
-if ! echo $duration | grep -q '^[0-9]:[0-9]\{1,2\}:[0-9]\{1,2\}$'; then
-  echo "!!! The Duration field has wrong data: $duration; exit"
-  exit 1
-fi
+esac
 
-h=${duration%%:*} && h=${h#0}
-m=${duration%:*} && m=${m#*:} && m=${m##0}
-s=${duration##*:} && s=${s##0}
-errors=""
 duration=""
-if [ "$h" != "" ]; then
-  if [ $h -gt 5 ]; then
-    echo "??? Are you sure this recording is $h hours long?"
-  fi
+m=${m#0}; s=${s#0}
+if [ "$h" != "0" ]; then
   duration=${h}h
   hs=$(( $h * 3600 ))
 fi
-if [ "$m" != "" ]; then
-  if [ $m -gt 59 ]; then
-    m_error="\n    $m min is more than one hour."
-    errors=1
-  else
+if [ "$m" != "0" ]; then
     duration="$duration ${m}min"
     ms=$(( $m * 60 ))
-  fi
 fi
-if [ "$s" != "" ]; then
-  if [ $s -gt 59 ]; then
-    s_error="\n    $s s is more than one minute."
-    errors=$(( $errors + 1 ))
-  else
+if [ "$s" != "0" ]; then
     duration="$duration ${s}s"
-  fi
 fi
 
-if [ "$errors" != "" ]; then
-  printf 1>&2 "!!! Error(s) in the Duration field: $m_error $s_error\nExit.\n"
-  exit 1
+ts=$(( $hs + $ms + $s ))
+if   [ $ts -gt 2700 ]; then tlength='long'
+elif [ $ts -lt  600 ]; then tlength='short'
+else                        tlength='medium'
 fi
 
-ts=$(( $hs + $ms + $s ))
-if   [ $ts -gt 2700 ]; then
-  tlength='long'
-elif [ $ts -lt  600 ]; then
-  tlength='short'
-else
-  tlength='medium'
+# Create missing entries.
+
+grep -q '^Year:'   entry || sed -i '/^Id: /     aYear:' entry
+grep -q '^Lang:'   entry || sed -i '/^Type: /   iLang:' entry
+grep -q '^Length:' entry || sed -i '/^Type: / aLength:' entry
+grep -q '^Media:'  entry || sed -i '/^Length:/ aMedia:' entry
+if ! grep -q '^Date:' entry; then
+  if grep -q '^Location:' entry; then sed -i '/^Location: / iDate:' entry
+  else sed -i '/^Language: / iDate:' entry; fi
 fi
 
 awk -v year="$year" -v lang="$lang" -v tlength="$tlength" -v media="$media" \
@@ -162,6 +186,7 @@
 
 # Convert entry.rec to entry.html and add it to media.html,
 # then add entry.rec to media.rec.
+
 add_entry $entry_rec
 
 # Make sure this entry isn't reused by mistake.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]