Created
October 27, 2019 03:00
-
-
Save jojonki/f58d52d64bd20eb538dc689a67c20bb3 to your computer and use it in GitHub Desktop.
Timeshift modification for Sony's actioncam on Mac
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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