Skip to content

Instantly share code, notes, and snippets.

@tatesuke
Last active December 20, 2015 04:38
Show Gist options
  • Save tatesuke/6071820 to your computer and use it in GitHub Desktop.
Save tatesuke/6071820 to your computer and use it in GitHub Desktop.
Contour GPSで撮った動画ファイルを一括で日付.MOVに変更する。 Contour GPSで撮った動画ファイルは、FILE0001.MOVのようなファイル名で保存される。 個人的にファイル名を日付にしたいので、ContourStoryTellerでインポートした後に実行するとファイル名やStoryTellr関連ファイルを書き換える。 GPSの情報から日付を引っ張ってくるので.nmeaファイルが有る場合のみ有効。
import datetime
import os
import re
DIR_BASE = '/Volumes/share/contour/' # Contourライブラリのパス
def main():
oldNameList = getOldNameList()
for oldName in oldNameList :
try:
newName = getNewName(oldName)
print oldName + " to " + newName
renameMovieFile(oldName, newName)
renameTumbnailFile(oldName, newName)
renameNmeaFile(oldName, newName)
rewriteXMP(oldName, newName)
except Exception:
print 'fail : ' + oldName
def renameMovieFile(oldName, newName):
oldName2 = DIR_BASE + oldName + ".MOV"
newName2 = DIR_BASE + newName + ".MOV"
os.renames(oldName2, newName2)
def renameTumbnailFile(oldName, newName):
oldName2 = DIR_BASE + 'Storyteller-Data/Thumbnails/' + oldName + ".jpg"
newName2 = DIR_BASE + 'Storyteller-Data/Thumbnails/' + newName + ".jpg"
os.renames(oldName2, newName2)
def renameNmeaFile(oldName, newName):
oldName2 = DIR_BASE + 'Storyteller-Data/GPS/' + oldName + ".nmea"
newName2 = DIR_BASE + 'Storyteller-Data/GPS/' + newName + ".nmea"
os.renames(oldName2, newName2)
def rewriteXMP(oldName, newName):
oldFile = None
newFile = None
try:
oldFile = open(DIR_BASE + 'Storyteller-Data/XMP/' + oldName + '.xmp', 'r')
newFile = open(DIR_BASE + 'Storyteller-Data/XMP/' + newName + '.xmp', 'w')
for line in oldFile:
if line.find(oldName) != -1 :
line = re.sub(oldName, newName, line)
newFile.write(line)
finally:
oldFile.close()
newFile.close()
os.remove(DIR_BASE + 'Storyteller-Data/XMP/' + oldName + '.xmp')
def getOldNameList():
oldNameList = []
fileList = os.listdir(DIR_BASE + 'Storyteller-Data/GPS/')
for fileName in fileList:
if re.search('FILE.*\\.nmea', fileName) is not None:
oldNameList.append(fileName.replace('.nmea', ''))
return oldNameList
def getNewName(fileName):
firstLine = ''
openFile = None
try:
openFile = open(DIR_BASE + 'Storyteller-Data/GPS/' + fileName + '.nmea', 'r')
for line in openFile:
firstLine = line
break
term = firstLine.split(',')
rawTime = term[1].split('.')[0]
rawDate = term[9]
tempDate = rawDate + rawTime
date = datetime.datetime.strptime(tempDate, "%d%m%y%H%M%S")
date = date + datetime.timedelta(hours=9)
newName = date.strftime('%Y-%m-%d-%H%M%S')
return newName
finally:
openFile.close()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment