#!/usr/bin/env bash POD_BASE_DIR=${POD_BASE_DIR:-~/Music/} POD_SUB_DIR=${POD_SUB_DIR:-Podcasts} POD_EXPORT_BRANCH=${POD_EXPORT_BRANCH:-master} POD_EXPORT_TARGET=${POD_EXPORT_TARGET:-sansa-cast} show_usage() { echo "$(basename $0) [ list | list-all | play [ FILE ] | pick [-x] | pause | stop | listened | update-feeds | wanted | export [ BRANCH [ TARGET ] ] ]" >&2 } show_help() { show_usage cat < /dev/null ; then git_annex_wrap metadata -s "seek_time=${SEEK}" "${FILE}" fi } if [ $# -lt 1 ] ; then show_usage exit 1 fi CMD=$1 shift case "$CMD" in help) show_help exit ;; list) if [ $# -lt 1 ] ; then find_unlistened --in=here else find_unlistened --in=here | grep $@ fi exit ;; list-all) if [ $# -lt 1 ] ; then find_unlistened else find_unlistened | grep $@ fi exit ;; play) pod stop mpc clear if [ $# -lt 1 ] ; then for item in $(find_unlistened --in=here) ; do mpc add $item done else play_pod $1 fi exit ;; pick) CHOSEN_POD='' if [ "$1" == "-x" ] ; then CHOSEN_POD=$(find_unlistened --in=here | cut -d'/' -f 2- | rofi -dmenu -p "podcast") else CHOSEN_POD=$(find_unlistened --in=here | cut -d'/' -f 2- | fzf) fi if [ "${#CHOSEN_POD}" -gt 0 ] ; then play_pod "${POD_SUB_DIR}/${CHOSEN_POD}" fi exit ;; pause) FILE=$(get_cur_file) SEEK=$(get_cur_seek) mpc pause set_loc $FILE $SEEK exit ;; stop) FILE=$(get_cur_file) SEEK=$(get_cur_seek) mpc stop set_loc $FILE $SEEK exit ;; listened) if [ $# -lt 1 ] ; then FILE=$(get_cur_file) git_annex_wrap metadata -s tag=listened "${FILE}" else if [ $1 = '-' ] ; then cat | while read FILE ; do git_annex_wrap metadata -s tag=listened "${FILE}" done else for FILE in $* ; do git_annex_wrap metadata -s tag=listened "${FILE}" done fi fi exit ;; update-feeds) CUR_DIR=$(pwd) cd $POD_BASE_DIR grep -v '^# ' ${POD_SUB_DIR}/podcasts-list.txt |\ while read -r LINE; do URL=${LINE##* } TITLE=${LINE% *} echo "Downloading ${TITLE}..." git annex importfeed \ --template="${POD_SUB_DIR}/\${feedtitle}/\${itempubdate}-\${itemtitle}\${extension}" \ "${URL}" echo done git annex add ${POD_SUB_DIR} git commit -m "Caught podcasts" git annex find --include="${POD_SUB_DIR}/*" --and --not --metadata tag=listened |\ xargs git annex metadata --tag unlistened mpc update cd $CUR_DIR exit ;; wanted) find_unlistened --not --in=here exit ;; export) grep -v '^# ' ${POD_BASE_DIR}/${POD_SUB_DIR}/export-devices.csv | \ while read -r LINE; do REMOTE=$(echo "${LINE}" | cut -f 1) DIRECTORY=$(echo "${LINE}" | cut -f 2) BRANCH=$(echo "${LINE}" | cut -f 3) if [ -d "${DIRECTORY}" ] ; then git_annex_wrap export "${BRANCH}" --to "${REMOTE}" fi done exit ;; *) show_usage echo echo "Subcommand $CMD is not valid." >&2 exit 1 ;; esac