get_youtube_videos/fix_dir_dates.sh

21 lines
832 B
Bash
Executable file

#!/bin/bash
while read -r dir
do
echo "Checking dir '${dir}'..."
last_file="${dir}/$(ls -ht -- "${dir}/" | grep \.webm\.download_info\.json | head -n1)"
if [ "${last_file}" == "${dir}/" ]; then
last_file="${dir}/$(ls -ht -- "${dir}/" | head -n1)"
fi
if [ "${last_file}" == "${dir}/" ]; 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)
touch -t "${last_file_time_formated}" -- "${dir}"
else
touch -r "${last_file}" -- "${dir}"
fi
fi
done <<< "$(find . -mindepth 1 -maxdepth 1 -type d)"