Skip to content

Commit

Permalink
Conditionally shut down
Browse files Browse the repository at this point in the history
Only shut down if any video was found. If not, that means that we're starting up the server manually, in which case we *want* it to stay on. Closes #64.
  • Loading branch information
waldoj committed Jun 21, 2019
1 parent abc7ed3 commit f8dc5c8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
32 changes: 13 additions & 19 deletions bin/handler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ function finish {
cd ..
rm -Rf video/

if [[ -v "SHUTDOWN" ]]; then
echo "[WOULD SHUT DOWN SERVER NOW]"
#sudo shutdown -h now
if [[ -v "SHUTDOWN" ]] && [[ "$ANY_VIDEO_FOUND" == true ]]; then
sudo shutdown -h now
else
cd bin/
cd bin/ || exit
./handler.sh || exit
fi

Expand All @@ -21,6 +20,9 @@ function finish {
# Run the finish() function every time this script exits for any reason.
trap finish EXIT

# Establish a flag that indicates whether any video has been found
ANY_VIDEO_FOUND=false

# Change to the directory containing this script.
cd "$(dirname "$0")" || exit 1

Expand All @@ -34,6 +36,7 @@ cd "$VIDEO_DIR" || exit 1
php ../bin/get_video.php
GOT_VIDEO=$?
if [ $GOT_VIDEO -eq 1 ]; then
ANY_VIDEO_FOUND=true
exit 1
elif [ $GOT_VIDEO -eq 2 ]; then
export SHUTDOWN=1
Expand All @@ -42,12 +45,12 @@ fi

# Turn the JSON into key/value pairs, and make them into environment variables.
eval "$(jq -r '. | to_entries | .[] | .key + "=\"" + .value + "\""' < metadata.json)"
set $filename
set $date
set $date_hyphens
set $s3_url
set $chamber
set $type
set "$filename"
set "$date"
set "$date_hyphens"
set "$s3_url"
set "$chamber"
set "$type"

# Define the name of the directory that will store the extracted chyrons.
export output_dir="${filename/.mp4/}"
Expand Down Expand Up @@ -94,12 +97,3 @@ if [ "$type" = "floor" ]; then
php ../bin/process_captions.php "$CAPTIONS_FILE" "$VIDEO_ID" || exit $?

fi

#/home/ubuntu/youtube-upload-master/bin/youtube-upload '
# . '--tags="virginia, legislature, general assembly" '
# . '--default-language="en" '
# . '--default-audio-language="en" '
# . '--title="Virginia ' . ucfirst($video['chamber']) . ', ' . date('F j, Y', strtotime($video['date'])) . '" '
# . '--recording-date="' . $DATE . 'T00:00:00.0Z" '
# . $DATE
##
12 changes: 12 additions & 0 deletions deploy/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Get the test video.
echo "Downloading test House video from S3"
curl -s -o test-house-video.mp4 https://s3.amazonaws.com/deploy.richmondsunlight.com/test-house-video.mp4

# OCR the video.
set output_dir=test-house-video
ocr.sh test-house-video.mp4 house

# Verify that the chyrons match what we expect them to be.
cat *.txt

0 comments on commit f8dc5c8

Please sign in to comment.