Created
November 6, 2020 15:28
-
-
Save goldfndr/2b6a7ef111260dfb7d8f3c3293927ba9 to your computer and use it in GitHub Desktop.
Retrieve on demand audio files from Radio Free America rackspace (no longer in use)
This file contains 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
@echo off | |
set wget="C:\Program Files (x86)\GnuWin32\bin\wget.exe" --no-check-certificate | |
setlocal EnableDelayedExpansion | |
rem @echo "Merge MP3" (Downloads) to combine, Kid3 (Start) to change tags | |
if "%1"=="" goto usage | |
:@echo off | |
set date=%1 | |
if "%1"=="next" ( | |
rem Get the already retrieved date | |
for /F "tokens=2 delims=_-" %%i in ('dir /b *202004*-*.mp3') do set date=%%i | |
rem echo date=!date! | |
rem FIXME: Add a week to it; https://stackoverflow.com/q/355425 | |
rem goto :EOF | |
) | |
rem Customize hours for desired defaults | |
:Note: 07:00 at PST8PDT7 is 14 in summer, 15 in winter; Loop syntax: (start,step,end) | |
set hours=14,1,15 | |
rem set hours=15,1,16 | |
rem Thanksgiving: 6am (14 UTC) for 6 hours | |
rem set hours=14,1,19 | |
rem set hours=14,1,17 | |
if not "%2"=="" set hours=%2 | |
echo Looping through %hours% | find "," | |
if ERRORLEVEL 1 set hours=%hours%,1,%hours% | |
set minutes=00 15 30 45 | |
if not "%3"=="" set minutes=%3 | |
rem Customize these for desired defaults | |
set host=https://rfa-rackspace-archive-prod.s3.amazonaws.com | |
set station=knhc | |
set filesize=14400366 | |
rem Iterate through the requested files | |
set bytes=0 | |
set count=0 | |
for /L %%h in (%hours%) do ( | |
for %%m in (%minutes%) do ( | |
if not exist %station%_%date%-%%h%%m00.mp3 %wget% %host%/%station%_%date%-%%h%%m00.mp3 | |
set /A count += 1 | |
set /A bytes += %filesize% | |
) | |
) | |
rem Separate thousands calculations, hoping for enough luck to not need zero padding | |
set /A MB=%bytes% / 1000 / 1000 | |
set /A kB=%bytes% / 1000 %% 1000 | |
set /A B=%bytes% %% 1000 | |
rem Present downloaded files results; store to a file instead of performing a command twice | |
if "%2"=="" dir %station%_%date%-* | findstr "%date% bytes" | findstr /V "free" > _dir.txt | |
if not "%2"=="" if "%3"=="" dir %station%_%date%-%2* | findstr "%date% bytes" | findstr /V "free" > _dir.txt | |
if not "%3"=="" dir %station%_%date%-%2%3* | findstr "%date% bytes" | findstr /V "free" > _dir.txt | |
type _dir.txt | |
rem Put the sum in an environment variable | |
for /f "tokens=*" %%A in (_dir.txt) do set "totals=%%A" | |
del _dir.txt | |
rem Display a downloaded files results check line for visually comparing byte count. | |
title %totals% // %count% File(s) %MB%,%kB%,%B% bytes | |
rem Add padding depending on count's one vs two digits & MB's two vs three digits. | |
rem (A closing parenthesis in an echo is interpreted as ending an open one, so must escape.) | |
rem echo Should read: 12 file(s) 172,804,392 bytes; if not then: | |
if %count% GEQ 10 ( | |
echo Expected: %count% File^(s^) %MB%,%kB%,%B% bytes ^(%bytes%^); if much less then | |
) else if %MB% GEQ 100 ( | |
echo Expected: %count% File^(s^) %MB%,%kB%,%B% bytes ^(%bytes%^); if much less then | |
) else ( | |
echo Expected: %count% File^(s^) %MB%,%kB%,%B% bytes ^(%bytes%^); if much less then | |
) | |
echo %wget% | |
echo %host%/%station%_%date%- | |
choice /M "Combine 15 minute blocks into hour blocks" | |
title Command Prompt | |
if ERRORLEVEL 2 goto :EOF | |
for /L %%h in (%hours%) do ( | |
call combine %date% %%h | |
pause | |
) | |
goto :EOF | |
:usage | |
echo Downloads a radio station's on demand files, e.g. https://www.c895.org/ondemand/ | |
echo. | |
echo %0 date [h [m]] | |
echo h Specifies an hour (e.g. 14) or start,step,end syntax (e.g. 14,1,16) | |
echo m Specifies a two digit minute (e.g. 00). | |
echo. | |
echo start,step,end syntax yields a sequence of numbers from start to end by step. | |
echo So 14,1,6 would generate the sequence 14 15 16. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment