Register
It is currently Tue Jul 22, 2014 11:26 am

script for getting podcasts


All times are UTC - 6 hours


Post new topic Reply to topic  [ 16 posts ] 
Author Message
 PostPosted: Thu Aug 11, 2005 9:53 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
i found a country artist i like and he does a pod cast. so after some digging i found a simple podcast downloader for bash. i am having some problems getting it configured to work. here's the code, and what i have put in. thanks in advance guys. i am finding more time at work to practice bash so i plan on being here more often.

Code:
#!/bin/bash
# By Linc 10/1/2004
# Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder
# Last revision 07/01/2005 - Many Contributers!
# If you use this and have made improvements or have comments
# drop me an email at linc dot fessenden at gmail dot com
# I'd appreciate it!

# Make script crontab friendly:
cd $(/root/podcasts $0)
#[b]i added the new dir. this is for slax.[/b]
# datadir is the directory you want podcasts saved to:
/root/podcasts=$(date +%Y-%m-%d)

# Check for and create datadir if necessary:
if test ! -d $/root/podcasts
        then
        mkdir $/root/podcasts
fi

# Delete any temp file:
rm -f temp.log

# Read the bp.conf file and wget any url not already in the podcast.log file:
while read podcast
   do
   file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p')
   for url in $file
      do
      if ! grep "$url" podcast.log > /dev/null
         then
         wget -q -P $/root/podcasts "$http://www.jeffblack.com/blacktuesdays.xml" && echo $http://www.jeffblack.com/blacktuesdays.xml >> temp.log
#[b]the above url is for the podcast i want.[/b]
      fi
      done
   done < bp.conf
# Move dynamically created log file to permanent log file:
cat podcast.log >> temp.log
sort temp.log | uniq > podcast.log
rm temp.log
# Create an m3u playlist:
ls $/root/podcasts | grep -v m3u > $/root/podcasts/podcast.m3u


Top
 Profile YIM  
 PostPosted: Thu Aug 11, 2005 10:40 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
some things i'm not sure about and could use some clearing up :)
Code:
# Make script crontab friendly:
cd $(/root/podcasts $0)

jbsnake wrote:
here it's changing to a directory that hasn't been assigned yet...
i'm not sure why it's also naming the script here ($0)...
but let's go on...

Code:
# datadir is the directory you want podcasts saved to:
/root/podcasts=$(date +%Y-%m-%d)

jbsnake wrote:
first off... change the name of that variable /root/podcasts to datadir
so the above line would read
datadir=$(date +%Y-%m-%d)
next... i personally would never name a directory a date...
atleast not without having another higher directory
something like:

Code:
basedir="/home/${USER}/podcasts"
datadir="${basedir}/$(date +%Y-%m-%d)"

jbsnake wrote:
might be more appropriate.
now edit these lines...

Code:
# Check for and create datadir if necessary:
if test ! -d $/root/podcasts
        then
        mkdir $/root/podcasts
fi


to...

Code:
# Check for and create datadir if necessary:
if test ! -d "${basedir}"
        then
        mkdir "${basedir}"
fi

if test ! -d "${basedir}/${datadir}"
        then
        mkdir "${basedir}/${datadir}"
fi

make the next line read...
Code:
# Delete any temp file:
rm -f "${basedir}/${datadir}/temp.log"


instead :)

Code:
# Read the bp.conf file and wget any url not already in the podcast.log file:
while read podcast
   do
   file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' " | sed -n 's/.*url="\([^"]*\)".*/\1/p')
   for url in $file
      do
      if ! grep "$url" "${basedir}/${datadir}/podcast.log" > /dev/null
         then

jbsnake wrote:
also change the wget line to what i have below (copy and paste over what you have :)

Code:
         wget -q -P ${basedir}/${datadir} "http://www.jeffblack.com/blacktuesdays.xml" && echo http://www.jeffblack.com/blacktuesdays.xml >> "${basedir}/${datadir}/temp.log"
fi
      done
   done < bp.conf
#[b]the above url is for the podcast i want.[/b]

jbsnake wrote:
the $http:// portion... usually in bash $ means it's a variable

i also would like to know what the bp.conf file is...
the code above looks as though it would work... depending on the bp.conf file and whether or not that file is in the same directory as this script

the rest of this script looks fine... as long as you copy and paste what i have below over what you have to keep the variables matching :)


