Skip to content

Instantly share code, notes, and snippets.

@quillaja
Last active December 7, 2020 01:24
Show Gist options
  • Save quillaja/db528948255f6368c9f006984059f25c to your computer and use it in GitHub Desktop.
Save quillaja/db528948255f6368c9f006984059f25c to your computer and use it in GitHub Desktop.
fish shell script to download archived xray.fm shows
#! /usr/bin/fish
#==============
# This is a fish shell script to download archived mp3 files of shows
# from the radio station XRAY (krxy).
#==============
# get show numbers given show title (in url style)
# curl -s https://xray.fm/shows/home-of-space-paranoid | grep -Poe '(?<=title"\>\<a href="\/broadcasts\/)\d*?(?=")'
# get show mp3 given show number
# curl -s https://xray.fm/broadcasts/22520 | grep -Poe 'http.*mp3(?=")' | wget -i -
# "global" of shows i'm interested in
set shows "home-of-space-paranoid" "gothique-boutique"
# "global" of shownum file
set prevDLedShows "shownums.txt"
# read file of already downloaded shows
while read -la line
set showNumsFile $showNumsFile $line
end < $prevDLedShows
# get the list of show numbers for each show name
for show in $shows
set showNumsAll $showNumsAll (curl -s https://xray.fm/shows/$show | grep -Poe '(?<=title"\>\<a href="\/broadcasts\/)\d*?(?=")')
end
# filter out the shows that are already in the list of downloaded shows (build clean list)
for show in $showNumsAll
if not contains $show $showNumsFile
set showNums $showNums $show
end
end
# get the url of the MP3 for each show
set n (count $showNums)
for show in $showNums
set urls $urls (curl -s https://xray.fm/broadcasts/$show | grep -Poe 'http.*mp3(?=")')
end
# echo $urls (count $urls)
# download each show
if math (count $urls) > 0
echo $urls | xargs wget
end
# append/add downloaded show numbers to file
if math $n > 0
echo $showNums >> $prevDLedShows
echo $n "downloaded:"
for i in (seq $n)
echo $showNums[$i]"," $urls[$i]
end
else
echo "no shows downloaded"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment