get_youtube_videos/fix_dir_dates.sh

25 lines
1.2 KiB
Bash
Executable file

#!/bin/bash
while read -r dir
do
if [ -n "${dir}" ]; then
echo "Checking dir '${dir}'..."
last_file="$(find "${dir}/" -type f -printf "%T@ %p\n" | sort -n | grep \.webm\.download_info\.json | head -n1 | sed 's/^[0-9\.]* //')"
if [ "${last_file}" == "${dir}/" ] || [ -z "${last_file}" ]; then
last_file="$(find "${dir}/" -type f -printf "%T@ %p\n" | sort -n | head -n1 | sed 's/^[0-9\.]* //')"
fi
if [ "${last_file}" == "${dir}/" ] || [ -z "${last_file}" ]; then
echo "Skipping, no file found in dir"
else
echo "Last modified file is '${last_file}'"
filetime="$(jq '.info_dict.filetime' -- "${last_file}" )"
if [ "${filetime}" != "null" ] && [ -n "${filetime}" ]; then
last_file_time_formated=$(date -d "@${filetime}" +%Y%m%d%H%M.%S)
echo "Setting times for '${dir}' to '${last_file_time_formated}'..."
touch -t "${last_file_time_formated}" -- "${dir}"
else
echo "Setting times for '${dir}' to same as '${last_file}'..."
touch -r "${last_file}" -- "${dir}"
fi
fi
fi
done <<< "$(find . -mindepth 1 -maxdepth 1 -type d | grep -Ev '^\./\.')"