├── README.md └── podcast-download.sh /README.md: -------------------------------------------------------------------------------- 1 | # Bash Podcast Download 2 | A simple bash script to download all media from a podcast feed 3 | 4 | ##Usage 5 | Call the script using 6 | 7 | sh podcast-download.sh http://myfeed.com/rss /PATH/TO/DOWNLOAD/FOLDER 8 | 9 | ###Optional 10 | 11 | You can hardcode the feed and output path by changing the variables at the top of the file. You can then ommit the feed and folder when envoking the script 12 | 13 | # Optional Variables 14 | # You can hardcode the feed and url variables here to avoid sending them when envoking the script 15 | 16 | FEED='http://myfeed.com/rss' 17 | FOLDER='/PATH/TO/MY/FOLDER' 18 | 19 | 20 | If the media file already exsists then the file is not downloaded. 21 | 22 | Assumes that the RSS feed is formatted correctly with media in the correct hirachy 23 | 24 | ####Feed requirments 25 | 26 | 27 | 28 | 29 | ...nodes... 30 | 31 | ...nodes... 32 | 33 | 34 | 35 | ...nodes... 36 | 37 | 38 | 39 | 40 | 41 | 42 | ####Platform Requirments 43 | This script was written on an OSX machine so assumes that you have the following programs installed 44 | 45 | - curl 46 | - xpath 47 | - egrep 48 | - sed 49 | 50 | ####TODO 51 | 52 | - Create option to rename files to the title of the item + original file extension 53 | - Create start and end paramaters to limit range of downloaded podcasts 54 | -------------------------------------------------------------------------------- /podcast-download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # 4 | # Description: A simple bash script to download all media from a podcast XML feed 5 | # 6 | # Usage: sh podcast-download.sh http://myfeed.com/rss /PATH/TO/FOLDER 7 | # 8 | # Author: Andrew Morton 9 | # Url: https://github.com/mortocks/bash-podcast-download 10 | # 11 | # Licence: GNU v3.0 12 | 13 | 14 | # Optional Variables 15 | # You can hardcode the feed and url variables here to avoid sending them when envoking the script 16 | FEED='' # URL TO THE RSS FEED 17 | FOLDER='' # RELATIVE PATH OF FOLDER TO DOWNLOAD FILES TO 18 | 19 | # Override hardcoded feeds with passed variables 20 | [ -n "$1" ] && FEED=$1 21 | [ -n "$2" ] && FOLDER=$2 22 | 23 | # Check if feed is empty 24 | if [ -z "$FEED" ]; then 25 | echo "Error: No feed specified"; exit 26 | fi 27 | 28 | # Check if path is empty 29 | if [ -z "$FOLDER" ]; then 30 | echo "Error: No folder specified"; exit 31 | fi 32 | 33 | # Create destination folder if it doesn't exsist 34 | if [ -d $FOLDER ]; then 35 | echo "$FOLDER exists" 36 | else 37 | echo "Creating directory $FOLDER" 38 | mkdir $FOLDER 39 | fi 40 | 41 | 42 | STARTTIME=`date +%s` 43 | 44 | 45 | # Get the full XML feed | extract the enclosure url attribute | extract the url 46 | MEDIA=$(curl -s $FEED | xpath '/rss/channel/item/enclosure/@url' 2>/dev/null | egrep -o 'https?://[^"<]+' ) 47 | 48 | 49 | # Loop through and download file if not already downloaded 50 | while IFS= read -r URL 51 | do 52 | 53 | # Find the last part of the url using the / as delimiter 54 | AFTER_SLASH=${URL##*/} 55 | 56 | # Remove any additional query params in the filename by removing everything after ? 57 | FILE_NAME=${AFTER_SLASH%%\?*} 58 | 59 | DATE=$(date) 60 | 61 | # If file as already been downloaded ignore 62 | if [ -f $FOLDER/$FILE_NAME ]; then 63 | echo "Exsists $URL $FOLDER/$FILE_NAME $FILE_NAME $DATE" 64 | else 65 | echo "Download $URL $FOLDER/$FILE_NAME $FILE_NAME $DATE" 66 | curl -s -L $URL > $FOLDER/$FILE_NAME 67 | fi 68 | 69 | done <<< "$MEDIA" 70 | 71 | ENDTIME=`date +%s` 72 | echo Finished total time `expr $ENDTIME - $STARTTIME`s. --------------------------------------------------------------------------------