Skip to content

Instantly share code, notes, and snippets.

@monokano

monokano/aiver.py

Last active Oct 31, 2020
Embed
What would you like to do?
Illustratorファイル(ai, eps)の作成アプリバージョンと保存バージョンを検出する
#!/usr/bin/python
#
# Usage: python aiver.py illustrator-file(ai,eps)
#
# This script will detect the app version written in the illustrator file.
#
import sys, os, re
def getAppName(ver):
# get illustrator app name
fv = float(ver)
mv = int(fv)
if (mv>=1 and mv<=4) or (mv>=6 and mv<=10):
return str(mv)
elif mv==5:
if fv<5.5:
return '5'
else:
return '5.5'
elif mv==11:
return 'CS'
elif (mv>=12 and mv<=14) or mv==16:
return 'CS'+str(mv-10)
elif mv==15:
if fv<15.5:
return 'CS5'
else:
return "CS5.5"
elif mv==17:
return 'CC'
elif (mv>=18 and mv<=19) or (mv>=21 and mv<=23):
return 'CC '+str(mv+1996)
elif mv==20:
return 'CC 2015.3'
else:
return str(mv+1996)
def getVer(s):
createdVer = ''
savedVer = ''
# like strings
s = re.sub(r'[\x00-\x1F\x7F-\xFF]+', '', s)
# created version
cvList = s.split('AI8_CreatorVersion: ', 1)
if len(cvList)==2:
m = re.search(r'^[\d.]+', cvList[1])
createdVer = m.group()
# saved version
svList = s.split('%%Creator: Adobe Illustrator(R) ')
c = len(svList)
if c==2:
m = re.search(r'^[\d.]+', svList[1])
savedVer = m.group()
elif c>2:
m = re.search(r'^[\d.]+', svList[-1])
savedVer = m.group()
return [createdVer, savedVer]
if len(sys.argv) > 1 :
arg = sys.argv[1]
ex = os.path.splitext(arg)[1]
if ex in {'.ai', '.eps'}:
# read
f = open(arg, 'rb')
mb = 1048576 #1MB
rs = f.read(mb)
vers = getVer(rs)
if not vers[1]:
rs = f.read(mb*10) #10MB
vers = getVer(rs)
if not vers[1]:
rs = f.read(mb*50) #50MB
vers = getVer(rs)
if not vers[1]:
rs = f.read(mb*100) #100MB
vers = getVer(rs)
if not vers[1]:
rs = f.read(mb*300) #300MB
vers = getVer(rs)
if not vers[1]:
rs = f.read() #read all
vers = getVer(rs)
if vers[1]:
# adjust version info
cvList = vers[0].split('.')
del cvList[2:]
createdVer = '.'.join(cvList)
savedVer = vers[1]
# return value
print 'Created: ' + getAppName(createdVer) +'(v'+ vers[0] + '), Saved: ' + getAppName(savedVer) +'(v'+ savedVer + ')'
else :
print >> sys.stderr, 'Usage: python aiver.py illustrator-file(ai,eps)'
sys.exit()
else :
print >> sys.stderr, 'Usage: python aiver.py illustrator-file(ai,eps)'
sys.exit(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.