aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xapod-bot.sh12
1 files changed, 5 insertions, 7 deletions
diff --git a/apod-bot.sh b/apod-bot.sh
index 5bd3952..ffa2a1d 100755
--- a/apod-bot.sh
+++ b/apod-bot.sh
@@ -27,14 +27,12 @@ apod_html=$(curl -sS $apod_base_url/astropix.html)
title=$(echo "$apod_html" | pup 'center:nth-child(2) > b:nth-child(1) text{}' \
| sed -e 's/^ *//' -e 's/ *$//')
-image_link=$apod_base_url/$(echo "$apod_html" | pup -p 'img attr{src}')
-youtube_video_id=$(echo "$apod_html" | pup 'iframe attr{src}' | awk -F/ '{print $5}' | awk -F? '{print $1}')
-youtube_link="https://www.youtube.com/watch?v=$youtube_video_id"
-if [[ -z "$youtube_video_id" ]]
-then
- media_link=$image_link
+if [[ -z "$(echo "$apod_html" | pup 'iframe attr{src}')" ]]; then
+ media_link=$apod_base_url/$(echo "$apod_html" | pup -p 'img attr{src}')
else
- media_link=$youtube_link
+ media_link=$(echo "$apod_html" | pup 'iframe attr{src}' | sed 's/?.*//' \
+ | sed 's|player.vimeo.com/video|vimeo.com|' \
+ | sed 's|embed/|watch?v=|')
fi
date=$(echo "$apod_html" | pup ':contains("Discuss") attr{href}' | awk -F= '{print $2}')
page_link=$apod_base_url/ap$date.html