Last active
May 10, 2021 13:15
-
-
Save mberkowski/eedda15fbb4e42e878079cd1eb65a2e4 to your computer and use it in GitHub Desktop.
MPR Classical Daily Download Downloader
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 | |
# | |
# https://www.yourclassical.org/topics/daily-download | |
# Downloads an MPR Classical "Daily Download" mp3 file | |
# to $HOME/music/mprdailydownload. | |
# Supply a date argument as YYYY-MM-DD for a specific date's download | |
# or omit the argument for today's download. | |
# | |
# If the command `ffprobe` (from `ffmpeg`) is available, the file will be renamed as | |
# YYYYMMDD-Composer_composer-Title-title.mp3 | |
# | |
# Example cron entry (every weekday morning at 7am), with logfile | |
# 0 7 * * 1-5 /path/to/mprdailydownload.sh >> /path/to/mprdailydownload.log 2>&1 | |
# | |
# USAGE: | |
downloads_dir=$HOME/music/mprdailydownload | |
# Accepts a date argument as YYYY-MM-DD or defaults to today | |
date=${1:-today} | |
filedate=$(date -d "$date" +%Y%m%d) | |
# URL root | |
root="https://play.publicradio.org/web/o/minnesota/classical/programs/free-downloads/" | |
downloadfile="$(date -d "$date" +%Y/%m/%d)/daily_download_${filedate}_128.mp3" | |
savefile="${downloads_dir}/mprdailydownload_$(basename $downloadfile)" | |
mkdir -p $downloads_dir | |
# Download via wget | |
wget -nv -O "$savefile" "${root}${downloadfile}" | |
# Rename the file with composer-title if ffprobe from ffmepg is available | |
# Originally used id3info, but that fails to read some tag formats | |
# ffprobe seems more reliable, and might be more widely available anyway. | |
if [ "$(command -v ffprobe)" ] | |
then | |
# Retrieve individual id3 tag frames, replace space with underscores, trim leading _ | |
#composer=$(id3info $savefile | grep TCOM | cut -d: -f2- | tr ' ' '_' |sed -e 's/^_//g') | |
composer=$(ffprobe $savefile 2>&1 | grep -e 'composer \+: ' | cut -d: -f2 | tr ' ' _ | sed -e 's/^_//g') | |
#title=$(id3info $savefile | grep TIT2 | cut -d: -f2- | tr ' ' '_' | sed -e 's/^_//g') | |
title=$(ffprobe $savefile 2>&1 | grep -e 'title \+: ' | cut -d: -f2 | tr ' ' _ | sed -e 's/^_//g') | |
metaname="${filedate}-${composer}-${title}-128.mp3" | |
echo "Renaming $(basename $savefile) to ${metaname}..." | |
mv "$savefile" "${downloads_dir}/${metaname}" | |
fi | |
# Michael Berkowski, 2019 | |
# GitHub @mberkowski | |
# Special thanks to MPR Classical for providing the daily download |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment