wlvfs/scripts/video-upload-date.sh

28 lines
667 B
Bash

#!/usr/bin/env bash
secs="$(date +%s%N)"
file_prefix="/tmp/wlvfs$secs-"
fifo="/tmp/fifo-vup$secs"
mkfifo "$fifo"
youtube-dl -o "$file_prefix%(upload_date)s" -- "$1" 2>/dev/null > "$fifo" &
pid="$!"
while read -r line; do
file=$(echo "$line" | grep 'Destination:')
[ -n "$file" ] && {
file=$(echo "$file" | cut -d " " -f 3)
update=$(echo "$file" | sed -E "s|($file_prefix)(([0-9]+)\|(NA))(\..+)?|\2|")
if [ "$update" = "NA" ]; then
date +%Y%m%d
else
echo "$update"
fi
break
}
done < "$fifo"
kill "$pid"
rm "$fifo"
echo "$file" | grep -q "^$file_prefix" && rm "$file"* 2>/dev/null