-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProPresenter7_ENG_to_Russian_Adjuster.py
191 lines (157 loc) · 6.82 KB
/
ProPresenter7_ENG_to_Russian_Adjuster.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
import json
import os
import platform
import shutil
import sys
import xml.etree.ElementTree as ET
import zipfile
# Author - Daniel Agafonov (https://github.com/AlphaHasher)
# Author of lines 89-103, 164-173 - Martijn Lentink (https://github.com/martijnlentink)
# THINGS TO DO AND UPDATE BEFORE USING THIS SCRIPT:
# 1. Download your desired translation from here: https://github.com/martijnlentink/propresenter-custom-bibles . This will give you an output folder which will have the USX file you need to target.
# 2. Update the file_path variable to the path of your USX file that you want to target (for example: the PSA.usx file in the output folder)
# 3. Update the output_folder variable to the path of the output folder that was created when you downloaded the translation from the link above
# 4. Update the translation_name variable to the name of the translation you are adjusting (for example: ESV RUS Adjusted)
# 5. Update the metadata and rvmetadata files to include the new translation name (this is where the translation name will be displayed in ProPresenter)
# Load the USX file
file_path = "path/to/your/file.usx"
output_folder = "path/to/your/output/folder" # created after you download the translation from the link above
translation_name = "NAME RUS Adjusted"
tree = ET.parse(file_path)
root = tree.getroot()
# The verse_map dictionary
verse_map = {
'PSA': {
'1:1-2:12': 'X:X',
'3:1-9:20': 'X:+1',
'10:1': '-1:+21',
'10:2-18': '-1:+21',
'11:1-7': '-1:X',
'12:1-13:4': '-1:+1',
'13:5': '-1:+1',
'13:6': '-1:+1',
'14:1-17:15': '-1:X',
'18:1-22:31': '-1:+1',
'23:1-29:11': '-1:X',
'30:1-31:24': '-1:+1',
'32:1-33:22': '-1:X',
'34:1-22': '-1:+1',
'35:1-28': '-1:X',
'36:1-12': '-1:+1',
'37:1-40': '-1:X',
'38:1-42:11': '-1:+1',
'43:1-5': '-1:X',
'44:1-49:20': '-1:+1',
'50:1-23': '-1:X',
'51:1-52:9': '-1:+2',
'53:1-6': '-1:+1',
'54:1-7': '-1:+2',
'55:1-59:17': '-1:+1',
'60:1-12': '-1:+2',
'61:1-65:13': '-1:+1',
'66:1-20': '-1:X',
'67:1-70:5': '-1:+1',
'71:1-74:23': '-1:X',
'75:1-77:20': '-1:+1',
'78:1-79:13': '-1:X',
'80:1-81:16': '-1:+1',
'82:1-8': '-1:X',
'83:1-85:13': '-1:+1',
'86:1-17': '-1:X',
'87:1': '-1:+1',
'87:2': '-1:X',
'87:3-7': '-1:X',
'88:1-90:4': '-1:+1',
'90:5': '-1:+1',
'90:6': '-1:X',
'90:7-91:16': '-1:X',
'92:1-15': '-1:+1',
'93:1-101:8': '-1:X',
'102:1-28': '-1:+1',
'103:1-107:43': '-1:X',
'108:1-13': '-1:+1',
'109:1-114:8': '-1:X',
'115:1-18': '-2:+8',
'116:1-9': '-2:X',
'116:10-19': '-1:-9',
'117:1-147:11': '-1:X',
'147:12-20': 'X:-11',
'148:1-150:6': 'X:X',
}
}
def move_rvbible_propresenter_folder(rvbible_loc):
system_str = platform.system()
_, filename = os.path.split(rvbible_loc)
if system_str == 'Windows':
program_data = os.getenv('PROGRAMDATA')
propresenter_bible_location = os.path.join(program_data, 'RenewedVision\ProPresenter\Bibles\sideload')
os.makedirs(propresenter_bible_location, exist_ok=True)
elif system_str == 'Darwin':
propresenter_bible_location = '/Library/Application Support/RenewedVision/RVBibles/v2/'
else:
raise Exception("Unable to determine operating system, please copy the bible manually")
new_file_loc = os.path.join(propresenter_bible_location, filename)
shutil.copyfile(rvbible_loc, new_file_loc)
def apply_adjustment(chap_no, verse_no, adjustment):
chap_adj, verse_adj = adjustment.split(":")
if chap_adj == "X":
new_chap_no = chap_no
else:
new_chap_no = str(int(chap_no) + int(chap_adj))
if verse_adj == "X":
new_verse_no = verse_no
else:
new_verse_no = str(int(verse_no) + int(verse_adj))
return new_chap_no, new_verse_no
chapter_map = {}
for elem in root.iter():
if elem.tag == "book":
book = elem.text
book_c = elem.get('code')
if elem.tag == "chapter":
chap_no = elem.get('number')
chapter_map[chap_no] = elem # Store chapter elements for later adjustment
if elem.tag == "verse":
verse_no = elem.get('number')
ref = f"{chap_no}:{verse_no}"
for ref_range, adjustment in verse_map.get(book_c, {}).items():
if "-" not in ref_range:
start_ref = end_ref = ref_range
else:
start_ref, end_ref = ref_range.split("-")
start_chap, start_verse = map(int, start_ref.split(":"))
if ":" not in end_ref:
end_ref = f"{start_chap}:{end_ref}"
end_chap, end_verse = map(int, end_ref.split(":"))
if (start_chap < int(chap_no) < end_chap) or (start_chap == int(chap_no) and start_verse <= int(verse_no)) or (end_chap == int(chap_no) and int(verse_no) <= end_verse):
new_chap_no, new_verse_no = apply_adjustment(chap_no, verse_no, adjustment)
elem.set('number', new_verse_no)
chapter_map[chap_no] = new_chap_no # Store the new chapter number
break
print(f"Psalm {chap_no}:{verse_no} adjusted to {new_chap_no}:{new_verse_no}")
# Update the chapter numbers in the XML structure
for old_chap_no, new_chap_no in chapter_map.items():
for chap_elem in root.findall(f".//chapter[@number='{old_chap_no}']"):
chap_elem.set('number', new_chap_no)
# print(f"Chapter {old_chap_no} updated to {new_chap_no}")
# Save the modified XML back to the file
tree.write(file_path, encoding='utf-8', xml_declaration=False)
# Fixes the duplicate chapter 9 issue
search_text = '<chapter number="9" style="c" /><para style="s1">'
replace_text = '<para style="p"><verse number="22" style="v" />'
# Read the file content
with open(file_path, 'r', encoding='utf-8') as file:
file_content = file.read()
first_occurrence_index = file_content.find(search_text)
second_occurrence_index = file_content.find(search_text, first_occurrence_index + len(search_text))
file_content = (file_content[:second_occurrence_index] + replace_text + file_content[second_occurrence_index + len(search_text):])
# Write the updated content back to the file
with open(file_path, 'w', encoding='utf-8') as file:
file.write(file_content)
zip_location = os.path.join(output_folder, f"../{translation_name}.rvbible")
shutil.make_archive(zip_location, 'zip', output_folder)
rvbible_location = shutil.move(zip_location + ".zip", zip_location)
print("Moving bible to ProPresenter directory")
move_rvbible_propresenter_folder(rvbible_location)
print("Done! Please restart ProPresenter and check if the bible is correctly installed.")
input("Press enter to close...")