Skip to content

Instantly share code, notes, and snippets.

@yoosefi
Last active December 27, 2017 00:32
Show Gist options
  • Save yoosefi/3d5841e0c2b71edf02eec0730249128f to your computer and use it in GitHub Desktop.
Save yoosefi/3d5841e0c2b71edf02eec0730249128f to your computer and use it in GitHub Desktop.
sets video file mtime to its encode date
#!/bin/bash
# sets video file mtime to its encode date
# requires mediainfo
# see also the inverse of this script: "encode-date-from-mtime.sh"
# https://gist.github.com/yoosefi/66d9a58466fb9e8bf5a8467fc11f470e
set -eu
for each in "$@"; do
x=($(mediainfo "${each}" | grep -m1 'Encoded date'))
# skip null dates
if [ -z "${x}" ]; then
echo no date for \""${each}"\" >&2
continue
fi
# skip bogus dates
if ! [[ "${x[4]}" =~ ^(199)|(20).* ]]; then
echo bad date for \""${each}"\" >&2
continue
fi
touch --date="${x[*]:3}" "${each}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment