Register
It is currently Wed Apr 16, 2014 10:45 am

downloading "new" MP3's from a website.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Fri Jul 17, 2009 7:12 am   

Joined: Fri Jul 17, 2009 6:36 am
Posts: 1
Hi,

I am not a programmer but I needed to cobble together a script to save me time
manually downloading MP3's of a radio show that I like.

The functionality of the script is actually good so far however I am trying to remove
a puzzling error message. The script was originally in KSH because I found an old
reference book on this shell. I then realised that I don't have this shell so I have
modified it to run in BASH.

I have installed the Cygwin environment on a Windows PC.
Here is the script:
Code:
#!/usr/bin/bash
exec 2>/dev/null         #In KSh this sends ALL standard error for the script to dev/null but is this true for BASH?

function cleanup {
    if [[ -a core ]]; then
        rm core
    fi
    exit
}

trap cleanup INT TERM

while getopts ":f:u:" opt; do
    case $opt in
            f  ) FOLDER="$OPTARG" ;;
            u  ) URL="$OPTARG" ;;
            \? ) print >&2 "usage: rsi [-f LOCAL_FOLDER] [-u DOWNLOAD_URL]"
                 return 1
    esac
done
shift $(($OPTIND - 1))

URL=${URL:-"http://www.slovakradio.sk/inetportal/rsi/core.php?lang=2"}
FOLDER=${FOLDER:-"C:/RSI"}

for i in $(lynx -source $URL | grep -o 'http://[^"]*.mp3' | uniq -i | sort -n | tail -6)
do
   rsifile=$(basename $i)
   if test -e $FOLDER/$rsifile
   then
      print "$rsifile was already downloaded."
   else
      print "Downloading $rsifile to $FOLDER."
      wget -c --no-proxy --directory-prefix=$FOLDER $i
      if test -s $FOLDER/$rsifile
      then
         print "Downloaded this file:"
      fi
   fi
done

exit 0


This is the output I get when the script finds existing files matching the new MP3's
that I find from the webpage's source.
$ ./rsi -f Z:/RSI 2>/dev/null | tee logfile.txt
Quote:
Can't find file ondemandRSI_relID2_soundID7338.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7344.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7349.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7356.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7362.mp3 was already downloaded.
Can't find file ondemandRSI_relID2_soundID7369.mp3 was already downloaded.


What is causing the "Can't find file " string in this error message? It's coming out of file descriptor 1 not 2
if that's significant at all since I am redirecting all standard error to dev/null.
Thanks, Nick.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP