-
Notifications
You must be signed in to change notification settings - Fork 0
/
descendants.py
255 lines (204 loc) · 9.51 KB
/
descendants.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
from gedcom.element.individual import IndividualElement
from gedcom.element.family import FamilyElement
from gedcom.parser import Parser
from moviepy.editor import *
import speech
from pathlib import Path
import logging
import gedcom.tags
import video
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S',
handlers=[
logging.FileHandler("debug.log"),
logging.StreamHandler()
])
file_path = 'C:\\Users\\laverty\\Documents\\gedcom-video-laverty\\laverty.ged'
family_list = []
gedcom_parser = Parser()
gedcom_parser.parse_file(file_path)
root_child_elements = gedcom_parser.get_root_child_elements()
def get_individual_from_id(id):
for element in root_child_elements:
if isinstance(element, IndividualElement):
if element.get_pointer() == id:
return element
def get_family_from_id(id):
for element in root_child_elements:
if isinstance(element, FamilyElement):
if element.get_pointer() == id:
return element
def get_family_from_individual(individual):
return gedcom_parser.get_families(individual)
def get_children(individual):
"""Return elements corresponding to parents of an individual
Optional parent_type. Default "ALL" returns all parents. "NAT" can be
used to specify only natural (genetic) parents.
:type individual: IndividualElement
:type parent_type: str
:rtype: list of IndividualElement
"""
children = []
families = gedcom_parser.get_families(individual, gedcom.tags.GEDCOM_TAG_FAMILY_SPOUSE)
for family in families:
children += gedcom_parser.get_family_members(family, gedcom.tags.GEDCOM_TAG_CHILD)
# for family_member in family_members:
# logging.info(family_member.get_tag())
return children
def get_descendants( individual):
"""Return elements corresponding to ancestors of an individual
Optional `ancestor_type`. Default "ALL" returns all ancestors, "NAT" can be
used to specify only natural (genetic) ancestors.
:type individual: IndividualElement
:type ancestor_type: str
:rtype: list of Element
"""
children = get_children(individual)
descendants = []
descendants.extend(children)
for child in children:
descendants.extend(get_descendants(child))
#logging.info(descendants)
return descendants
def get_descendant_families(family):
family_list = []
family_list.append(family)
# father = gedcom_parser.get_family_members(family, gedcom.tags.GEDCOM_TAG_HUSBAND)
# mother = gedcom_parser.get_family_members(family, gedcom.tags.GEDCOM_TAG_WIFE)
children = gedcom_parser.get_family_members(family, gedcom.tags.GEDCOM_TAG_CHILD)
# if father:
# logging.info("father : " + " ".join(father[0].get_name()) )
# if mother:
# logging.info("mother : " + " ".join(mother[0].get_name()) )
for child in children:
#logging.info("child : " + " ".join(child.get_name()) )
family_spouse = gedcom_parser.get_families(child, gedcom.tags.GEDCOM_TAG_FAMILY_SPOUSE)
# if family_spouse:
# logging.info("Skipping Clip")
# else:
# logging.info("Create Clip")
for f in family_spouse:
family_list.extend(get_descendant_families(f))
return family_list
def get_individual_gallery_files(element):
files = []
element_children = element.get_child_elements()
for element in element_children:
if element.get_tag() == "OBJE":
for e in root_child_elements:
if e.get_pointer() == element.get_value():
for f in e.get_child_elements():
if f.get_tag() == "FILE":
for t in f.get_child_elements():
t_val = ""
if t.get_tag() == "TITL":
t_val = t.get_value()
for c in t.get_child_elements():
if c.get_tag() == "CONC":
t_val += c.get_value()
files.append({'path':f.get_value(),'description':t_val})
return files
def get_individual_clips(individual):
individual_clips = []
individual_gallery_files = get_individual_gallery_files(individual)
individual_profile_photo = None
individual_fullname = " ".join(individual.get_name())
individual_shortname = individual_fullname.split(" ")[0]
if individual_gallery_files:
individual_profile_photo = individual_gallery_files[0]['path']
individual_default_text = f"{individual_fullname}\n "
individual_birth_year = individual.get_birth_year()
if individual_birth_year != -1:
individual_default_text += f"was born in {individual_birth_year}\n "
individual_default_clip = video.get_clip(f"{individual.get_pointer()}_default", individual_default_text, image=individual_profile_photo)
individual_clips.append(individual_default_clip)
return individual_clips
def get_family_clips(family):
logging.info("------------------------")
#logging.info(family)
family_clips = []
father = gedcom_parser.get_family_members(family, gedcom.tags.GEDCOM_TAG_HUSBAND)
mother = gedcom_parser.get_family_members(family, gedcom.tags.GEDCOM_TAG_WIFE)
children = gedcom_parser.get_family_members(family, gedcom.tags.GEDCOM_TAG_CHILD)
father_fullname = " ".join(father[0].get_name())
mother_fullname = " ".join(mother[0].get_name())
father_shortname = father_fullname.split(" ")[0]
mother_shortname = mother_fullname.split(" ")[0]
family_intro_text = f"{father_fullname}\n and \n{mother_fullname}"
logging.info(family_intro_text)
family_intro = video.get_family_intro_clip("family_intro", family_intro_text, image=None)
family_clips.append(family_intro)
father_clip = get_individual_clips(father[0])
family_clips.extend(father_clip)
mother_clip = get_individual_clips(mother[0])
family_clips.extend(mother_clip)
number_of_children = len(children)
if number_of_children > 0:
child_word = "children"
if number_of_children == 1:
child_word = "child"
children_text = f"Together they had {number_of_children} {child_word}.\n"
if len(children) == 2:
for child in children:
children_text += child.get_name()[0].split(" ")[0] + " and "
if children_text[-5:] == " and ":
children_text = children_text[:-5]
else:
for child in children:
children_text += child.get_name()[0].split(" ")[0] + ", "
children_text = children_text.rstrip(', ')
children_text = children_text + "."
family_photos = get_individual_gallery_files(family)
family_photo = None
if family_photos:
family_photo = family_photos[0]['path']
children_clip = video.get_clip(f"{father_fullname}_children", children_text, image=family_photo)
family_clips.append(children_clip)
father_gallery_files = get_individual_gallery_files(father[0])
if len(father_gallery_files) > 1:
del father_gallery_files[0]
for count, father_gallery_file in enumerate(father_gallery_files):
father_gallery_clip = video.get_clip(father_fullname + str(count), father_gallery_file['description'], image=father_gallery_file['path'])
family_clips.append(father_gallery_clip)
mother_gallery_files = get_individual_gallery_files(mother[0])
if len(mother_gallery_files) > 1:
del mother_gallery_files[0]
for count, mother_gallery_file in enumerate(mother_gallery_files):
mother_gallery_clip = video.get_clip(mother_fullname + str(count), mother_gallery_file['description'], image=mother_gallery_file['path'])
family_clips.append(mother_gallery_clip)
# father_death_year = father[0].get_death_year()
# if father_death_year != -1:
# logging.info(father_shortname + " passed away in " + str(father_death_year) )
# mother_death_year = mother[0].get_death_year()
# if mother_death_year != -1:
# logging.info(mother_shortname + " passed away in " + str(mother_death_year) )
return family_clips
if __name__ == "__main__":
clips = []
starting_id = "@I0007@"
#starting_id = "@I282315998674@"
#starting_id = "@I282315998663@"
starting_family = "@F0002@"
starting_individual = get_individual_from_id(starting_id)
# descendants = get_descendants(starting_individual)
# for descendant in descendants:
# logging.info(descendant.get_name())
starting_families = get_family_from_individual(starting_individual)
descendant_families = get_descendant_families(starting_families[0])
for family in descendant_families:
family_clips = get_family_clips(family)
for family_clip in family_clips:
clips.append(family_clip)
if clips:
final_clip = concatenate_videoclips(clips)
video_final_path = str(Path("descendants.mp4"))
musicfile = AudioFileClip("music.mp3")
musicclip = afx.audio_loop(musicfile, duration=final_clip.duration)
#final_video = final_clip.set_audio(audioclip)
final_audio = CompositeAudioClip([final_clip.audio.volumex(1), musicclip.volumex(0.6)])
final_video = final_clip.set_audio(final_audio)
final_video.write_videofile(video_final_path, fps=5)
else:
logging.info("No Clips Generated!")