a pastebin project

Paste Description for Something

Just a little bash podcatcher I'm working on. Wordpress.com didn't like some of the code, so I'm putting it here.

Something

  1. #!/bin/sh
  2. # Created by Lehman Black - http://dosnlinux.wordpress.com
  3.  
  4. # podthingy - the podcatching thingy
  5. # name suggestions welcome ;)
  6.  
  7. CWD=`pwd`
  8.  
  9. # TODO: make an "unlistened" folder
  10. # TODO: integrate into SVN repo
  11.  
  12. # podcasts should be stored in separate folders under $PODCAST_ROOT
  13. # each podcast directory should have a *.list and *.info file
  14.  
  15. # sample info file
  16. #PODCAST="The Java Posse"
  17. #TOPIC="Java news"
  18. #HOMEPAGE="http://javaposse.com"
  19. #FEED="http://feeds.feedburner.com/javaposse"
  20. #LICENSE="Creative Commons"
  21. #ALBUM="The Java Posse"
  22. #ARTIST="Tor Norbye, Carl Quinn, Joe Nuxoll, Dick Wall"
  23. #GENRE="Podcast"
  24. # end info file
  25.  
  26. PODCAST_ROOT=$HOME
  27.  
  28. # make sure it works on folders only
  29. for PODCAST in $PODCAST_ROOT/*/
  30. do
  31.         if ! [ -f $PODCAST/*.info ]
  32.         then
  33.                 # skip if this is not a podcast directory
  34.                 continue
  35.         fi
  36.  
  37.         INFO_FILE=$PODCAST/*.info
  38.         LIST_FILE=$PODCAST/*.list
  39.  
  40.         PODNAME=`grep PODCAST $INFO_FILE | cut -d \" -f2`
  41.  
  42.         echo "Podcast: $PODNAME"
  43.         echo
  44.  
  45.         # preserve origional *.list until everything's finished downloading
  46.         TMP=`mktemp -t podcast.XXXXXX`
  47.         cat $LIST_FILE > $TMP
  48.  
  49.         echo -e "\tScanning feed for new episodes..."
  50.         echo
  51.  
  52.         FEED=`grep FEED $INFO_FILE | cut -d \" -f2`
  53.         FEED_ITEMS=`wget -q -O - $FEED | \
  54.                                 awk -F '<' '/url=/{print $NF}' | \
  55.                                 grep 'url=' | \
  56.                                 sed -e 's/.*url=\"//' \
  57.                                         -e 's/\".*//'`
  58.         NEW_ITEMS=""
  59.        
  60.         for NEW in $FEED_ITEMS
  61.         do
  62.                 if ! ( grep -q $NEW $LIST_FILE )
  63.                 then
  64.                         echo -e "\tNEW: $NEW"
  65.                         NEW_ITEMS="$NEW_ITEMS $NEW"
  66.                 fi
  67.         done
  68.  
  69.         # TODO count number of new episodes
  70.  
  71.         # skip if there are no podcasts to download
  72.         if [ -z `echo $NEW_ITEMS | tr -d '[:space:]'` ]
  73.         then
  74.                 echo "Podcast up to date"
  75.                 echo
  76.  
  77.                 rm $TMP
  78.  
  79.                 continue
  80.         fi
  81.  
  82.         echo
  83.  
  84.         # download the new episodes
  85.         for EPISODE in $NEW_ITEMS
  86.         do
  87.                 echo -ne "\tDownloading $EPISODE... "
  88.  
  89.                 wget --random-wait -q -c $EPISODE -P $PODCAST
  90.                 echo $EPISODE >> $TMP
  91.  
  92.                 echo "Done."
  93.         done
  94.  
  95.         # put the most recent podcast at the beginning -- hopefully
  96.         echo -e "\tUpdating list file"
  97.         sort -r $TMP > $LIST_FILE
  98.  
  99.         rm $TMP
  100.  
  101.         echo
  102.         echo "Podcast up to date"
  103.         echo
  104. done

advertising

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords.

fantasy-obligation