#!/usr/bin/env bash

while read line; do
    me=$(echo $line)
    if [[ "$me" =~ ^Podcast\ Download.+ ]]; then

      url=$(echo "$me" | cut -d ' ' -f 4)
      type=$(echo "$me" | cut -d ' ' -f 6)

      echo "$type : $(date) => $url" >> /home/karmst/.config/newsboat/podcasts.txt

      if [[ "$type" =~ ^video ]]; then
        dunstify "Playing Video : $url"
        mpv -fs --really-quiet --no-terminal $url
      else
        dunstify "Playing Audio : $url"
        mpc add $url
        mpc play
      fi

    fi
done