Code:
# Move dynamically created log file to permanent log file:
cat podcast.log >> "${basedir}/${datadir}/temp.log"
sort "${basedir}/${datadir}/temp.log" | uniq > "${basedir}/${datadir}/podcast.log"
rm "${basedir}/${datadir}/temp.log"
# Create an m3u playlist:
ls "${basedir}/${datadir}" | grep -v m3u > "${basedir}/${datadir}/podcast.m3u"


Top
 Profile  
 PostPosted: Thu Aug 11, 2005 11:09 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
thanks jb, i'll work on it tomorrow night. :)


Top
 Profile YIM  
 PostPosted: Sat Aug 13, 2005 1:13 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
hey jb, is there a way that i could make it so i would be prompted to provide the url :? i am thinking that i might include this on the slax disk.


Top
 Profile YIM  
 PostPosted: Sat Aug 13, 2005 11:51 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
ok... directly before this line:
Quote:
# Read the bp.conf file and wget any url not already in the podcast.log file:

type:
Code:
read -p "Please enter the url you want to add to the podcast list: " url

now there will not be any error checking at this point... but we will atleast be able to test it before release :)
the next line you have to edit will be:
Quote:
wget -q -P ${basedir}/${datadir} "http://www.jeffblack.com/blacktuesdays.xml" && echo http://www.jeffblack.com/blacktuesdays.xml >> "${basedir}/${datadir}/temp.log"
fi
done
done < bp.conf

it will need to be:
Code:
wget -q -P ${basedir}/${datadir} "${url}" && echo "${url}" >> "${basedir}/${datadir}/temp.log"
fi
      done
   done < bp.conf

and that should be it :)
hope it works... if not write me back here and i will try and fix it tonight (off to work i go :) )


Top
 Profile  
 PostPosted: Sat Aug 13, 2005 4:04 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
i'm at work now...so when it slows down i will try.


Top
 Profile YIM  
 PostPosted: Sat Aug 13, 2005 9:02 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
the bp.conf file is just a list of urls that the author likes.


Top
 Profile YIM  
 PostPosted: Sat Aug 13, 2005 9:07 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
ok i made all the necessary changes.

./bashpodder.sh

and i get this.
Code:
root@slax:~# ls
Desktop/  SLAX\ installer  Set\ IP\ address  bashpodder.sh  bashpodder.sh~
root@slax:~# ./bashpodder.sh
-bash: ./bashpodder.sh: Permission denied
root@slax:~#


Top
 Profile YIM  
 PostPosted: Sat Aug 13, 2005 9:20 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
:idea: wow it's amazing what looking at the properties will do. i need to do that some more. ok here's my new error.

Code:
root@slax:~# ./bashpodder.sh
./bashpodder.sh: line 14: ${basedir }/$(date +%Y-%m-%d): bad substitution
./bashpodder.sh: line 19: ${basedir }: bad substitution
./bashpodder.sh: line 46: syntax error: unexpected end of file
root@slax:~#


Edit: fixed the above....cept for the syntax at line 46
here is the code the way i did it.

Code:
#!/bin/bash
# By Linc 10/1/2004
# Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder
# Last revision 07/01/2005 - Many Contributers!
# If you use this and have made improvements or have comments
# drop me an email at linc dot fessenden at gmail dot com
# I'd appreciate it!

# Make script crontab friendly:
cd $(dirname $0)

# datadir is the directory you want podcasts saved to:
basedir="/home/$guest/podcasts"
datadir="${basedir }/$(date +%Y-%m-%d)"

# Check for and create datadir if necessary:
if test ! -d "${basedir}"
        then
        mkdir "${basedir }"
fi

if test ! -d "${basedir}/${datadir}"
   then
   mkdir "${basedir}/${datadir}"
# Delete any temp file:
rm -f "${basedir}/${datadir}/temp.log"

read -p "Please enter the url you want to add to the podcast list: " url
# Read the bp.conf file and wget any url not already in the podcast.log file:
while read podcast
   do
   file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p')
   for url in $file
      do
      if ! grep "$url" "${basedir}/${datadir}/podcast.log" > /dev/null
         then
         wget -q -P ${basedir}/${datadir} "${url}" && echo "${url}" >> "${basedir}/${datadir}/temp.log"
   fi
       done
   done < bp.conf
