Skip to content

Instantly share code, notes, and snippets.

@jojonki
Created October 27, 2019 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jojonki/f58d52d64bd20eb538dc689a67c20bb3 to your computer and use it in GitHub Desktop.
Save jojonki/f58d52d64bd20eb538dc689a67c20bb3 to your computer and use it in GitHub Desktop.
Timeshift modification for Sony's actioncam on Mac
from datetime import datetime
from pytz import timezone
import subprocess
import glob
import xml.etree.ElementTree as ET
# replaced time zones
SRC_TZ_ZONES = ['UTC+09:00', 'UTC+01:00']
# target time zone
TGT_TZ_ZONE = ['Europe/Berlin']
def main():
xml_files = glob.glob('./*.XML')
for x in xml_files:
print(x)
tree = ET.parse(x)
root = tree.getroot()
for child in root:
if child.tag.endswith('CreationDate'): # <CreationDate value="2019-10-09T11:15:16+09:00"/>
v = child.attrib['value']
d = datetime.fromisoformat(v)
tz_name = d.tzname()
print('tzname:', tz_name)
if tz_name in SRC_TZ_ZONES:
print('org:', d)
d = d.astimezone(timezone('Europe/Berlin'))
print('rpl:', d)
nd = '{}/{}/{} {}:{}:{}'.format(d.month, d.day, d.year, d.hour, d.minute, d.second)
cmd = ['setfile', '-d', '"{}"'.format(nd), '{}'.format(x.replace('XML', 'MP4').replace('M01', ''))]
print(cmd)
subprocess.run(cmd)
else:
print('Skip', d)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment