get_youtube_videos/fix_dir_dates.sh

24 lines
988 B
Bash
Raw Normal View History

2024-11-20 10:22:26 +01:00
#!/bin/bash
while read -r dir
do
2024-11-20 10:24:39 +01:00
echo "Checking dir '${dir}'..."
2024-11-20 11:45:46 +01:00
last_file="${dir}/$(ls -ht -- "${dir}/" | grep \.webm\.download_info\.json | head -n1)"
2024-11-20 11:51:53 +01:00
if [ "${last_file}" == "${dir}/" ]; then
2024-11-20 11:47:30 +01:00
last_file="${dir}/$(ls -ht -- "${dir}/" | head -n1)"
fi
2024-11-20 11:51:53 +01:00
if [ "${last_file}" == "${dir}/" ]; then
echo "Skipping, no file found in dir"
else
2024-11-20 11:47:30 +01:00
echo "Last modified file is '${last_file}'"
filetime="$(jq '.info_dict.filetime' -- "${last_file}" )"
2024-11-20 11:48:11 +01:00
if [ "${filetime}" != "null" ] && [ -n "${filetime}" ]; then
2024-11-20 11:47:30 +01:00
last_file_time_formated=$(date -d "@${filetime}" +%Y%m%d%H%M.%S)
2024-11-20 11:53:00 +01:00
echo "Setting times for '${dir}' to '${last_file_time_formated}'..."
2024-11-20 11:47:30 +01:00
touch -t "${last_file_time_formated}" -- "${dir}"
else
2024-11-20 11:53:00 +01:00
echo "Setting times for '${dir}' to same as '${last_file}'..."
2024-11-20 11:47:30 +01:00
touch -r "${last_file}" -- "${dir}"
fi
2024-11-20 11:45:46 +01:00
fi
2024-11-20 10:22:26 +01:00
done <<< "$(find . -mindepth 1 -maxdepth 1 -type d)"