3 Useful Recipes
FilipBB edited this page 2016-11-17 18:53:30 -05:00

Adding entries to a playlist with a custom download handler

This custom download handler uses wget to download the enclosure and then add it to a playlist.

In greg.conf:

downloadhandler = greg-wget "{link}" "{fullpath}"

greg-wget:

#!/bin/bash 
LINK="$1"
FILENAME="$2"

#download the enclosure
/usr/bin/wget --no-verbose --show-progress "$LINK" -O "$FILENAME"

#add the downloaded file to a playlist
echo -e "$FILENAME" \\n >>~/podcasts-$(date +%F).m3u

Performing different actions based on file type

This custom download handler uses wget to download the enclosure and then convert the file to an mp3 audio file using an appropriate decoder/encoder.

In greg.conf:

downloadhandler = greg-wget "{link}" "{directory}" {date}-"{filename_title}"

greg-wget:

#!/bin/bash 
LINK="$1"
DIR="$2"
FILENAME="$3"
TMPFILE="~/enclosure.tmp"

#download the enclosure to a temporary location
/usr/bin/wget --no-verbose --show-progress "$LINK" -O $TMPFILE

#determine the mime type of the enclosure
TYPE=$(file --mime-type -b $TMPFILE |cut -d '/' -f 2)

#use "mediainfo" to determine the type if "file" fails
if [ "$TYPE" = "" ]; then
    TYPE=$(mediainfo --Output="Audio;%Format%" $TMPFILE)
fi

case $TYPE in
    *mp3*|*mpeg*)
        mv -vf "$TMPFILE" "$DIR"/"$FILENAME".mp3
        ;;
    *m4a*)
        faad -o - "$TMPFILE"| lame - "$DIR/$FILENAME".mp3
        ;;
    *mp4*)
        ffmpeg -i "$TMPFILE" -f mp3 -ab 192000 -vn "$DIR/$FILENAME".mp3
        ;;
    *)
        echo -e "\nNot a media file! Detected as: $TYPE\n"
        ;;
esac

#cleanup
rm -f $TMPFILE