#!/bin/bash ##################################################### # Podcatcher Script # # you must first make a text file in the same directory # that contains the feeds and name the text file podlist.txt # # Made By : Ibrahim Riad ##################################################### ##################################################### # Declaring variables ##################################################### main_directory="$HOME/Podcast" podcast_directory="$main_directory/podcasts" download_directory="$main_directory/shows" archive_directory="$main_directory/archive" #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #NOTE: Dont put the history file in the podcast_directory #or the download_directory as it will be deleted #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! history="$main_directory/downloaded_history.txt" podcast_number="3" alarm="/usr/lib/openoffice/share/gallery/sounds/applause.wav" multimedia_player="xmms" stream_player="kaffeine" function clean_up { # Perform program exit housekeeping echo "" echo "" echo -e "\033[0;31mThe script was exited unexpectatly\033[0m" echo "" echo -e "\033[0;31mTemp files removed\033[0m" echo "" sleep 1 rm "$podcast_directory"/* 2>/dev/null exit } trap clean_up SIGHUP SIGINT SIGTERM #<---------------------------------------------------> ##################################################### # Specifying options ##################################################### while [ "$1" != "" ];do case $1 in -n|--podcast_number ) podcast_number="$2" ;; -c|--clean ) rm "$download_directory"/* 2>/dev/null rm "$podcast_directory"/* 2>/dev/null echo -e "\033[0;31mDirectory Cleaned\033[0m" exit ;; -a|--archive ) if [ ! -d "$archive_directory" ];then echo -e "\033[0;32mMaking archive directory\033[0m" echo "" mkdir "$archive_directory" fi cp "$download_directory"/*.mp3 "$archive_directory" 2>/dev/null cp "$download_directory"/*.ogg "$archive_directory" 2>/dev/null echo -e "\033[0;31mPodcasts archived\033[0m" exit ;; -p|--play ) $multimedia_player "$download_directory/latest.m3u" & exit ;; -d|--download ) download="y" ;; -h|--help ) echo " Usage: $0 [OPTIONS] Options are: -n, --podcast_number Specify the number of podcast per each stream to be downloaded -c, --clean Delete the podcasts and playlist -p, --play Play the playlist -d, --download Downloads aoutomatically new podcasts -h, --help Display this text and exit Examples: $0 -n 1 Will download the latest podcasts $0 -n 1 -d Will download the latest podcasts without confirmation " exit ;; esac shift done #<---------------------------------------------------> clear ##################################################### # Checking directories ##################################################### echo "#################################" echo "# Checking directories" echo "#################################" echo "" if [ -d "$main_directory" ];then echo -e "\033[0;32mMain directory exists\033[0m" echo "" else echo -e "\033[0;32mMaking main directory\033[0m" echo "" mkdir "$main_directory" fi if [ -d "$podcast_directory" ];then echo -e "\033[0;32mPodcast directory exists\033[0m" echo "" else echo -e "\033[0;32mMaking podcast directory\033[0m" echo "" mkdir "$podcast_directory" fi if [ -d "$download_directory" ];then echo -e "\033[0;32mDownload directory exists\033[0m" echo "" else echo -e "\033[0;32mMaking download directory\033[0m" echo "" mkdir "$download_directory" fi #<---------------------------------------------------> ##################################################### # Downloading feeds ##################################################### echo "#################################" echo "# Downloading feeds" echo "#################################" echo "" if [ ! -f "$main_directory/podlist.txt" ];then echo -e "\033[0;31mFile podlist.txt doesnt exists\033[0m" echo "" echo -n "Create one ? (y/n) : " read cpod echo "" if [ $cpod == "y" ];then touch "$main_directory/podlist.txt" echo "It's created but its empty now , you could check out http://www.podcast.net/ http://www.podcastalley.com/ for some feeds" echo "" rm "$main_directory/lock" exit else rm "$main_directory/lock" exit fi fi if [ ! -s "$main_directory/podlist.txt" ];then echo "The podlist.txt file is empty , you could check out http://www.podcast.net/ http://www.podcastalley.com/ for some feeds" echo "" rm "$main_directory/lock" exit fi echo "" for i in `cat "$main_directory/podlist.txt"` do echo -e "\033[0;32mDownloading feed ....\033[0m" echo "" wget -t 2 -P "$podcast_directory" "$i" done #<---------------------------------------------------> ##################################################### # Filter the feeds from the mp3 and ogg parts ##################################################### cd "$podcast_directory" for p in `ls` do cat $p | grep audio/mpeg > $p.log cat $p | grep audio/ogg >> $p.log done #<---------------------------------------------------> ##################################################### # Clean the output of the filter ##################################################### for x in `ls *.log` do cat "$x" | head -n $podcast_number | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p' >> final.txt done #<---------------------------------------------------> clear ##################################################### # Download the podcast and keep a history of it ##################################################### echo "#################################" echo "# Download or stream the podcast" echo "#################################" echo "" for d in `cat final.txt` do temp=$(cat "$history" | grep "$d") 2>/dev/null exists=$(echo $?) echo "" if [ $exists -eq 1 ];then if [ "$download" == "y" ];then choise="d" else read -s -n1 -p "Download or Stream : $d (d/s/n) ? " choise fi echo "" if [ $choise == "d" ] || [ $choise == "D" ] || [ $choise == "y" ];then echo -e "\033[0;32mDownloading : \033[0m" "$d" echo "" wget -c -P "$download_directory" "$d" && echo "$d" >> "$history" && cat "$alarm" > /dev/dsp elif [ $choise == "s" ] || [ $choise == "S" ];then echo -e "\033[0;32mStreaming : \033[0m" "$d" echo "" echo "$d" >> "$history" $stream_player "$d" & else echo -e "\033[0;31mSkipping : \033[0m" "$d" echo "" fi else echo -e "\033[0;31mYou already downloaded \033[0m" "$d" echo "" continue fi done #<---------------------------------------------------> ##################################################### # Create an m3u playlist ##################################################### ls -1rc "$download_directory" | grep -v m3u > "$download_directory/latest.m3u" #<---------------------------------------------------> ##################################################### # Cleanup ##################################################### rm * 2>/dev/null echo "#################################" echo -e "#""\033[0;32m Done \033[0m" echo "#################################" echo ""