Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #: Title: gPodder Syncronization
- #: Author: Neal T. Bailey <[email protected]>
- #: Date: 01/10/2012
- #: 07/11/2012
- #: Version: 1.1
- #: Requires: gpodder, ffmpeg, lame
- #: Purpose: Downloads video podcasts, rips the audio from them,
- #: and copies them to a path that syncs with my ipod.
- #
- #: Usage: ./gpodder-sync.sh
- #:
- # gPodder CLI Reference: http://wiki.gpodder.org/wiki/User_Manual#Command-line_interface
- #
- # Workflow
- # 1. Parse overrides file
- # 2. Update podcasts
- # 3. Download new podcast episodes
- # 4. Ignore all previously downloaded podcasts
- # 5. Copy the podcasts that are not in the history file
- # 6. Rip audio out of video files
- # Log
- log="/tmp/$(date +%Y-%m-%dT%H:%M)-podcast-download.log"
- # Podcast definitions (podcast RSS urls, 1 per line)
- defs="$HOME/Downloads/Podcasts/auto-download.conf"
- # gPodder download directory (where gpodder is configured to download)
- podDownload="$HOME/Downloads/Podcasts/gpodder-downloads"
- # publish directory (the directory to copy converted podcasts to)
- pubDir="$HOME/Downloads/Podcasts/_converted"
- # history file (The file to save download/convert history)
- histFile="$HOME/Downloads/Podcasts/_converted/_history.txt"
- # Check dependencies
- # Validate gpodder-cli is installed
- if [ $(which gpo | grep -c "gpo") -eq 0 ]; then
- echo "error: gpodder-cli is not installed!" | tee -a "$log"
- exit 1
- fi
- # Validate ffmpeg is installed
- if [ $(which ffmpeg | grep -c "ffmpeg") -eq 0 ]; then
- echo "error: ffmpeg is not installed!" | tee -a "$log"
- exit 1
- fi
- # Check definitions file
- if [ ! -e "$defs" ]; then
- echo "error: couldn't find podcast definitions file: $defs!" | tee -a "$log"
- # exit 1
- fi
- # Check download path
- if [ ! -e "$podDownload" ]; then
- mkdir -p "$podDownload"
- fi
- # Check publish path
- if [ ! -e "$pubDir" ]; then
- mkdir -p "$pubDir"
- fi
- # Temp IFS
- tIFS="$IFS"
- # Share definitions
- # -check for override file
- if [ -e "$defs" ]; then
- # use these urls
- arrUris=( ` cat "$defs" ` )
- else
- arrUris=( "$@" )
- fi
- for itm in "${arrUris[@]}"
- do
- # update & download podcasts
- echo "Updating & downloading podcast: $itm" | tee -a "$log"
- gpo update "$itm" && gpo download "$itm"
- done
- IFS=';'
- arrpods=( $(find "$podDownload" \( -name "*.mp3" -or -name "*.mp4" \) -printf %p\;) )
- for pod in "${arrpods[@]}"
- do
- fileName=$(basename "$pod")
- if [ $(cat "$histFile" | grep -ce "$fileName") -ne "0" ]; then
- echo "Skip existing: $fileName" | tee -a "$log"
- else
- if [ $(echo "$fileName" | grep -ic ".mp4") -gt "0" ]; then
- echo "$fileName" >> "$histFile"
- noextName=$(echo "$fileName" | sed 's/.mp4//g')
- fileName="$noextName.mp3"
- ffmpeg -i "$pod" -vn -ac 2 -ab 192k "$pubDir/$fileName"
- pod=$(echo "$pod" | sed 's/.mp4/.mp3/g')
- fi
- cp "$pod" "$pubDir"
- echo "Copying: $fileName -> $pubDir" | tee -a "$log"
- echo "$fileName" >> "$histFile"
- echo "Copying new podcast: $fileName"
- fi
- done
- # sort history file
- sort -o "$histFile" "$histFile"
- # Apply global ownership to downloads (allow all users to delete)
- echo "Setting full control permissions to downloads." | tee -a "$log"
- chmod -R 777 "$podDownload" && chmod -R 777 "$pubDir"
- echo "Tasks complete." | tee -a "$log"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement