#!/bin/bash # Generates a feed file for droid nation # Feed base URL feedbase="http://www.quadronyx.org/mirror/podcasts/droidnation/" # ..xml # Feed title and description feedtitle="Droid Nation Audio Cast (UNOFFICIAL FEED)" feeddesc="Droid Nation was an audio cast (also known as a podcast) about \ "'"'"rooting and hacking Android devices"'"'". There are 53 episodes in \ total, now hosted at the AMAZING archive.org." # Author (us) name and email authorname="Quadronyx (on behalf of Droid Nation)" authoremail="droidnationfeed@quadronyx.org" # File host URL and tag filehost="https://archive.org/details/droidnation" feedtag="archive.org,2015" # File base URL filebase="https://archive.org/download/droidnation/droidnation0" # . # Now now="$(date -u)" [ ${#} -ne 2 ] && { echo "Usage: $(basename "${0}") [ogg|mp3|all] [rss|atom|all]" exit 1 } ### types [ "${1}" == "all" ] && { types=(ogg mp3) } || { types=("${1}") } shift 1 [ "${types[0]}" != "ogg" ]\ && [ "${types[0]}" != "mp3" ]\ && { # Invalid type echo "Invalid type specified (${types[0]})" >&2 exit 2 } ### feeds [ "${1}" == "all" ] && { feeds=(rss atom) } || { feeds=("${1}") } shift 1 [ "${feeds[0]}" != "rss" ]\ && [ "${feeds[0]}" != "atom" ]\ && { # Invalid feed echo "Invalid feed specified (${feeds[0]})" >&2 exit 2 } ### START for t in "${types[@]}"; do #{ ### CREATE HEADERS for f in "${feeds[@]}"; do #{ outfile="${t}.${f}.xml" >"${outfile}" [ "${f}" == "rss" ] && { cat <>"${outfile}" ${feedtitle} $(date -uR) ${feeddesc} ${filehost} EOF } [ "${f}" == "atom" ] && { cat <>"${outfile}" ${feedtitle} ${authorname} ${authoremail} $(date -u --rfc-3339=seconds|tr ' ' T) ${feeddesc} tag:${feedtag}:${filehost} EOF } done #} ### CREATE ENTRIES for e in $(seq -w 53 -1 1); do #{ lastmod="${now}" contlen="0" while read line; do #{ # Get the first bit firstbit="${line%% *}" # NOTE: For this cast, the file dates are all borked :/ # # Check if lowercase firstbit is last-modified # [ "${firstbit,,}" == "last-modified:" ] && { # # Last-Modified # lastmod="${line#* }" # } # Check if lowercase firstbit is content-length [ "${firstbit,,}" == "content-length:" ] && { # Content-Length contlen="${line#* }" } done < <(\ curl -LIs ${filebase}${e}.${t}\ |tr -d '\r'\ |egrep 'Content-Length|Last-Modified'\ ) #} for f in "${feeds[@]}"; do #{ outfile="${t}.${f}.xml" [ "${f}" == "rss" ] && { # NOTE: For some reason the w3c validator says the URL is invalid when it's # https :S ... hence the substitution below cat <>"${outfile}" Episode ${e} Episode ${e} tag:${feedtag}:${filebase}${e}.${t} $(date -d "${lastmod}" -uR) EOF } [ "${f}" == "atom" ] && { cat <>"${outfile}" Episode ${e} Episode ${e} tag:${feedtag}:${filebase}${e}.${t} $(date -d "${lastmod}" -u --rfc-3339=seconds|tr ' ' T) EOF } done #} done #} ### CREATE FOOTERS for f in "${feeds[@]}"; do #{ outfile="${t}.${f}.xml" [ "${f}" == "rss" ] && { cat <>"${outfile}" EOF } [ "${f}" == "atom" ] && { cat <>"${outfile}" EOF } done #} done #}