# Move dynamically created log file to permanent log file:
cat podcast.log >> "${basedir}/${datadir}/temp.log"
sort "${basedir}/${datadir}/temp.log" | uniq > "${basedir}/${datadir}/podcast.log"
rm "${basedir}/${datadir}/temp.log"
# Create an m3u playlist:
ls "${basedir}/${datadir}" | grep -v m3u > "${basedir}/${datadir}/podcast.m3u"



i think the problem is here

Code:
# Move dynamically created log file to permanent log file:
cat podcast.log >> "${basedir}/${datadir}/temp.log"
sort "${basedir}/${datadir}/temp.log" | uniq > "${basedir}/${datadir}/podcast.log"
rm "${basedir}/${datadir}/temp.log"
# Create an m3u playlist:
ls "${basedir}/${datadir}" | grep -v m3u > "${basedir}/${datadir}/podcast.m3u"



whatcha think.


Top
 Profile YIM  
 PostPosted: Sat Aug 13, 2005 10:56 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
coastie wrote:
# datadir is the directory you want podcasts saved to:
basedir="/home/$guest/podcasts"
datadir="${basedir }/$(date +%Y-%m-%d)"

# Check for and create datadir if necessary:
if test ! -d "${basedir}"
then
mkdir "${basedir }"
fi

the above is incorrect...
we don't have a value for $guest
i used $USER because that is a variable that is assigned to the shell, and will evaluate to the actual users' name
like, if you were logged in as coastie when you ran this script, $USER would evaluate to coastie.

also, the spaces after the word basedir and before the closing }...
those have to go :)

the above should be:
Code:
# datadir is the directory you want podcasts saved to:
basedir="/home/${USER}/podcasts"
datadir="${basedir}/$(date +%Y-%m-%d)"

# Check for and create datadir if necessary:
if test ! -d "${basedir}"
        then
        mkdir "${basedir}"
fi

coastie wrote:
if test ! -d "${datadir}"
then
mkdir "${datadir}"

right there is the "unexpected end of file"
no fi
we forgot to close the if statement...
but it gets better... i realized after finding this if statement error that we had a larger error... my dumb self made a redundant variable call
everywhere that i have ${basedir]/${datadir}is incorrect... they should just read ${datadir} :D
you can read the rest of this post (since i work from the back to the front of a script to error check it :) ) and see the little things i found when looking real close... or you can just copy and paste the code block at the bottom of this post... either way :)
coastie wrote:
# Delete any temp file:
rm -f "${datadir}/temp.log"

read -p "Please enter the url you want to add to the podcast list: " url
# Read the bp.conf file and wget any url not already in the podcast.log file:
while read podcast
do
file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' " | sed -n 's/.*url="\([^"]*\)".*/\1/p')

the above looks fine... but this next part needs to be fixed since we have a new variable called url
coastie wrote:
for url in $file
do
if ! grep "$url" "${datadir}/podcast.log" > /dev/null
then
wget -q -P ${datadir} "${url}" && echo "${url}" >> "${datadir}/temp.log"
fi
done
done < bp.conf

change that to:
Code:
   for furl in $file
      do
      if ! grep "${furl}" "${datadir}/podcast.log" > /dev/null
         then
         wget -q -P ${datadir} "${url}" && echo "${url}" >> "${datadir}/temp.log"
   fi
       done
   done < bp.conf

and then this part:
coastie wrote:
# Move dynamically created log file to permanent log file:
cat podcast.log >> "${datadir}/temp.log"

change that line to:
Code:
# Move dynamically created log file to permanent log file:
cat "${datadir}/podcast.log" >> "${datadir}/temp.log"


sort "${datadir}/temp.log" | uniq > "${datadir}/podcast.log"
rm "${datadir}/temp.log"
# Create an m3u playlist:
ls "${datadir}" | grep -v m3u > "${datadir}/podcast.m3u"
[/code]


i think the problem is here

Code:
# Move dynamically created log file to permanent log file:
cat podcast.log >> "${basedir}/${datadir}/temp.log"
sort "${basedir}/${datadir}/temp.log" | uniq > "${basedir}/${datadir}/podcast.log"
rm "${basedir}/${datadir}/temp.log"
# Create an m3u playlist:
ls "${basedir}/${datadir}" | grep -v m3u > "${basedir}/${datadir}/podcast.m3u"



whatcha think.[/quote]

like i said above... i could just kick myself :oops:

here's what i have that works so far as i know (i don't have a bp.conf file)
Code:
#!/bin/bash
# By Linc 10/1/2004
# Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder
# Last revision 07/01/2005 - Many Contributers!
# If you use this and have made improvements or have comments
# drop me an email at linc dot fessenden at gmail dot com
# I'd appreciate it!

# edited by jbsnake and coastie (had to tweak some things)

# Make script crontab friendly:
cd $(dirname $0)

# datadir is the directory you want podcasts saved to:
basedir="/home/${USER}/podcasts"
datadir="${basedir}/$(date +%Y-%m-%d)"

# Check for and create datadir if necessary:
if test ! -d "${basedir}"
        then
        mkdir "${basedir}"
fi

if test ! -d "${datadir}"
   then
   mkdir "${datadir}"
fi
# Delete any temp file:
rm -f "${datadir}/temp.log"

read -p "Please enter the url you want to add to the podcast list: " url
# Read the bp.conf file and wget any url not already in the podcast.log file:
while read podcast
   do
   file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' " | sed -n 's/.*url="\([^"]*\)".*/\1/p')
   for furl in "${file}"
      do
      if ! grep "${furl}" "${datadir}/podcast.log" > /dev/null
         then
         wget -q -P ${datadir} "${url}" && echo "${url}" >> "${datadir}/temp.log"
   fi
       done
   done < bp.conf
# Move dynamically created log file to permanent log file:
cat "${datadir}/podcast.log" >> "${datadir}/temp.log"
sort "${datadir}/temp.log" | uniq > "${datadir}/podcast.log"
rm "${datadir}/temp.log"
# Create an m3u playlist:
ls ${datadir} | grep -v m3u > "${datadir}/podcast.m3u"


Top
 Profile  
 PostPosted: Sat Aug 13, 2005 11:22 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
it looks good. i am not going to be adding the bp.conf file in the slax iso so that isn't necessary. do you think we could take that line out :?


Top
 Profile YIM  
 PostPosted: Sun Aug 14, 2005 12:21 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
done...
new code
Code:
#!/bin/bash
# By Linc 10/1/2004
# Find the latest script at http://linc.homeunix.org:8080/scripts/bashpodder
# Last revision 07/01/2005 - Many Contributers!
# If you use this and have made improvements or have comments
# drop me an email at linc dot fessenden at gmail dot com
# I'd appreciate it!

# edited by jbsnake and coastie (had to tweak some things)

# Make script crontab friendly:
cd $(dirname $0)

# datadir is the directory you want podcasts saved to:
basedir="/home/${USER}/podcasts"
datadir="${basedir}/$(date +%Y-%m-%d)"

# Check for and create datadir if necessary:
if test ! -d "${basedir}"
        then
        mkdir "${basedir}"
fi

if test ! -d "${datadir}"
   then
   mkdir "${datadir}"
fi
# Delete any temp file:
rm -f "${datadir}/temp.log"

read -p "Please enter the url you want to add to the podcast list: " url
# Read the bp.conf file and wget any url not already in the podcast.log file:
# while read podcast
#   do
#   file=$(wget -q $podcast -O - | xsltproc parse_enclosure.xsl - 2> /dev/null) || file=$(wget -q $podcast -O - | tr '\r' '\n' | tr \' \" | sed -n 's/.*url="\([^"]*\)".*/\1/p')
#  for furl in "${file}"
  #    do
   #   if ! grep "${furl}" "${datadir}/podcast.log" > /dev/null
    #     then
         wget -q -P ${datadir} "${url}" && echo "${url}" >> "${datadir}/temp.log"
   #fi
     #  done
   #done < bp.conf
# Move dynamically created log file to permanent log file:
cat "${datadir}/podcast.log" >> "${datadir}/temp.log"
sort "${datadir}/temp.log" | uniq > "${datadir}/podcast.log"
rm "${datadir}/temp.log"
# Create an m3u playlist:
ls ${datadir} | grep -v m3u > "${datadir}/podcast.m3u"


Top
 Profile  
 PostPosted: Sun Aug 14, 2005 12:27 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
sweet 8)

thanks for all the help jb


Top
 Profile YIM  
 PostPosted: Sun Aug 14, 2005 12:32 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
anytime... just don't forget to let me have a link to the iso :)


Top
 Profile  
 PostPosted: Sun Aug 14, 2005 7:33 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
i talked to crouse and he is gonna put it on the ftp for the lug
8)


Top
 Profile YIM  
 PostPosted: Sun Aug 14, 2005 7:35 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
awesome :)


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 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:  


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