#!/bin/bash
#####################################################
# PMRP                                              #
# Poor man's radio stream recorder                  #
# ==================================================#
# Internet radio streamer to listen to online radio #
# ==================================================#
# © 2023 WTFPL lxgator @ gmail.com                  # 
# ###################################################
NAME='PMRP Record'
RICON='/usr/share/icons/hicolor/48x48/apps/pmrp-record.png'
CONF="$HOME/.pmrp"
SR="streamripper"

A1=`cat $CONF/url | awk 'NR==1 {print}'`

if ! test -d $HOME/Music/"PMRP"; then
mkdir -p $HOME/Music/"PMRP"
fi
ENTRY=$(yad --width=450 --height=125 --window-icon=$RICON --image=$RICON --fixed --center \
        --form --title="PMRP Record" \
        --field="Save in:DIR" $HOME/Music/"PMRP" \
--text='\nSave Recording Stream' \
--button="Cancel"!/usr/share/pmrp/icons/cancel.svg:1 \
--button="Ok"!/usr/share/pmrp/icons/ok.svg:0)
ret=$?
[[ $ret -eq 1 ]] &&
PID=`ps -eaf | grep record | grep -v grep | awk '{print $2}'`
kill -9 $PID > /dev/null 2>&1 &
if [[ $ret -eq 0 ]]; then 
RET=$?
    OIFS=$IFS 
    IFS="|" 
    i=0
    retChoice=()

    for ret in $ENTRY;do 
        retChoice[$i]="$ret"
        i=$(($i+1))
    done

    IFS=$OIFS 
    SAVEDIR=${retChoice[0]} # directory path
$SR $A1 2>&1 -m 30 -u 0 -s -d "$SAVEDIR" --xs_offset=-2000 | \
"/usr/share/pmrp/notify/Record"
fi 






