forked from echeno/adobe-font-extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.py
146 lines (106 loc) · 3.83 KB
/
extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import sys
import os
import argparse
import shutil
from os.path import join as pjoin
from xml.etree import ElementTree
from collections import namedtuple
from pprint import pprint
from distutils.dir_util import mkpath
class AdobeCCFontExtractor:
pass
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
# global configuration object
class Config:
path_prefix = ''
filename_prefix = ''
filename_suffix = ''
font_dir = ''
manifest = ''
install_path = ''
target_path = ''
# font data object
FontData = namedtuple('FontData', 'id name weight')
def get_font_metadata(manifest_path):
tree = ElementTree.parse(manifest_path)
# find the <fonts> element containing the list of fonts
fonts_subtree = tree.getroot().find('fonts')
fonts = []
for font_elem in fonts_subtree.findall('font'):
props = font_elem.find('properties')
f_id = font_elem.find('id').text
f_name = props.find('familyName').text
f_weight = props.find('variationName').text
font = FontData(id=f_id, name=f_name, weight=f_weight)
fonts.append(font)
return fonts
# install the fonts on the system per the --install flag
def install_fonts(fonts):
pass
# extract the fonts to location
# folder structure:
# location/
# Font1/
# Font1 - Variation1.otf
# Font1 - Variation2.otf
def extract_fonts(fonts, config):
font_dir = config.font_dir
location = config.target_path
filename_prefix = config.filename_prefix
filename_suffix = config.filename_suffix
# make dirs to location if they don't exist
mkpath(location)
for font in fonts:
src = pjoin(font_dir, filename_prefix + str(font.id))
# src = pjoin(font_dir, '.' + str(font.id) + '.otf')
filename = font.name + ' - ' + font.weight + '.otf'
dest = pjoin(location, filename)
shutil.copy(src, dest)
def sync_all_fonts():
''' Go to the Adobe CC website and sync EVERY font '''
pass
def platform_setup():
'''Set up paths for MacOS or Windows'''
c = Config()
if sys.platform == 'win32': # Windows
c.path_prefix = os.path.expandvars(r'%APPDATA%\Adobe\CoreSync\plugins\livetype')
c.font_dir = pjoin(c.path_prefix, 'r')
c.manifest = pjoin(c.path_prefix, r'c\entitlements.xml')
c.target_path = os.path.expandvars(r'%USERPROFILE%\Downloads\extracted-fonts')
else: # MacOS
c.path_prefix = os.path.expandvars(r'$HOME/Library/Application Support/Adobe/CoreSync/plugins/livetype')
c.filename_prefix = '.'
c.filename_suffix = '.otf'
c.font_dir = os.path.join(c.path_prefix, '.r')
c.manifest = os.path.join(c.path_prefix, '.c/entitlements.xml')
c.target_path = os.path.expandvars(r'$HOME/Downloads/extracted-fonts')
return c
def main():
config = platform_setup()
# parse the command line arguments
parser = argparse.ArgumentParser(description='Extract Adobe CC Typekit fonts. '
'Adobe CC Font Sync syncs your fonts from Typekit, however '
'These fonts are not available')
# parser.add_argument('--install', type=
parser.add_argument('-l', '--list', help='show which fonts are synced')
parser.parse_args()
try:
font_data = get_font_metadata(config.manifest)
pprint(font_data)
extract_fonts(font_data, config)
except IOError as e:
print("Error: The font manifest could not be found. Make sure Adobe Creative Cloud is running.", e)
def test():
config = platform_setup()
config.target_path = 'TEST'
fonts = get_font_metadata(config.manifest)
extract_fonts(fonts, config)
if __name__ == '__main__':
main()