Last active
July 19, 2024 07:23
-
-
Save monokano/511789a092c09abb3fb938630fd547b4 to your computer and use it in GitHub Desktop.
Illustratorファイル(ai, eps)の作成アプリバージョンを検出するPython3スクリプト
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
#!/usr/bin/env python3 | |
import sys | |
import time | |
import argparse | |
import glob | |
__version__ = "2.0.1" | |
def getAppName(ver): | |
try: | |
versions = ver.split('.') | |
major_version = int(versions[0]) | |
major_minor_version = float(f"{versions[0]}.{versions[1]}") | |
if (1 <= major_version <= 4) or (6 <= major_version <= 10): | |
return str(major_version) | |
elif major_version == 5: | |
return '5' if major_minor_version < 5.5 else '5.5' | |
elif major_version == 11: | |
return 'CS' | |
elif (12 <= major_version <= 14) or major_version == 16: | |
return f'CS{major_version - 10}' | |
elif major_version == 15: | |
return 'CS5' if major_minor_version < 15.5 else 'CS5.5' | |
elif major_version == 17: | |
return 'CC' | |
elif (18 <= major_version <= 19) or (21 <= major_version <= 23): | |
return f'CC {major_version + 1996}' | |
elif major_version == 20: | |
return 'CC 2015.3' | |
else: | |
return str(major_version + 1996) | |
except (ValueError, IndexError): | |
return f"Unknown version: {ver}" | |
def process_file(file_path, timeout=None): | |
start_time = time.time() | |
if not file_path.lower().endswith(('.ai', '.eps')): | |
return f"Error: File {file_path} is not an .ai or .eps file." | |
try: | |
with open(file_path, 'r', errors='ignore') as file: | |
for line in file: | |
if timeout is not None and time.time() - start_time > timeout: | |
return f"Timeout of {timeout} seconds reached for {file_path}." | |
if line.startswith("%%AI8_CreatorVersion:"): | |
version = line.strip().split("%%AI8_CreatorVersion:", 1)[1].strip() | |
app_name = getAppName(version) | |
return f"{file_path}: {app_name} ({version})" | |
return f"Error: Adobe Illustrator version information not found in {file_path}." | |
except IOError as e: | |
return f"Error reading file {file_path}: {e}" | |
def process_files(file_paths, timeout=None): | |
results = [] | |
for file_path in file_paths: | |
result = process_file(file_path, timeout) | |
results.append(result) | |
return results | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser( | |
description=f"aiver3 v{__version__}\n" | |
"Detect Adobe Illustrator creator version from AI or EPS files.", | |
epilog="Note:\n" | |
"This script detects only the creator version of Illustrator files,\n" | |
"not the compatible version.\n\n" | |
"Example:\n" | |
" python3 aiver3.py example.ai\n" | |
" python3 aiver3.py -t 5 *.eps\n" | |
" python3 aiver3.py file1.ai file2.ai file3.eps", | |
formatter_class=argparse.RawTextHelpFormatter | |
) | |
parser.add_argument("file_paths", nargs='+', help="Path(s) to the AI or EPS file(s). Wildcards are supported.") | |
parser.add_argument("-t", "--timeout", type=float, metavar="SECONDS", | |
help="Timeout in seconds for each file (optional). If not specified, the script will run until completion.") | |
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}") | |
args = parser.parse_args() | |
# Expand wildcards in file paths | |
expanded_file_paths = [] | |
for path in args.file_paths: | |
expanded_file_paths.extend(glob.glob(path)) | |
results = process_files(expanded_file_paths, args.timeout) | |
for result in results: | |
print(result) |
アップデートしました。主な変更点は下記の通り。
- バージョン検出処理を刷新した
- 作成バージョンのみ検出するようにした。互換バージョン検出は非対応に
- 結果を「フルパス: アプリケーション名 (バージョン番号)」の形式で出力するようにした
- -h で詳細な説明を出力するようにした
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pytoh2用→ aiver.py