#!/bin/bash

list="$@ "
_PID=

#echo -e "\n\n-- $(date "+%Y-%m-%d %H:%M:%S") ------------------------\n" >> ytdl.log

if [ -n "$list" ]
then
	youtube-dl $list #2>>ytdl.err >>ytdl.log &
	_PID=$(jobs -p)
fi

while true
do
	read -p "URL: " url
	kill $_PID || (sleep 2; kill -9 $_PID)
	if [ $url = "." ]
	then
		kill $_PID || (sleep 2; kill -9 $_PID)
		exit 0
	fi
	list="${list}${url} "
	#echo -e "\n\n-- $(date "+%Y-%m-%d %H:%M:%S") ------------------------\n" >> ytdl.log
	youtube-dl $list #2>>ytdl.err >>ytdl.log &
	_PID=$(jobs -p)
done


