Created
April 29, 2025 06:16
-
-
Save FalsePhilosopher/9e0c18b999b7558385c9d15e197188be to your computer and use it in GitHub Desktop.
KRCL DL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# REQUIREMENTS: wget, grep, sed, awk, date, basename | |
set -e | |
scrape_shows() { | |
curl -s https://krcl.org/shows/ | grep -oP '(?<=href="/shows/)[^"/]+' | sort -u | grep -vE '^(about|events|shows|rss|news|programs|genre|support)' | |
curl -s https://krcl.org/shows/ | grep -oP '(?<=href="/)[^"/]+' | sort -u | grep -vE '^(about|events|shows|rss|news|programs|genre|support)' | |
} | |
shows=($(scrape_shows)) | |
if [ ${#shows[@]} -eq 0 ]; then | |
echo "Failed to fetch show list. Exiting." | |
exit 1 | |
fi | |
echo "Available shows:" | |
for i in "${!shows[@]}"; do | |
printf "%3d) %s\n" $((i+1)) "${shows[$i]}" | |
done | |
read -p "Select a show number: " show_number | |
selected_show="${shows[$((show_number-1))]}" | |
read -p "How many months back? (3/6/9/12/24/64): " months | |
read -p "What day of the week does it air? (1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat, 7=Sun): " weekday_target | |
read -p "What start time? (example: 22-00-00): " start_time | |
echo "Downloading $selected_show for the last $months months, every $weekday_target at $start_time..." | |
base_url="https://krcl-media.s3.us-west-000.backblazeb2.com/audio/$selected_show" | |
mkdir -p "$selected_show" | |
cd "$selected_show" || exit 1 | |
start_date=$(date +%Y-%m-%d) | |
end_date=$(date -d "$start_date -$months months" +%Y-%m-%d) | |
current_date="$start_date" | |
while [[ "$current_date" > "$end_date" ]]; do | |
weekday=$(date -d "$current_date" +%u) | |
if [[ "$weekday" -eq "$weekday_target" ]]; then | |
filename="${selected_show}_${current_date}_${start_time}.mp3" | |
file_url="$base_url/$filename" | |
if [[ -f "$filename" ]]; then | |
echo "Already downloaded: $filename, skipping." | |
else | |
echo -n "Checking $filename... " | |
if wget --spider -q "$file_url"; then | |
echo "found! Downloading..." | |
wget -q --show-progress "$file_url" | |
else | |
echo "not found, skipping." | |
fi | |
fi | |
fi | |
current_date=$(date -d "$current_date -1 day" +%Y-%m-%d) | |
done | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment