karaoke-lyrics-processor 0.3.1__py3-none-any.whl → 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- karaoke_lyrics_processor/karaoke_lyrics_processor.py +64 -13
- {karaoke_lyrics_processor-0.3.1.dist-info → karaoke_lyrics_processor-0.4.0.dist-info}/METADATA +1 -1
- karaoke_lyrics_processor-0.4.0.dist-info/RECORD +8 -0
- karaoke_lyrics_processor-0.3.1.dist-info/RECORD +0 -8
- {karaoke_lyrics_processor-0.3.1.dist-info → karaoke_lyrics_processor-0.4.0.dist-info}/LICENSE +0 -0
- {karaoke_lyrics_processor-0.3.1.dist-info → karaoke_lyrics_processor-0.4.0.dist-info}/WHEEL +0 -0
- {karaoke_lyrics_processor-0.3.1.dist-info → karaoke_lyrics_processor-0.4.0.dist-info}/entry_points.txt +0 -0
@@ -181,36 +181,52 @@ class KaraokeLyricsProcessor:
|
|
181
181
|
self.logger.debug(f"Text after cleaning punctuation spacing: {cleaned_text}")
|
182
182
|
return cleaned_text
|
183
183
|
|
184
|
+
def fix_commas_inside_quotes(self, text):
|
185
|
+
"""
|
186
|
+
Move commas inside quotes to after the closing quote.
|
187
|
+
"""
|
188
|
+
self.logger.debug(f"Fixing commas inside quotes in: {text}")
|
189
|
+
# Use regex to find patterns where a comma is inside quotes and move it outside
|
190
|
+
fixed_text = re.sub(r'(".*?)(,)(\s*")', r"\1\3\2", text)
|
191
|
+
self.logger.debug(f"Text after fixing commas inside quotes: {fixed_text}")
|
192
|
+
return fixed_text
|
193
|
+
|
184
194
|
def process_line(self, line):
|
185
195
|
"""
|
186
196
|
Process a single line to ensure it's within the maximum length,
|
187
197
|
handle parentheses, and replace non-printable spaces.
|
188
198
|
"""
|
189
|
-
# Replace non-printable spaces at the beginning
|
190
199
|
line = self.replace_non_printable_spaces(line)
|
191
|
-
# Clean up punctuation spacing
|
192
200
|
line = self.clean_punctuation_spacing(line)
|
201
|
+
line = self.fix_commas_inside_quotes(line)
|
193
202
|
|
194
203
|
processed_lines = []
|
195
204
|
iteration_count = 0
|
196
205
|
max_iterations = 100 # Failsafe limit
|
197
206
|
|
198
|
-
while len(line) > self.max_line_length:
|
199
|
-
if iteration_count > max_iterations:
|
200
|
-
self.logger.error(f"Maximum iterations exceeded in process_line for line: {line}")
|
201
|
-
break
|
202
|
-
|
207
|
+
while len(line) > self.max_line_length and iteration_count < max_iterations:
|
203
208
|
# Check if the line contains parentheses
|
204
209
|
if "(" in line and ")" in line:
|
205
210
|
start_paren = line.find("(")
|
206
|
-
end_paren =
|
211
|
+
end_paren = self.find_matching_paren(line, start_paren)
|
207
212
|
if end_paren < len(line) and line[end_paren] == ",":
|
208
213
|
end_paren += 1
|
209
214
|
|
215
|
+
# Process text before parentheses if it exists
|
210
216
|
if start_paren > 0:
|
211
|
-
|
212
|
-
|
213
|
-
|
217
|
+
before_paren = line[:start_paren].strip()
|
218
|
+
processed_lines.extend(self.split_line(before_paren))
|
219
|
+
|
220
|
+
# Process text within parentheses
|
221
|
+
paren_content = line[start_paren : end_paren + 1].strip()
|
222
|
+
if len(paren_content) > self.max_line_length:
|
223
|
+
# Split the content within parentheses if it's too long
|
224
|
+
split_paren_content = self.split_line(paren_content)
|
225
|
+
processed_lines.extend(split_paren_content)
|
226
|
+
else:
|
227
|
+
processed_lines.append(paren_content)
|
228
|
+
|
229
|
+
line = line[end_paren + 1 :].strip()
|
214
230
|
else:
|
215
231
|
split_point = self.find_best_split_point(line)
|
216
232
|
processed_lines.append(line[:split_point].strip())
|
@@ -218,11 +234,46 @@ class KaraokeLyricsProcessor:
|
|
218
234
|
|
219
235
|
iteration_count += 1
|
220
236
|
|
221
|
-
if line: # Add
|
222
|
-
processed_lines.
|
237
|
+
if line: # Add any remaining part
|
238
|
+
processed_lines.extend(self.split_line(line))
|
239
|
+
|
240
|
+
if iteration_count >= max_iterations:
|
241
|
+
self.logger.error(f"Maximum iterations exceeded in process_line for line: {line}")
|
223
242
|
|
224
243
|
return processed_lines
|
225
244
|
|
245
|
+
def find_matching_paren(self, line, start_index):
|
246
|
+
"""
|
247
|
+
Find the index of the matching closing parenthesis for the opening parenthesis at start_index.
|
248
|
+
"""
|
249
|
+
stack = 0
|
250
|
+
for i in range(start_index, len(line)):
|
251
|
+
if line[i] == "(":
|
252
|
+
stack += 1
|
253
|
+
elif line[i] == ")":
|
254
|
+
stack -= 1
|
255
|
+
if stack == 0:
|
256
|
+
return i
|
257
|
+
return -1 # No matching parenthesis found
|
258
|
+
|
259
|
+
def split_line(self, line):
|
260
|
+
"""
|
261
|
+
Split a line into multiple lines if it exceeds the maximum length.
|
262
|
+
"""
|
263
|
+
if len(line) <= self.max_line_length:
|
264
|
+
return [line]
|
265
|
+
|
266
|
+
split_lines = []
|
267
|
+
while len(line) > self.max_line_length:
|
268
|
+
split_point = self.find_best_split_point(line)
|
269
|
+
split_lines.append(line[:split_point].strip())
|
270
|
+
line = line[split_point:].strip()
|
271
|
+
|
272
|
+
if line:
|
273
|
+
split_lines.append(line)
|
274
|
+
|
275
|
+
return split_lines
|
276
|
+
|
226
277
|
def process(self):
|
227
278
|
self.logger.info(f"Processing input lyrics from {self.input_filename}")
|
228
279
|
|
{karaoke_lyrics_processor-0.3.1.dist-info → karaoke_lyrics_processor-0.4.0.dist-info}/METADATA
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: karaoke-lyrics-processor
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.0
|
4
4
|
Summary: Process song lyrics to prepare them for karaoke video production, e.g. by splitting long lines
|
5
5
|
Home-page: https://github.com/karaokenerds/karaoke-lyrics-processor
|
6
6
|
License: MIT
|
@@ -0,0 +1,8 @@
|
|
1
|
+
karaoke_lyrics_processor/__init__.py,sha256=rLRkJQi61qkRiNXdlTleE3ahJ1oBKcghYVkz64x7IIg,62
|
2
|
+
karaoke_lyrics_processor/cli.py,sha256=bdtseRI2jcChb1bMr92pc5mpSWpHXh4TSzA2tknbyjU,2522
|
3
|
+
karaoke_lyrics_processor/karaoke_lyrics_processor.py,sha256=3x5Ev9xzJ_FHarHDiYHtxftpXH0PaWZGJl9GjYeeIg0,13510
|
4
|
+
karaoke_lyrics_processor-0.4.0.dist-info/LICENSE,sha256=BiPihPDxhxIPEx6yAxVfAljD5Bhm_XG2teCbPEj_m0Y,1069
|
5
|
+
karaoke_lyrics_processor-0.4.0.dist-info/METADATA,sha256=_tWFNbjNUj4WoA79ZqVCsRwH2J5KlMqXQ8j8ZthzoGI,4264
|
6
|
+
karaoke_lyrics_processor-0.4.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
7
|
+
karaoke_lyrics_processor-0.4.0.dist-info/entry_points.txt,sha256=hjFp6CUxl1p-1WJYfB6TbNcI_DHEnVzX3BXAs4y_0O8,78
|
8
|
+
karaoke_lyrics_processor-0.4.0.dist-info/RECORD,,
|
@@ -1,8 +0,0 @@
|
|
1
|
-
karaoke_lyrics_processor/__init__.py,sha256=rLRkJQi61qkRiNXdlTleE3ahJ1oBKcghYVkz64x7IIg,62
|
2
|
-
karaoke_lyrics_processor/cli.py,sha256=bdtseRI2jcChb1bMr92pc5mpSWpHXh4TSzA2tknbyjU,2522
|
3
|
-
karaoke_lyrics_processor/karaoke_lyrics_processor.py,sha256=qMITsW0SbYCaacvEi9WzuZNeBMJhl2wlMck4WktzTEY,11513
|
4
|
-
karaoke_lyrics_processor-0.3.1.dist-info/LICENSE,sha256=BiPihPDxhxIPEx6yAxVfAljD5Bhm_XG2teCbPEj_m0Y,1069
|
5
|
-
karaoke_lyrics_processor-0.3.1.dist-info/METADATA,sha256=rCLkfq2I2QkdQlEGI0kiecLb_v5HdcBzuKT0VaNdjJw,4264
|
6
|
-
karaoke_lyrics_processor-0.3.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
7
|
-
karaoke_lyrics_processor-0.3.1.dist-info/entry_points.txt,sha256=hjFp6CUxl1p-1WJYfB6TbNcI_DHEnVzX3BXAs4y_0O8,78
|
8
|
-
karaoke_lyrics_processor-0.3.1.dist-info/RECORD,,
|
{karaoke_lyrics_processor-0.3.1.dist-info → karaoke_lyrics_processor-0.4.0.dist-info}/LICENSE
RENAMED
File without changes
|
File without changes
|
File without changes
|