Advertisement
Guest User

gpodder-sync

a guest
Mar 27th, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.22 KB | None | 0 0
  1. #!/bin/bash
  2. #: Title: gPodder Syncronization
  3. #: Author: Neal T. Bailey <nealbailey@hotmail.com>
  4. #: Date: 01/10/2012
  5. #:       07/11/2012
  6. #: Version: 1.1
  7. #: Requires: gpodder, ffmpeg, lame
  8. #: Purpose: Downloads video podcasts, rips the audio from them,
  9. #:      and copies them to a path that syncs with my ipod.
  10. #
  11. #: Usage: ./gpodder-sync.sh
  12. #:
  13. # gPodder CLI Reference: http://wiki.gpodder.org/wiki/User_Manual#Command-line_interface
  14. #
  15. # Workflow
  16. #   1. Parse overrides file
  17. #   2. Update podcasts
  18. #   3. Download new podcast episodes
  19. #   4. Ignore all previously downloaded podcasts
  20. #   5. Copy the podcasts that are not in the history file
  21. #   6. Rip audio out of video files
  22.  
  23. # Log
  24. log="/tmp/$(date +%Y-%m-%dT%H:%M)-podcast-download.log"
  25.  
  26. # Podcast definitions (podcast RSS urls, 1 per line)
  27. defs="$HOME/Downloads/Podcasts/auto-download.conf"
  28.  
  29. # gPodder download directory (where gpodder is configured to download)
  30. podDownload="$HOME/Downloads/Podcasts/gpodder-downloads"
  31.  
  32. # publish directory (the directory to copy converted podcasts to)
  33. pubDir="$HOME/Downloads/Podcasts/_converted"
  34.  
  35. # history file (The file to save download/convert history)
  36. histFile="$HOME/Downloads/Podcasts/_converted/_history.txt"
  37.  
  38.  
  39. # Check dependencies
  40. # Validate gpodder-cli is installed
  41. if [ $(which gpo | grep -c "gpo") -eq 0 ]; then
  42.     echo "error: gpodder-cli is not installed!" | tee -a "$log"
  43.     exit 1
  44. fi
  45.  
  46. # Validate ffmpeg is installed
  47. if [ $(which ffmpeg | grep -c "ffmpeg") -eq 0 ]; then
  48.     echo "error: ffmpeg is not installed!" | tee -a "$log"
  49.     exit 1
  50. fi
  51.  
  52. # Check definitions file
  53. if [ ! -e "$defs" ]; then
  54.     echo "error: couldn't find podcast definitions file: $defs!" | tee -a "$log"
  55. #   exit 1
  56. fi
  57.  
  58. # Check download path
  59. if [ ! -e "$podDownload" ]; then
  60.     mkdir -p "$podDownload"
  61. fi
  62.  
  63. # Check publish path
  64. if [ ! -e "$pubDir" ]; then
  65.     mkdir -p "$pubDir"
  66. fi
  67.  
  68. # Temp IFS
  69. tIFS="$IFS"
  70.  
  71. # Share definitions
  72. #  -check for override file
  73. if [ -e "$defs" ]; then
  74.   # use these urls
  75.   arrUris=( ` cat "$defs" ` )
  76. else
  77.   arrUris=( "$@" )
  78. fi
  79.  
  80. for itm in "${arrUris[@]}"
  81.  do
  82.     # update & download podcasts
  83.     echo "Updating & downloading podcast: $itm" | tee -a "$log"
  84.     gpo update "$itm" && gpo download "$itm"
  85.  done
  86.  
  87. IFS=';'
  88. arrpods=( $(find "$podDownload" \( -name "*.mp3" -or -name "*.mp4" \) -printf %p\;) )
  89.  
  90. for pod in "${arrpods[@]}"
  91.  do
  92.     fileName=$(basename "$pod")
  93.     if [ $(cat "$histFile" | grep -ce "$fileName") -ne "0" ]; then
  94.         echo "Skip existing: $fileName" | tee -a "$log"
  95.     else       
  96.         if [ $(echo "$fileName" | grep -ic ".mp4") -gt "0" ]; then
  97.             echo "$fileName" >> "$histFile"
  98.             noextName=$(echo "$fileName" | sed 's/.mp4//g')
  99.             fileName="$noextName.mp3"
  100.             ffmpeg -i "$pod" -vn -ac 2 -ab 192k "$pubDir/$fileName"
  101.             pod=$(echo "$pod" | sed 's/.mp4/.mp3/g')
  102.         fi
  103.    
  104.         cp "$pod" "$pubDir"
  105.         echo "Copying: $fileName -> $pubDir" | tee -a "$log"
  106.         echo "$fileName" >> "$histFile"    
  107.         echo "Copying new podcast: $fileName"
  108.     fi
  109.  done
  110.  
  111. # sort history file
  112. sort -o "$histFile" "$histFile"
  113.  
  114. # Apply global ownership to downloads (allow all users to delete)
  115. echo "Setting full control permissions to downloads." | tee -a "$log"
  116. chmod -R 777 "$podDownload" && chmod -R 777 "$pubDir"
  117.  
  118. echo "Tasks complete." | tee -a "$log"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement